How to animate a sprite?

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

How to animate a sprite?

Post by jman » December 26th, 2013, 10:38 am

Hello,

I would like to learn how to manage sprite movement more efficiently.
There are a couple of things that I'm solving using a "brute force" approach and I wonder if there's a more "PSX-oriented" way of doing this.

I'll try to keep it short :-)

Basically what I would like to do is the following:
1_ Automatically animate a sprite according to the number of frames available
2_ Correct timing of the frames animation
3_ Tips in order to minimize calculations

(1) In order to "animate" a sprite I have to change GsSPRITE.u GsSPRITE.v coordinates relative to the TIM file. Currently I have a struct to manage an item on screen:

Code: Select all

struct MyHero
{
	GsIMAGE img;
	GsSPRITE sprt;
	...
};
Let's say I have a TIM file with four frames for the same sprite (see attachment).
I want to automatically invoke a animateSprite(GsSPRITE sprite) method that calculates the next frame to use.
I could add a "frame_index" property in the struct and keep track of the current frame; then proceed like this to calculate the offset of the TIM file:

Code: Select all

(TIM width / num_frames) * frame_index++
Is there something better?

(2) How do I correctly synchronize the sprite animation in order to prevent a visual flickering?

(3) What is an efficient way to organize sprite frames in the TIM file in order to minimize these calculations?
Examples: the first row/column of the TIM file frame for basic sprite movement, the second one is for explosion animation, and so on... suggestions?

Thanks
You do not have the required permissions to view the files attached to this post.

User avatar
inc^lightforce
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 248
Joined: Mar 07, 2013
I am a: Programmer Windows+PS1, GFX Artist
PlayStation Model: Black
Location: Germany

Post by inc^lightforce » December 26th, 2013, 12:27 pm

You can have my Source Code that i wrote in 2010.
Something isn't used, but all necessary files are included in the package i think :)

see Example:
[youtube]http://www.youtube.com/watch?v=MGpOiG5goxM[/youtube]

the jumping Mouse is the animated Sprite called "mumie" in the Source Code

PACK here:
http://rapidshare.com/share/7F7A51B93E6 ... 45535A56A5

shouts
inc.

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » December 27th, 2013, 9:16 am

inc^lightforce wrote:You can have my Source Code that i wrote in 2010.
Did everyone in the scene used to write code like that? :-)
Anyway, thank you very much, I think I got the idea: I can only prepare an array of GsSPRITE and then manually do some calculations to do what I really want (see my previous post). I'll work a bit more on this.

For anyone interested I attach source code, TIM file and resulting BIN of a sample using Orion_'s wrapper.
The Sonic sprite is taken from a post of user "bizarro2011", the frames are not perfectly aligned so there's a slight movement effect.

EDIT: uploaded and replaced attachment with a revised version of the code
You do not have the required permissions to view the files attached to this post.
Last edited by jman on December 27th, 2013, 11:33 pm, edited 1 time in total.

User avatar
inc^lightforce
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 248
Joined: Mar 07, 2013
I am a: Programmer Windows+PS1, GFX Artist
PlayStation Model: Black
Location: Germany

Post by inc^lightforce » December 27th, 2013, 10:53 am


jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » December 27th, 2013, 11:30 pm

I love demos and related productions, there really is some art in it. I could spend hours staring at them.
However taken as tutorial code, they are sometimes a bit hard to follow. If I wrote code like that at work I would be fired! :-D

User avatar
inc^lightforce
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 248
Joined: Mar 07, 2013
I am a: Programmer Windows+PS1, GFX Artist
PlayStation Model: Black
Location: Germany

Post by inc^lightforce » December 28th, 2013, 1:51 am

If I wrote code like that at work I would be fired! :-D
ha ha :D
we call it "leisure Coding"

feel free to check some of my other code-samples here: http://www.psxdev.net/forum/viewtopic.php?f=41&t=272

cheers

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests