Problem with mouse pointer[solved]

Started by 659_minifly, November 15, 2011, 12:44:38 PM

Previous topic - Next topic

659_minifly

Hello
Maybe i use it in the wrong way
But when i click on one circle i have a repetition of the position


screenvsync on

Dim i as integer
Dim j as integer
Dim BW As Float
Dim BH As Float
Dim L as integer
dim Couleur as integer
Dim X_Pos As Float
Dim Y_Pos As Float
Dim Y_case as integer
Dim Y_case as integer
BW=64
BH=64

For i=1 to 8
for j=1 to 8
; box Bw*J,BH*I,(BW*J)+BW,(BH*i)+BH,0
L=rnd(5)
if l=0 then Couleur=rgb(255,255,255)
if l=1 then Couleur=rgb(255,0,0)
if l=2 then Couleur=rgb(0,255,0)
if l=3 then Couleur=rgb(0,0,255)
if l=4 then Couleur=rgb(255,255,0)
if l=5 then Couleur=rgb(0,255,255)
ink couleur
circle  Bw*J+(BW/2),BH*i+(BH/2),30
  Next j
Next i
do
If LeftMouseButton()=true then gosub Sub_Recherche_case
If RightMouseButton()=True then end


loop

Sync
WaitKey
end

Sub_Recherche_case:
; for calculate the positon of the mouse on the grid

        X_Pos =  MouseX()
        Y_Pos =  MouseY()


 X_case=X_Pos/BW
 Y_case=Y_Pos/BH

print X_case
print Y_case

sync
return




How can i fix it
Thanks

Fix it with "flushmouse" work fine

kevin

#1
  Another little tidbit,  you can clean up the colour picking stuff inside the circle drawing loop, by putting the selection of colours inside an array.  Then you choose a colour you pull a random and use that as the index like bellow

PlayBASIC Code: [Select]
screenvsync on

Dim i as integer
Dim j as integer
Dim BW As Float
Dim BH As Float
Dim L as integer
dim Couleur as integer
Dim X_Pos As Float
Dim Y_Pos As Float
Dim Y_case as integer
Dim Y_case as integer
BW=64
BH=64


Dim Palette(5)
Palette(0)=rgb(255,255,255)
Palette(1)=rgb(255,0,0)
Palette(2)=rgb(0,255,0)
Palette(3)=rgb(0,0,255)
Palette(4)=rgb(255,255,0)
Palette(5)=rgb(0,255,255)

For i=1 to 8
for j=1 to 8
; box Bw*J,BH*I,(BW*J)+BW,(BH*i)+BH,0
L=rnd(5)
circleC Bw*J+(BW/2),BH*i+(BH/2),30,1,Palette(L)
Next j
Next i



Do
If LeftMouseButton()=true then gosub Sub_Recherche_case
loop RightMouseButton()=True

Sync
WaitKey
end

Sub_Recherche_case:
; for calculate the positon of the mouse on the grid

X_Pos = MouseX()
Y_Pos = MouseY()


X_case=X_Pos/BW
Y_case=Y_Pos/BH

print X_case
print Y_case

sync
return





 Also the main Do / loop can use conditions, so this part


PlayBASIC Code: [Select]
do
If LeftMouseButton()=true then gosub Sub_Recherche_case
If RightMouseButton()=True then end
loop



 could be expressed as

PlayBASIC Code: [Select]
 do
If LeftMouseButton()=true then gosub Sub_Recherche_case
loop RightMouseButton()=True




659_minifly

Thank you kevin for your help
I would need more of them