• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Choose sprite from a larger mastersheet

B

Bretonator

Guest
I am working with a game that uses procedural generation of sprites, and there is a spritesheet laid out like a 3 dimensioned array. In pseudocode, I imagine referencing it something like this:

image = imgMatrix[3, 2, 0];

imagine a spritesheet called imgMatrix that is laid out in quadrants with 3x3 square sprites in each quadrant. In array sizing pseduocode: imgMatrix[3,2,2]

Each numeric value would be multiplied to find a corresponding coordinate on the spritesheet and then just use or draw only a selected portion of it. The 3 would perhaps correspond to the fourth quadrant of the spritesheet. 2 would be the row, 0 the column:
-------------------
|..........|...........|
|..........|...........|
|..........|...........|
---------|----------
|..........|...........|
|..........|...........|
|..........|X........|
-------------------
'X' would be the desired sprite portion to reference and display on screen

I'm trying to figure a way to select a portion of a spritesheet without having to "cut it up" as we normally do and create far too many sprites to fiddle with.

Is there a way to do this?
 
Last edited by a moderator:

RangerX

Member
Your only way is to have a sprite index with many image indexes.
Your sprite index is your "mastersheet" and you do your calculations with the image indexes (which are integers though)
 
B

Bretonator

Guest
Your only way is to have a sprite index with many image indexes.
Your sprite index is your "mastersheet" and you do your calculations with the image indexes (which are integers though)
That may work. I'll have to play with it. Thank you.
So I set the master sheet as the sprite_index, then each image_index will be the subimage I want. How do I define the size of the image_index? I may be overlooking something really obvious, but I'm also about to go to sleep. If the master sheet is several hundred pixels by several hundred pixels, I need to define a sub image that is only 32x32.
 

Fern

Member
Could also just define each sprite in a ds_list or array. Instead of having a single sprite with hundreds of indexes.
 

RangerX

Member
Create a sprite index. You will realise you can have any size for image_indexes. The only thing you will not choose is the name/reference number of those image_index. You'll have to work with what the engine gives.
 
Top