Newbie needs Help! Flipping!

BlitzPlus Forums/BlitzPlus Beginners Area/Newbie needs Help! Flipping!

observe, study, learn, practice, gain!
app=CreateWindow("designer",0,0,640,480,0,1) ; create the window

canvas=CreateCanvas(32,32,512,320,app) ; create the canvas on the window

img=CreateImage(512,320) ; create an image


Repeat

	WaitEvent() ; wait for events
	If EventID()=$803 quit=True ; alt-f4 pressed? make 'quit' true
	
	
	If EventSource()=canvas ; we doin' something on the canvas?
	
		If EventID()=$201 ; mouse-down?
			lmd=True
		EndIf
		
		If EventID()=$202 ; mouse-up?
			lmd=False
		EndIf
		
		If lmd ; while the mouse is down
			ex=EventX() ; x+y coords from the canvas! (not the screen!)
			ey=EventY() ;
			
			SetBuffer ImageBuffer(img) ; make sure we draw to the imagebuffer
				Color Rnd(255),Rnd(255),Rnd(255)
				Text ex,ey,"mouse!"
			SetBuffer CanvasBuffer(canvas) ; and draw that image to the canvas
				Cls
				DrawBlock img,0,0  				;DrawBlock img,-ex/2,-ey/2     ; <--- try this for some creepy effect
			FlipCanvas canvas ; flip the canvas (or else you'll be watching @ nothing)
		EndIf

	EndIf
	
	
Until quit ; so, repeat until quit = true


; make sure you add this, since you could press alt-f4 before the current buffer was set to the
; desktopbuffer
SetBuffer DesktopBuffer()
                           


; place to clean-up things,
FreeImage img ; like this..

End


*update*
- got rid of the setbuffers within the $201 and $202 checks, they were useless .. :)
- indented the stuff within a buffer-scope .. =personal style .. but I recommend it to everyone..