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 / 2d sprite animation

Author
Message
ZapMan
13
Years of Service
User Offline
Joined: 1st Feb 2013
Location:
Posted: 1st Feb 2013 08:30
Im new to this website, so i hope im doing this right. But i have a problem. I am trying to animate a sprite of spider man using 4 different bmps of him in different positions. I saw a piece of code on this website posted by a user named nonZero. they werent too sure if it would work or not but ill put it in the attachments.In their example, he was using only two other images. please let me know if this works, i tryed it but im not to good at this program yet.

Metric City Police Department
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 1st Feb 2013 16:38 Edited at: 2nd Feb 2013 01:45
You may want to look into CREATE ANIMATED SPRITE Sprite Number, Filename, Across, Down, Image Number and PLAY SPRITE Sprite Number, Start Frame, End Frame, Delay Value

Here is an example from DBP's help file.


Also, you needn't attach the code as a text file. You can simply put it between [[/b]code] and [/[b]code]. You can also use [[/b]code lang=dbp] to add syntax highlighting to your code.

Example:
[[b]
code lang=dbp]
`This is a test code
`This is more test code
a = a + 1
print a
sync
end
[/[b][/b]code]

Result:


Good luck and welcome to the forums!

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 2nd Feb 2013 00:52
Hello ZapMan, welcome to the forums

I do hope you understand copyrights...

Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 2nd Feb 2013 18:06
Like zeroSlave said, you'll want to use CREATE ANIMATED SPRITE, SET SPRITE FRAME, and PLAY SPRITE.

CREATE ANIMATED SPRITE will split up a single image file into 'frames' that you then use to animate.

So in general what you do is make a single file (a "sprite sheet") with all of the animation pictures evenly spaced out in it (like a grid). Lets say each spiderman image was 100x100 pixels. If you combined the 4 bitmaps of him into a single 400x100 bitmap, and then use the CREATE ANIMATED SPRITE command so that your program knows it is 4 images wide and 1 image tall, you can then set the sprite frame to the correct image when moving. AKA:
if moving up --> SET SPRITE FRAME to 1
if moving right --> SET SPRITE FRAME to 2
etc.

Of course you will have to use the correct syntax for the commands, but hopefully this will give you the general idea.

-----

Now lets say you actually want to animate spiderman when he is moving: Lets say when you're moving to the right there is one image of him with his left foot in front, and then another image with his right foot in front.

This is where you want to use the PLAY SPRITE command. You'd check which frames are of him walking right, and then tell the program to:
If moving right --> play animated sprite, and set the "start frame" to the first frame of him walking right, and the "end frame" to the last frame of him walking right.

Hope this helps~

Login to post a reply

Server time is: 2026-07-07 00:48:29
Your offset time is: 2026-07-07 00:48:29