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.

DarkBASIC Professional Discussion / Animating sprites with movement

Author
Message
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 22nd Feb 2015 15:29 Edited at: 22nd Feb 2015 15:32
Hey guys,
Heads up > my syntax is pretty bad. >>>> I should probably add in that i dropped dbasic for years so trying to get my head around it again is proving to be a little bit difficult.
I was going through animating sprites and what not and am in a little pickle. I've searched around and am a little confused. (even through my previous posts from years go)

So i've managed to animate sprites through the create animated sprite OR using the load image and loading the certain section of image and pasting as i go along.

What I'm stuck at is with both of the variations, which is the more efficient?
And/or which is more efficient with a keypress?
eg

If i leftkey(), how do i stop the create animated sprite playing over when i'm not pressing the key.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 22nd Feb 2015 18:10
For simplicity consider you have a animated sprite character consisting of 5 frames. Frame 1 is the idle pose and frames 2 through 5 make up the walking animation. Using Set Sprite Frame you can control exactly which frame is displayed. If the left key is pressed increment the frame otherwise set the idle frame. This basic concept can be expanded on however necessary.

kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 23rd Feb 2015 03:40
Thanks for the quick reply. Currently at work, I'll try to implement that when I'm home. I had that (sorta) but I guess I did it a very long winded way and wasn't very efficient.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Feb 2015 13:43 Edited at: 23rd Feb 2015 13:46
Just note that you'll have to implement a delay in that or you'll be updating frames at the speed of the loop. I would suggest investing in timer based movement, key framing, lerping or another method. For now here's a simple method that works well:



Note: Get Ian's Matrix Plugin if you don't have it already! It's a must for DBP and use his Hitimer() instead cause it's way more accurate then the standard DBP one!
The Matrix1Utils plugins collection

"Get in the Van!" - Van B
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 23rd Feb 2015 13:57
Do please ignore the mirroring, i'm trying to figure that out myself.

Using the frame inc that youve suggested. I'm unsure of how i can make the variables to let the frame go back to 1 when i let go of the leftkey - because it auto plays frame 1 to 6?



Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Feb 2015 14:55 Edited at: 23rd Feb 2015 15:09
You don't seem to be using the frame inc method in your code so I can't help there until you've implement it cause WickedX pretty much covered it in his code.

The way Play Sprite works is it updates every time it's called, so not calling it should stop it updating (I've never used it but that's what the wiki says). All you need to do is check if your not pressing anything then set the frame back to 1.



"Get in the Van!" - Van B
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 23rd Feb 2015 23:50
Maybe it's because I haven't pulled it off just yet because I'm back at work again but if it's mid animation and then I suddenly release it and have it gi straight back to frame one, doesn't the animation look slightly disjointed?
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th Feb 2015 02:01
Depending on the sprite sheet it can look quite natural. This expansion to my snippet above should make a smooth transition from the current frame to the idle pose. As Sasuke suggested you'll need to implement some timer control.

kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 24th Feb 2015 03:23 Edited at: 24th Feb 2015 03:24
Hey wicked, first and foremost, thanks for all the help so far and everyone else that has input. I really appreciate it.

I know this is now spoon feeding me as I ask this but with the frame Inc method, is it possible for me to use the create animated sprite? Because as I understand it, when you use that it auto plays 1 to 6 and then just stops at which ever frame when I let go of the key. There's something I'm not understanding in terms of the sprite playing through the frames. I don't know if I'm explaining myself very well. =s

So I definitely understand what you're putting in front of me, I'm stuck at how to execute it correctly.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th Feb 2015 03:43 Edited at: 24th Feb 2015 03:44
Yes, you'll want to use Create Animate Sprite but, instead of using Play Sprite, Set Sprite Frame will allow you more control of how the frames are displayed.
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 24th Feb 2015 04:41
And that there has opened my eyes to a different method of doing it.

Thanks a lot!
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 24th Feb 2015 06:04
PlaySprite



Attachment

windowsXp
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 24th Feb 2015 08:48
That in itself just blew my mind. Thanks a lot guys.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Feb 2015 11:06
Excellent demo pcRaider.



Powered by Free Banners
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Feb 2015 11:44 Edited at: 24th Feb 2015 11:54
That's a great little demo there pcRaider I would say the only little adjustment you need to make there is the ability to hold down two directions, though that would be pretty simple to add.

As a different take on this, without using play sprite but altering pcRaiders code so it works with his media:



Note: Ian's Matrix Plugin is needed for the wrap command

"Get in the Van!" - Van B
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Feb 2015 12:38
Very neat.



Powered by Free Banners
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 25th Feb 2015 09:19
Hey again guys,

I was about to say, i hve no idea of that wrap command or have seen it just yet in my endeavours.

Login to post a reply

Server time is: 2026-07-11 18:26:48
Your offset time is: 2026-07-11 18:26:48