Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sprite loading/access
#1
I'm loading a sprite sheet and splitting it into its 16 individual sprites. I would like to know if there is a way to save each part (which will be a sprite animation) in one variable so i can just PUT sprite(1),sprite(2), sprite(3) for animation or something like
INKEY$=FIRE then PUT sprite(5). Or if there is a better way, I would be glad to know as well !

thanks
adam
f everyone was as stupid as me, we'd all be a lot smarter.
Reply
#2
You basicly want to create an index array where each subscript gives you the coresponding position withing the images array. For example:
Index(1) = 0
Index(2) = 45
Index(3) = 115
etc...
Then, when you take the segment and offset, you use it like this:

Segment% = varseg(Images(0))
Offset% = varptr(Images(Index(1))) -> Image 1
Offset% = varptr(Images(Index(2))) -> Image 2
Offset% = varptr(Images(Index(3))) -> Image 3
blah...
Check out PP256 for routines that automatically create an index and image array.
Reply
#3
Or you could save memory by skipping the extra array if your sprites are all the same size by using a simple offset variable. To calculate the offset for 13h, the formula's easy:

offset = SpriteHeight * SpriteWidth / 2 + 2

assuming integer sprite arrays. Then, for GET and PUT, you do something like this:

GET(0,0)-(15,15),sprite(offset *spritenumber)
PUT(20,50),sprite(offset * spritenumber)


Far more effective for fixed-size sprites. Of course, for sprites of varying size in the same array, adding the second array is the most effective way to do it.
I'd knock on wood, but my desk is particle board.
Reply
#4
My sprites are all going to be the same size, and I think it will be a lot easier that way, but I'll save both code examples just in case. This is for my megaman game. The first guy I did had a different array for each sprite and I ended up with around 100 arrays. This isn't practical for one character, forget five. This way will be much easier. Thanks to you both!

adam
f everyone was as stupid as me, we'd all be a lot smarter.
Reply
#5
An even easier way is to actually use a 2-dimensional array (instead of simulating one by multiplying with an offset)

Code:
DIM Sprites(SpriteSizeX * SpriteSizeY \ 2 + 1, 1 TO NumSprites)

and then to GET/PUT use:

Code:
GET (x1, y1)-(x2, y2), Sprites(0, n)
PUT (x, y), Sprites(0, n), PSET

where n is from 1 to NumSprites
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)