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.

Newcomers DBPro Corner / Stopping the Play Sprite Animation

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 20th Mar 2011 15:26
Ive been having a look at how to control a character using simple w,a,s,d keys and animating the sprite as he moves as someone has created an awesome isometric sprite sheet that i would like to use for now to demonstrate how this is done. Now the movement is fine, though in this version i havent added north east, north west, south east etc yet the principle will work (i just could do with tweeking the character movement and animation speed to match how hes walking)

Now i have a problem here. As the animation plays through the full range of frames its been set at, a change in direction makes it play through all the frames until it gets to where its supposed to be, but there isnt anythnig like a stop animation when your not holding the key down (it does stop but wants to resume when you change direction till it is finished). I need something to make this transition smooth so when you stop holding down the key, perhaps it resets back to the first frame and gets it ready for a direction change without wanting to play through.

Because there are apparently hundreds of ways to move a sprite no one person has written a tutorial that can be gone through and understood easily. I can understand this in a way but with no former background knowledge of program i have to ask the question, how the hell do people just do it. Do you wake up one day and say, there thats how its done. How does one learn some of the different method in order to choose which one may be best for himself. What are the different methods, whats the pro's and con's of each? Or where does one buy the implant that makes people just wake up with the knowledge of how to do these things because its hard enough to find info with the internet, i know most folk here probably knew how to do this pre internet.

Please help, i am at a very frustrated point in learning to program at the moment and i need all the help i can get so i can stand on my own two feet eventually.

Code is here:



I also have a second problem i would like to get sorted. The bmp has a pink alpha channel so i can get some transparancy, however i always get a pink line around my sprites as the program sort of gradients the pixels where they meet creating an almost pink but not quite 255, 0, 255 meaning they will show up. Anyone have any tips for avoiding this? I would absolutely love to use png's as there isnt a transparency problem, what you see is what you get, only problem is i intend to use the "ogre" in collision detection and i want pixel perfect collision from extends which only works with bmps. Bit stuck here.

Attachments

Login to view attachments
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 20th Mar 2011 21:30
Hi again. I quite understand your frustration, programming's like that, especially at the start. Anyhow have a go with this code.



All I do is when the key is detected as being pressed, I check to see if the animation is currently in the correct section and if it is not, I move the sprite frame directly there. Now you'll notice a new issue with this which is that if you hit two of the direction keys at once, it jumps between the two. I notice your sprite sheet has animations for moving at diagonals so you will need to add these too in a similar way to the way you have already implemented movement except you will need to check two keys instead of one.

As for your second issue, my suggestion would be to edit your sprite sheet using a good image editor like GIMP. These have a magic wand tool which will select similar colours. Tinker with the similarity settings on the magic wand so you select all the shades of pink and then set them all to exactly the same colour.

On your broader question of how do people know programming techniques, well I think most of us learnt like you are at the moment. Tutorials, books, trial an error, a little bit of invention and, at least for my part, lots of asking questions on this forum; something I continue to do. Good luck and do post if this doesn't make sense.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 21st Mar 2011 01:15
Thats brilliant, that does the job. I knew Sprite Frame but i didnt think to add it, thats the stage i am at at the moment, where i know stuff but dont think how to use it so it is almost 'forgotton' about. I was going to add a check for 2 keys being pressed in either of the other four directions and with the new addition i can now do what i need to do with it. Thanks so much this is great. It will be nice to move on from this now its sorted rather than dwell on it

Now if only i could scroll a background with him, but thats what my other thread is for.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 23rd Mar 2011 01:49
OK i had a go at filling in the rest of the movements (north west, north east, south west and south east) but to no joy.

I cant quite put my finger on whats going wrong but i have a few ideas, one of which it is checking for all the conditions and two of them are appearing twice, but im not sure what to do?


I only have the north east bit filled in.

Would something like inkey$() checking for how many keys are pressed first and if inkey$() string length is more than 1 then check for 'w' and 'd' being pressed, then check for 'w' and 'a' being pressed etc? Or would it just get confused if i held down 'w' 'a' and 's' perhaps at the same time because it then fufils no conditions and stops the charater from walking instead of what i want and thats to keep going in the direction of the first 2 keypresses. I feel i am close to solving this problem but not much is working at the moment, and i am wasting a lot of time coming up with and testing silly theorys that i am coming up with. Can anyone help?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Mar 2011 08:53 Edited at: 23rd Mar 2011 08:55
It's easier to check for the keys separately from the actual movement and set a variable that represents the players current direction.



Also it's easier to use only one PLAY SPRITE command and one check to keep the sprite frame within range by using variables for the start and end frames. I'll let you do that.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 25th Mar 2011 00:55
Ok thanks to everyones help i managed to cook this up.

Not sure if its the best way to do it so critisism is welcome.



It does work (with the above posts attachments), so i am happy with it and couldnt have worked it out without your help guys, so once again thanks, but if there is a better way i would still like to know in case i learn something.

Login to post a reply

Server time is: 2024-11-22 23:40:34
Your offset time is: 2024-11-22 23:40:34