Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / 2D Animated Sprite Movement - Help with Directional Changes - dbpro

Author
Message
Mercury VirgoK
14
Years of Service
User Offline
Joined: 17th Jun 2008
Location: Sunny CA
Posted: 11th Mar 2010 21:36
Hi, I'm new at programming & I hope someone can help me solve this problem. I'm going to try to make it as clear as possible.

I have a character and I have created two animated sprites of that character. One facing & walking right, and the other facing & walking left.

I have written some code so that when I hold down the rightkey() to make the sprite walk right, it does so with no problem. However, I when hold down the leftkey() to turn it around and make it walk left - I end up with two sprites on the screen. One of them standing still facing right, while the other is facing(& walking) left. Conversely when I try to turn the sprite around to walk right again - I end up with one sprite standing still facing left, while the other is facing (& walking) right.

I would like only the sprite that is currently walking to be on the screen, and I want the directional change to be instant.

I think some how I need to clear the sprite as I change direction. I have tried clearing the screen, hiding the sprite, deleting the sprite, flipping and mirroring the sprite. No luck.

I hope that was understandable. Any Suggestions would be appreciated.



Luke: "I don't believe it."
Yoda: "That is why you fail."
TDK
Retired Moderator
20
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Mar 2010 16:34
It's because for some reason you are using 2 sprites - and I see nowhere any Hide Sprite to remove the one you don't want to see.

You could use just the one sprite with both animations in it and simply redefine the start and end frame of the required animation when you change direction.

TDK

Mercury VirgoK
14
Years of Service
User Offline
Joined: 17th Jun 2008
Location: Sunny CA
Posted: 12th Mar 2010 19:01 Edited at: 12th Mar 2010 19:52
You don't see hide sprite because I removed it when it didn't work.

So I guess I'll create one animation with six frames instead of 3 each and try what you suggested. I shall return if I can't make it work. Thank you for your time!

- - - - - - -

It works!!! Thanks

Luke: "I don't believe it."
Yoda: "That is why you fail."

Login to post a reply

Server time is: 2023-01-29 04:54:57
Your offset time is: 2023-01-29 04:54:57