I’m not sure if this is the best way to go, but I think this might
work anyone agree disagree?
I was thinking something a bit more along the lines of (forgive the
pseudo-code, I haven’t written C in a little while):
struct {
Sprite[] sprites;
int currentSprite;
int numberOfSprites;
val timeBetweenFrames;
} thing;
void spriteDraw() {
val currentTime = getTime();
if( currentTime > thing.timeBetweenFrames ) {
thing.currentSprite += 1;
if( thing.currentSprite >= thing.numberOfSprites )
thing.currentSprite = 0;
}
draw( thing.currentSprite );
}
The loop you wrote would, it seems always draw manOne…?
Another way might be:
Sprite getActiveSprite() {
return activeSprite;
}
void process() {
//change sprite if need be
}
void draw() {
getActiveSprite().draw();
}
As you can probably tell, I really like to process EVERYTHING then
draw EVERYTHING. ^^ I’m sorry if my pseudocode seems weird, I’ve
been working in Java lately, and don’t remember exactly how the
differences between the two work… << It seems like your way
probably works as you envision it in your head, though. I’d say give
it a shot if that’s what you’re comfortable with! That’s what I
do! Though I also tend to rewrite when I discover a way that works
better for me. But then, I doubt if anyone could have explained it
to me beforehand to avoid the rewrite…
Sorry if I’m being vague.
– ScottOn Mar 7, 2007, at 4:17 PM, Lamonte(Scheols/Demonic) wrote:
void int manOne(){
return 2;
}
void int manTwo(){
return 3;
}
void int spriteRUN(){
if(manOne() == 2){
//call sprite
//change sprite possition
manTwo();
}else if(manTwo == 3){
//call sprite
//change sprite possition
manOne();
}
}
On 3/7/07, Scott Harper wrote:
On Mar 7, 2007, at 3:33 PM, Lamonte(Scheols/Demonic) wrote:
Hello,
I was wondering whats the best way to switch between 2 image frames
every time I would press a key. For example, If I loaded 2 bitmaps
one will have its foot back and the other would have its foot
forward
so if I would to keep running the frames back and forth it would
look
like my sprite was walking. Any suggestions on the BEST way to do
this?
Unfortunately (as I’m sure many have discovered and I am currently
discovering), there’s no “best” way to do something like this. You
could set a variable and draw one or the other image based on that
variable’s value (meaning one more if() statement each frame), or you
could set some pointer variable to a drawing structure to point to a
different image each time it needs to switch… Those are the only
two reasonable ones I can come up with. The others a far more
obscure and unlikely.
Do either of those help at all?
I think a lot of “best” depends on how you’re structuring your
entities, also.
– Scott
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
–
Join phpdiscovery.com Now!
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org