DrawImageRect image,x,y,rect_x,rect_y,rect_width,rect_height[,frame]
Parameters
|
image - handle of the image to draw from x - x position on the destination buffer to draw at y - y position on the destination buffer to draw at rect_x - x coordinate inside the image where the piece starts rect_y - y coordinate inside the image where the piece starts rect_width - width of the piece to draw, in pixels rect_height - height of the piece to draw, in pixels frame (optional) - frame of an animated image to draw from; 0 (default) |
Description
|
Draws a rectangular piece of an image, treating its mask colour as transparent. Think of it as DrawImage with a window cut into the source picture. Masked pixels inside that window stay transparent, so a sprite carved out of a sheet still draws cleanly over the background. This is how you get by without a separate file per sprite: pack a whole tile set, character sheet or icon strip into one image and pull out cells by rectangle. It is also the easy way to do partial bars - a health bar that shrinks by drawing fewer columns of the same graphic, or a radial-free wipe that grows a rectangle each frame. rect_x,rect_y are measured from the top left of the image, and rect_width,rect_height are the size of the piece in pixels, not the coordinates of its far corner. Asking for a rectangle that runs off the edge of the image simply draws the part that exists. The destination x,y positions the image's handle and is relative to the current Origin. If you want the piece drawn opaque, mask colour and all, use DrawBlockRect instead. See also: DrawBlockRect, DrawImage, LoadAnimImage, MaskImage, CopyRect. |
Example
; DrawImageRect Example ; --------------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Explosion strip - 360x48, its background is the default black mask kaboom=LoadImage("media/kaboom.bmp") angle#=0 While Not KeyDown(1) Cls ; A 60x48 window drifts smoothly across the strip angle=angle+1 rx=150+150*Sin(angle) ; The whole image at the top, with the copied region boxed DrawImage kaboom,140,60 Color 255,255,0 Rect 140+rx,60,60,48,False ; An orange panel shows that masked pixels stay transparent Color 200,90,0 Rect 260,220,120,120,True ; DrawImageRect draws just that 60x48 portion of the image DrawImageRect kaboom,290,256,rx,0,60,48 Text 0,0,"Esc: exit" Text 0,20,"DrawImageRect kaboom,290,256,"+rx+",0,60,48" Text 0,40,"Only the boxed sub-rectangle is drawn - mask still transparent" Flip Wend End
Index