DrawImage image,x,y[,frame]
Parameters
|
image - handle of the image to draw x - x position to draw at y - y position to draw at frame (optional) - frame of an animated image to draw; 0 (default) |
Description
|
Draws an image, treating its mask colour as transparent. This is the workhorse for sprites. Pixels that match the image's mask colour - black unless you changed it with MaskImage - are left alone, so the sprite sits on top of whatever was already there instead of on a black card. Use DrawBlock when you want the opposite. It draws both plain images from LoadImage and strips from LoadAnimImage. For a strip, the frame parameter picks the cell, numbered from 0; stepping that number on a timer is all an animation is. The x,y is where the image's handle goes, and the handle is the top left corner until MidHandle, HandleImage or AutoMidHandle moves it. Coordinates are relative to the current Origin, and drawing off the edge of the screen is allowed - the image is clipped, so negative and oversized positions are a perfectly good way to slide things in and out of view. If you draw something and never see it, the usual cause is the buffer, not the command. Draw to BackBuffer(), redraw the whole scene every loop, and call Flip at the end of the loop to show it. See also: DrawBlock, DrawImageRect, LoadImage, LoadAnimImage, MaskImage, TileImage. |
Example
; DrawImage Example ; ----------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; The player ship sprite and a small star for the backdrop player=LoadImage("media/player.bmp") star=LoadImage("media/star1.bmp") ; Scatter the stars at fixed random positions SeedRnd MilliSecs() Dim star_x(19) Dim star_y(19) For i=0 To 19 star_x(i)=Rand(0,639) star_y(i)=Rand(0,479) Next While Not KeyDown(1) Cls ; Draw the starfield backdrop For i=0 To 19 DrawImage star,star_x(i),star_y(i) Next ; DrawImage puts the ship wherever the mouse points DrawImage player,MouseX(),MouseY() Text 0,0,"Move the mouse to fly the ship Esc: exit" Text 0,20,"DrawImage player,"+MouseX()+","+MouseY() Flip Wend End
Index