Drawing out of Spritesheet?

BlitzMax Forums/BlitzMax Programming/Drawing out of Spritesheet?

zoqfotpik(Posted 2012) [#1]
What is the canonical way in Blitzmax to draw out of a spritesheet?

Let's say I have a sheet of 10 sprites by 10 sprites. The sprites are 32x32 so the spritesheet is 320x320. Is there any draw command that will set a 32x32 viewport to a given x,y coordinate in that sheet and draw it?

At the moment I am running with a class that loads a spritestrip and on load cuts it up into an array of separate 32x32 images. But this obviously doesn't have the benefits of single-surface drawing. Any recommendations?


GfK(Posted 2012) [#2]
DrawSubImageRect()


zoqfotpik(Posted 2012) [#3]
Thank you. I knew there was some command to do that but I couldn't find it.

Reinventing the Wheel, Opus #876879234

Last edited 2012


Yan(Posted 2012) [#4]
At the moment I am running with a class that loads a spritestrip and on load cuts it up into an array of separate 32x32 images.
For future reference...

LoadAnimImage
DrawImage


zoqfotpik(Posted 2012) [#5]
I had thought of using draw image frames and I may end up doing that but would that be single surface? Does it cat the images into a strip or the like?

I had also thought of using a map to access images by name (tmetal1, etc.). Are strings fast enough with a map to do that?

No novice to programming here but a lot of my knowledge is from the mid 80s and a lot of things that were too slow then are fine now.


GNS(Posted 2012) [#6]
I'm fairly certain LoadAnimImage stores each animation 'frame' in separate pixmaps (1 pixmap per frame) so there will be a texture switch each time a new frame of animation is drawn.


zoqfotpik(Posted 2012) [#7]
Is there any reason why it does that, or why that implementation is superior to having it construct a spritesheet and read out of there? I can see a problem if the spritesheet got so large that it exceeded the window boundaries.

I'll just roll my own for this, thanks for your help.


Derron(Posted 2012) [#8]
Getting your sprites from a tmap should be fast enough - else the cpu would be the bottleneck, not your gpu.
In most cases you are getting an fps brake with the ladder one.


Like said: roll your own one: you can code your own sprite atlas. Add Sprites as long as they fit into a specified area (so they do not get eg. over 2048x2048). Most times you will do that beside your app, but it could be done internally too.
Then just drawsubimagerect the part you are interested in.
Do the same for animated images.

That way you can set custom animations like: sprite1,sprite2,sprite3,sprite2,sprite2,sprite3.
This gets way easierr than using normal "animimages".

bye
Ron