Create multiple images from one anim image...

BlitzMax Forums/BlitzMax Beginners Area/Create multiple images from one anim image...

doswelk(Posted 2008) [#1]
I have an anim image and I want to create multiple images from it, each one would be the next frame in the image.

I cannot work out how I would do it....

is there a way to "say"

for local x% = 0 to 19
image = AnimImage(frame(X))
next

Thanks in advance.....


CS_TBL(Posted 2008) [#2]
You'd need as many images as you have frames in your 'animimage', e.g. an array of images. Then again, what's the point of doing so in the first place?


MGE(Posted 2008) [#3]
Be careful, looks like you would be doubling up on video memory as well. Or more if they are not x2 sized.


JazzieB(Posted 2008) [#4]
You don't need to create multiple images from an image, as anim images are handled semi-automatically. You store the main animation image on disk, which contains all of your animation frames (each frame needs to be the same size and there can be no padding between images/frames). You then use LoadAnimImage to load it in. To draw, use the optional 'frame' parameter of the DrawImage command...

animImage:TImage=LoadAnimImage("animation.png",frame_width,frame_height,0,number_of_frames)

DrawImage animImage,x_pos,y_pos,frame

Hope that helps.


Retimer(Posted 2008) [#5]
I haven't been able to test this quickly as i'm in a rush, but this is a basic idea of how i've done it:

Local ISurf[< FrameCount here >] 
Local TileWidth:Int = "<insert Width>"
Local TileHeight:Int = "<Insert height>"
Local FrameCount:Int = "<insert Framecount>"
Local ISurf:TImage[FrameCount] 


Local Surf:TPixmap = LoadPixMap(" <Insert long image>") 
For ii = 0 To framecount - 1
	Local minus = ((PixmapWidth(Surf) / TileWidth)) * TileWidth
	Local Whole = (PixmapWidth(Surf) / TileWidth) 
	xw = (TileWidth * ii) 
	yw = (ii / (PixmapWidth(Surf) / TileWidth)) * TileWidth
	
	If ((ii * TileHeight) + TileHeight) >= PixmapWidth(Surf) 
		xw:-(Int(Float(ii) / Float(Whole)) * minus) 
		
	End If

	ISurf[ii] = LoadImage(PixmapWindow(Surf, xw, yw, TileWidth, TileHeight)) 
Next

Surf = Null


You can have multiple rows in your tileset as well. Not just one (which seems to be the limit in animImage loading).


TomToad(Posted 2008) [#6]
You can have more than one row of tiles with LoadAnimImage(). The tiles are divided from left to right, top to bottom. You can even separate the rows if you want to, say if each row represents the animation of a different character.
local TileSet:TImage = LoadAnimImage("Tileset.png",32,32,0,16)

'create a tileset from a 128x128 image indexed like so:
'00 01 02 03
'04 05 06 07
'08 09 10 11
'12 13 14 15

Local Player:TImage = LoadAnimImage("Tileset.png",32,32,0,4)
Local Enemy:TImage = LoadAnimImage("Tileset.png",32,32,4,4)
Local NPC:TImage = LoadAnimImage("Tileset.png",32,32,8,4)
Local Dog:TImage = LoadAnimImage("Tileset.png",32,32,12,4)

'This will create 4 sets from the 128x128 image, indexed like so:
'00 01 02 03 <- Accessed from the Player variable
'00 01 02 03 <- Accessed from the Enemy variable
'00 01 02 03 <- accessed from the NPC variable
'00 01 02 03 <- Accessed from the Dog variable



Retimer(Posted 2008) [#7]
Tom, having more than one row; does that require squared sized images?


xlsior(Posted 2008) [#8]
Tom, having more than one row; does that require squared sized images?


No.