Lets say I do:
img=createimage(31,31,rand(1,4))
how many frames does img have?
img=createimage(31,31,rand(1,4))
how many frames does img have?
Global image_strip = LoadAnim("tiles.bmp", 32, 32, 0) anim_size = GetAnimSize(image_strip) Print anim_size WaitKey() End Function LoadAnim(file$, tile_w, tile_h, first_frame) temp_image = LoadImage(file$) across = ImageWidth(temp_image) / tile_w down = ImageHeight(temp_image) / tile_h anim_size = across * down anim_strip = LoadAnimImage(file$, tile_w, tile_h, first_frame, anim_size) Return anim_strip End Function Function GetAnimSize(image) frames = 0 Repeat If Not ImageBuffer(image, frames) Then Exit frames = frames + 1 Forever Return frames End Function
image=CreateImage(width,height,frames) BufferList=PeekI(image+4) ;pImageBufferList BufferListEnd=PeekI(image+8) ;pImageBufferListEnd numframes=(BufferListEnd-BufferList)/4 ;Number of image framesFrom: http://www.blitzbasic.com/codearcs/codearcs.php?code=1751
Function GetTileCount(filename$, tw, th) temp_image = LoadImage(filename$) across = (ImageWidth(temp_image) / tw) down = (ImageHeight(temp_image) / th) count = (across * down) FreeImage temp_image Return count End Function
Global anim_strip = LoadAnimImage(file$, tile_w, tile_h, first, GetTileCount(file$, tile_w, tile_h))
Graphics 800,600 SetBuffer BackBuffer() Global framecnt animImage = easyLoadAnimImage("mysprite1.png") Local frame = 0 While Not KeyDown(1) Cls DrawImage animImage,50,50,frame frame = frame + 1 If frame = framecnt Then frame = 0 Flip Wend End Function easyLoadAnimImage(fname$) Local begin,cnt Local temp = LoadImage(fname) Local tempbuff = ImageBuffer(temp) Local bgColor = ReadPixel(0,0,tempbuff) Local xs = 8 Local ys = 8 Local x,y Local done = False While done = False done = True x=xs While x < ImageWidth(temp) For y = 0 To ImageHeight(temp)-1 If ReadPixel(x,y,tempbuff) <> bgColor Then done = False xs = xs + 1 x = 0 EndIf Next x = x + xs Wend Wend done = False While done = False done = True y=ys While y < ImageHeight(temp) For x = 0 To ImageWidth(temp)-1 If ReadPixel(x,y,tempbuff) <> bgColor Then done = False ys = ys + 1 y=0 EndIf Next y = y + ys Wend Wend cnt = (ImageWidth(temp) / xs) * (ImageHeight(temp) / ys) FreeImage temp framecnt = cnt Return LoadAnimImage(fname,xs,ys,0,cnt) End Function