Category: 2D Overlay
Syntax:
b2dCreateAnimSubImage:Int(imageHandle:Int, x:Int, y:Int, frameWidth:Int, frameHeight:Int, frameCount:Int)
Int
Makes an animation from frames inside another image (a sprite sheet), sharing its texture.
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. b2dGetImageWidth / b2dGetImageHeight give what they give for a b2dLoadAnimImage image on the same target.
As with b2dCreateSubImage, nothing is copied: the frames use the sheet's texture, the sheet can be freed first, and the texture goes when the last image using it is freed.
Returns 0 if imageHandle doesn't exist, frameWidth, frameHeight or frameCount is less than 1, or any frame falls outside the image.
View detailed documentation online
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)
BambooBasic © 2026 Michael Denathorn