b2dCreateAnimSubImage

Makes an animation from frames inside another image (a sprite sheet), sharing its texture.

2D Overlay

Parameters & Returns

Parameters

imageHandle Int
x Int
y Int
frameWidth Int
frameHeight Int
frameCount Int

Returns

Int

Quick Summary

Makes an animation from frames inside another image (a sprite sheet), sharing its texture.

Technical Exegesis...

Returns a new anim image handle whose frameCount frames, each frameWidth x frameHeight, are cut from imageHandle. Frame 0 is at x,y and the next ones follow left to right. When the next frame would pass the image's right edge, they carry on one row down (y + frameHeight), starting again at x.

It works like an image from b2dLoadAnimImage: draw it with b2dDrawAnimImage / b2dDrawAnimImageEx (frames 0 to frameCount - 1), and b2dGetAnimFrameAmount gives frameCount.

Example

Example.bam
Global sheet:Int = b2dLoadImage("Media/sprites.png")

; a 4-frame walk cycle somewhere in the middle of the sheet
Global walk:Int = b2dCreateAnimSubImage(sheet, 64, 32, 32, 32, 4)

b2dDrawAnimImage(walk, 200, 300, (frame / 8) Mod 4)