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 / Creating an animated sprite from a previously loaded texture

Author
Message
anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 18th Jul 2011 10:47


This requires you to load a texture at the same time when you create an animated sprite. Is there anyway that I can make an animated sprite without having a load a texture at the same time?

Thanks!
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Jul 2011 11:36
Well you could load a series of images and then change the image number of the sprite, like this
sprite num, x, y, 1
sprite num, x, y, 2
sprite num, x, y, 3

Same sprite, different image. But this requires loading multiple images.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Jul 2011 18:51
The reason why it requires an image is because it needs the image size to determine where to grab each frame (based on the number of frames across and down). If you know the size of the image you're going to load you can load a blank image that's the same exact size as the image you're going to use later so it'll grab the frames properly. Once that's done you can use LOAD IMAGE to replace the image number used in CREATE ANIMATED SPRITE to load the actual animation you want.

anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 18th Jul 2011 23:34
Doesn't DB have functions that allow you to get the size of an image anyway?...... I just find it redundant that you're required to load the sprite image this way.

Ah well. I got it working, but I still see it as a symptom of bad program design.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jul 2011 05:42
Yeah but it's designed that way so we don't have to use a bunch of commands that we have to use to make animation manually... CREATE ANIMATED SPRITE makes it a lot easier. The following code snips do exactly the same thing with the attached image.

Manual Animation:


CREATE ANIMATED SPRITE:


anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 22nd Jul 2011 13:24
I guess I find it odd that DB can't use a texture automatically loaded in memory and find its dimensions that way....



For instance, you provide a sprite number. You provide an image number. DarkBasic looks up the image and also figures out its width and height. Using the Across and Down values provided, it chops up the animated sprite accordingly, and TADA! Animated sprite.

I just find it peculiar that it doesn't work in this fashion.

Login to post a reply

Server time is: 2026-07-10 22:37:42
Your offset time is: 2026-07-10 22:37:42