b2dCreateSubImage

Makes an image from a rectangle of another image (a sprite sheet), sharing its texture.

2D Overlay

Parameters & Returns

Parameters

imageHandle Int
x Int
y Int
width Int
height Int

Returns

Int

Quick Summary

Makes an image from a rectangle of another image (a sprite sheet), sharing its texture.

Technical Exegesis...

Returns a new image handle that is the width x height rectangle at x,y of imageHandle, in pixels of that image. Use it to cut sprites out of one sprite sheet (atlas) of any layout, without drawing and grabbing them.

Nothing is copied: the sub-image uses the sheet's texture and just remembers its rectangle, so it costs no extra video memory and no upload.

Example

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

; cut sprites out of the sheet - any size, anywhere
Global player:Int = b2dCreateSubImage(sheet, 0, 0, 32, 48)
Global coin:Int = b2dCreateSubImage(sheet, 32, 0, 16, 16)

b2dSetImageMidHandle(player)
b2dDrawImage(player, 400, 300)
b2dDrawImage(coin, 100, 100)