LoadAnimImage ( bmpfile$,cellwidth,cellheight,first,count )
Parameters
|
bmpfile$ - path to the image file holding the strip cellwidth - width of one frame in pixels cellheight - height of one frame in pixels first - index of the first frame to take, counting from 0 count - how many frames to take |
Description
|
Loads an animation strip and returns a single image handle holding all its frames. The file is one picture made of equal-sized cells packed with no gaps. The command cuts it up for you, numbering the cells left to right and top to bottom starting at 0, and hands back one image whose frames you select with the frame parameter of DrawImage. first and count let you take a slice of a bigger sheet, which is how you keep a whole character on one file: frames 0 to 7 are the walk cycle, 8 to 11 the jump, and each animation becomes its own LoadAnimImage call against the same picture. To animate, step a frame counter on a timer rather than once per loop, so the speed does not depend on the machine - something like frame=(Millisecs()/100) Mod 8 - and draw with DrawImage sprite,x,y,frame. Ask for more frames than the sheet holds and you get a "Not enough frames in bitmap" error, so check that the cell size divides your file exactly; a stray pixel of padding will throw the whole grid off. The command returns 0 if the file itself cannot be loaded. Everything else about it matches LoadImage: same file formats, black masked by default, AutoMidHandle respected, one FreeImage frees the lot. See also: LoadImage, DrawImage, CreateImage, FreeImage, MaskImage. |
Example
; LoadAnimImage Example ; --------------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Load a 96x32 strip as 3 animation frames, each 32x32, starting at frame 0 spark=LoadAnimImage("media/spark.bmp",32,32,0,3) ; This strip uses bright pink as its transparent colour MaskImage spark,255,0,255 frame=0 delay_ms=120 timer=MilliSecs() While Not KeyDown(1) Cls ; [ / ] make the animation slower / faster If KeyHit(26) And delay_ms<400 Then delay_ms=delay_ms+40 If KeyHit(27) And delay_ms>40 Then delay_ms=delay_ms-40 ; Step to the next frame when enough time has passed If MilliSecs()>timer+delay_ms Then timer=MilliSecs() frame=(frame+1) Mod 3 End If ; Show the whole strip, with the current frame boxed For i=0 To 2 DrawImage spark,272+i*36,80,i Next Color 255,255,0 Rect 270+frame*36,78,36,36,False ; The animated spark flies with the mouse DrawImage spark,MouseX(),MouseY(),frame Text 0,0,"Move mouse [ / ] : animation speed Esc: exit" Text 0,20,"Frame "+frame+" of 3 frame delay "+delay_ms+"ms" Flip Wend End
Index