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 / Animating 2D Sprites

Author
Message
Gracus
12
Years of Service
User Offline
Joined: 10th Dec 2011
Location:
Posted: 11th Dec 2011 01:56
Hello, new to DarkBasic Pro and I am currently stuck on animating when my Sprites move.

Here's the code:

Load image "Images\Goku Running1.png",1
Load image "Images\Goku Running2.png",2
do
Sprite 999, Xpos, Ypos, 1
`Moves Sprite Left.
If leftkey() = 1
Xpos = Xpos - 5
endif
`Moves Sprite Right.
If Rightkey() = 1
Xpos = Xpos - -5
endif
sync
loop

What I'm trying to do is when the left key is pressed the two images repeatedly show (Which gives the animation of the sprite running) until the left key is is not in use.

I've tried multiple ways to make this work but none have been successful.

Does anyone know a way to do this? Thanks.
Joe Staff
12
Years of Service
User Offline
Joined: 7th Dec 2011
Location: Midsouth, USA
Posted: 11th Dec 2011 10:42
I haven't any experience playing with the sprite aspect of DarkBasic Pro. But quite simply you could implement a variable (before your main loop) and adjust each couple of loops (or base it on time for simplicity) then check it to see what sprite to show.

Example:
EricB
13
Years of Service
User Offline
Joined: 3rd Nov 2011
Location:
Posted: 11th Dec 2011 17:45
A few things to consider here.

First you should use a single image to generate the sprite. The image should contain equally sized and spaced images. (See attached file for a simple example) Please excuse my poor GIMP skills as I am not a graphic artist.

Then used like so:

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 12th Dec 2011 22:14
Quote: "First you should use a single image to generate the sprite. "

Not necessarily. As you may have noticed the sprite command requests an image number each time you use it and so changing the value of the image number will animate the sprite. You just need to put in a bit more work in controlling the animation, well image numbers and looping through them. It's a way of manually animating your sprites. But first we need to know what are in those image files. Is it a single frame of animation in each or a series of frames in each?

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 13th Dec 2011 07:55 Edited at: 13th Dec 2011 07:57
Okay, I'm gonna dive in now with my 5 cents/pence/yen/lire/imperial credits

Here is your code:


You're not actually telling it to do anything with your images. Below are some alterations based on the two strategies put forward:

Scenario 1 (Easiest) (What EricB was talking about)


Scenario 2 (Harder, more control) (What Hodgey was talking about)


In both examples, there is one major flaw but I ignored it in the coding since this topic's about animating sprites. I'd still better point it out. You need to either have different frames facing left/right OR you need to flip your sprites horizontally when changing directions (this may cause some minor accuracy problems with positioning based on how well-centered your images were on your canvas when you made them). Anyway, hope this helps break things down a little better.

Btw, you should place code in snippets like so...
[ code]
your codez
[ /code]
...but without the space.

Good luck and happy game making!

Login to post a reply

Server time is: 2024-11-25 17:03:02
Your offset time is: 2024-11-25 17:03:02