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.

Dark GDK / Sprite animation problems

Author
Message
Nithead
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Hampshire, England
Posted: 2nd Jun 2009 22:06
Hey all,

I havn't been on here for a long while, but have encountered a problem concerning sprite animations. All i am trying to do is create a way for my character to move up and down using the arrow keys, and for his oriention to change and his legs move when he moves.

here is my code:



the problem is that when turning round, it takes the character a while to change his orientation, and when changing from up to down he goes through about 5 frames before returning to the correct on.

please try and help guys

david

True geeks live forever, or die trying.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Jun 2009 23:33
I haven't had to test this but it looks like your animation wants to complete before allowing a change. Try forcing it out of the animation by setting the frame directly.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Nithead
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Hampshire, England
Posted: 3rd Jun 2009 17:08
Yes, thats what i suspected. I tried putting in the set frame command when the key is pressed, but all this does is make the animation not work or flash on and off.

True geeks live forever, or die trying.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jun 2009 17:26
Okay, another wild shot. Can you grab the current frame number from the animation and change the end frame to either that frame or the one following in a dbPlaySprite call?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Netjack
15
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 3rd Jun 2009 18:12
I actually had the same problem too. Still technically haven't solved the problem 100%, but for the most part, this is what I have done "with the help of the tutorial" to fix that problem.

have a variable something like.

int iPlayerFrame;

and then use the command dbSetSpriteFrame ( 1 , iPlayerFrame );

I did something like this.


int iPlayerFrame = 6;
int iFrameAnimateDelay = 0;

dbCreateAnimatedSprite ( 1, "playerpallet.bmp", 3, 3, 1 );
dbSprite ( 1, 0, 0, 1 );


void playerAnimate ( void )
{
// firstly increment the animation delay
iFrameAnimateDelay++;
if ( iFrameAnimateDelay > 8 )
{
// reset the delay and lets go animate
iFrameAnimateDelay = 0;

if ( checkLeft() )
{
iPlayerFrame = iPlayerFrame + 1;
if (iPlayerFrame > 6)
iPlayerFrame = 1;

}




if ( checkRight() )
{

iPlayerFrame = iPlayerFrame + 1;
if (iPlayerFrame > 12 || iPlayerFrame < 7)
iPlayerFrame = 7;
}


I'm not good at guessing what sprite frame you want to do with what but for the most part, you should see that it changes much quicker then with the dbPlaySprite command, since it actually wants to finish the set of frames you told it to play. Change the numbers as you see fit.

I removed two if statements I had that would check which way you where facing, but I would recommend you make a bool that checks if your facing a certain direction as well.
Nithead
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Hampshire, England
Posted: 3rd Jun 2009 18:36
I'm not entirely sure what you mean, but i tried this and the character ends up doing the moon walk...

grr this is so anoying, thanks for trying to help tho

True geeks live forever, or die trying.
Nithead
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Hampshire, England
Posted: 4th Jun 2009 17:04
Please help guys its just one of those stupid problems that i know there is a stupid solution for im just to stupid to see it.

True geeks live forever, or die trying.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Jun 2009 17:08
Only one other suggestion I can make is to delete the sprite altogether and re-establish it. However, GDK may want to finish an animation sequence before it will even delete an animated sprite.

Otherwise, the only thing I can think of is to set the frame yourself. However, this would also mean you'd have to deal with the delay factor yourself and would complicate the code.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Netjack
15
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 4th Jun 2009 19:59 Edited at: 4th Jun 2009 20:21
Let me try that again then. I was hoping that seeing the code was enough for to to adapt it into your own. I didn't think you where going to copy and paste it :p



Using and editing your code, this should work.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 4th Jun 2009 22:27
Here is a possible solution, I tested it and it works. The trick is to call the dbSetSpriteFrame when you change direction, so the animation continues playing from that frame, instead of going through other frames first.

I fail to grasp the meaning of your player_Step variable, so I left it out of this code. If you need it for something, it should be easy to integrate into this framework.

Does that help?

Nithead
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Hampshire, England
Posted: 6th Jun 2009 21:50
thanks guys this helps alot. the player step variable was in order to make him move 40 steps each time, so that he would always end up level with other objects.

True geeks live forever, or die trying.

Login to post a reply

Server time is: 2024-10-01 03:31:57
Your offset time is: 2024-10-01 03:31:57