gaps in lines

BlitzMax Forums/BlitzMax Beginners Area/gaps in lines

BachFire(Posted 2007) [#1]
Hello,

Since I just started, I'm doing something simple. You draw with your mouse pointer (hold down left button). But gaps can appear in the lines once in a while. Why is that happening? Here is the code:

Strict
Local x#=MouseX()
Local y#=MouseY()
Local width#=800
Local height#=800

Graphics width,height,0

While Not KeyDown(Key_Escape)
	DrawText "Right button = Clear screen",0,0
	DrawText "ESC = quit",0,15
	If x And y <> 0
		If MouseDown(1)
			DrawLine(x,y,MouseX(),MouseY())
			Plot MouseX(),MouseY()
		EndIf
		If MouseHit(2) Then Cls
	EndIf
	x=MouseX();y=MouseY()
	Flip
Wend



GfK(Posted 2007) [#2]
.


BachFire(Posted 2007) [#3]
Look at the code. I am drawing lines. I know there is also a Plot command, but I have removed that now since that was obsolete.. The gaps don't appear often, but they DO appear.


GfK(Posted 2007) [#4]
You're drawing the lines to alternate buffers. So you're going to get gaps.


BachFire(Posted 2007) [#5]
Hmmm.. I can't figure this out. What do you mean with alternate buffers? And how can I get around that?


QuietBloke(Posted 2007) [#6]
basically... you have two graphics windows... one is displayed on the screen.. and one is hidden.
All graphic commands are then written to the hidden one.
When you do the Flip command the two windows swap places.


ziggy(Posted 2007) [#7]
MouseX(), and MouseY() shoudn't be called more than once per loop. The mouse can be moved more than once in the same loop, and this could make you get wrong drawing.
Strict
Local x#=MouseX()
Local y#=MouseY()
Local width#=800
Local height#=800

Graphics width,height,0
local MX:Int
Local MY:Int
While Not KeyDown(Key_Escape)
	MX = MouseX()
	MY = MouseY()
	DrawText "Right button = Clear screen",0,0
	DrawText "ESC = quit",0,15
	If x And y <> 0
		If MouseDown(1)
			DrawLine(x,y,MX,MY)
			Plot MX,MY
		EndIf
		If MouseHit(2) Then Cls
	EndIf
	x=MX
        y=MY
	Flip
Wend

I'm not sure if you have to change anything else, as I can test it right now.

EDIT: changed to fix syntax error (tnx TaskMaster :D )


TaskMaster(Posted 2007) [#8]
I was about to post the same response.

The third from the last line:

x=MX();y=MY()

Should be:

x=MX;y=MY

But other than that, it works...

Good Job!


BachFire(Posted 2007) [#9]
Thanks for your input guys! But..

Plot MX,MY


..is not really needed, right?