OK three manuals later I still don't know! I've got player counters in my 2D gameboard as 32x32 pixel images and I want the mouse to move them from point a to point b. Mousex,mousey is not enough to control the mouse. Grabimage seems too flaky. I need to pick up any counter and move to any space. All the mouse command does is locate its x,y thats it. How does someone move a game counter on the game board, anyone???????
That damn mouse
Blitz3D Forums/Blitz3D Beginners Area/That damn mouse it's a very simplistic thing, but here you go:
*EDIT*
Updated it slightly so that you can see the mouse cursor with debug mode off.
Graphics 800,600,0,2 ;create counter graphic Global imgCounter = CreateImage(64,64) SetBuffer ImageBuffer(imgCounter) Color 255,0,0 Oval 0,0,64,64,True SetBuffer BackBuffer() Dim Board(7,7) For i = 0 To 3 Board(Rand(7), Rand(7)) = 1 Next Type Counter Field X% Field Y% End Type Global CurrentCounter.Counter = New Counter CurrentCounter\X = -1 While Not KeyDown(1) CheckInput() DrawGrid() DrawCounters() Flip Cls Wend End ;;;;;;;;;;;;;;;;;;; Function CheckInput() ;if left mouse button is pressed If MouseHit(1) Then ;if there is no current counter If CurrentCounter\X < 0 Then ;if a tile is under the mouse If Board(MouseX()/64,MouseY()/64) = 1 Then CurrentCounter\X = MouseX()/64 Currentcounter\Y = MouseY()/64 EndIf Else ;there is already a current counter If Board(MouseX()/64,MouseY()/64) = 0 Then ;move it to the new location Board(CurrentCounter\X,CurrentCounter\Y) = 0 Board(MouseX()/64, MouseY()/64) = 1 CurrentCounter\X = -1 Currentcounter\Y = -1 EndIf EndIf EndIf If MouseHit(2) Then CurrentCounter\X = -1 EndIf End Function ;;;;;;;;;;;;;;;;;;; Function DrawGrid() Color 255,255,255 For x = 0 To 7 For y = 0 To 7 Rect x*64,y*64,64,64,False Next Next End Function ;;;;;;;;;;;;;;;;;;; Function DrawCounters() For x = 0 To 7 For y = 0 To 7 If Board(x,y) = 1 Then DrawImage imgCounter, x*64,y*64 Next Next If CurrentCounter\X >-1 Then DrawImage imgCounter, MouseX(), MouseY() EndIf End Function
*EDIT*
Updated it slightly so that you can see the mouse cursor with debug mode off.
I'm not sure I quite understand, but I'll try anyway.
One idea would be:
1) Poll for a mousedown (left button pressed)
2) If it is clicked on a counter, then consider that counter "grabbed"
3) In your Render routine (which should be called every game loop), update the drawing location of that counter to be MouseX and MouseY
4) Poll for a mouseup (left button released)
5) If a counter was "grabbed", "release" it and stop updating the position in your Render routine.
<EDIT> Looks like Perturbatio posted a similar answer in the meantime
One idea would be:
1) Poll for a mousedown (left button pressed)
2) If it is clicked on a counter, then consider that counter "grabbed"
3) In your Render routine (which should be called every game loop), update the drawing location of that counter to be MouseX and MouseY
4) Poll for a mouseup (left button released)
5) If a counter was "grabbed", "release" it and stop updating the position in your Render routine.
<EDIT> Looks like Perturbatio posted a similar answer in the meantime
Thanks soooooo much, I'll try it out and see how it works. thanks to both of you for responding so quickly. I'll try to help someone one day to return the favor, though I'll most likely have more questions then answers for a while,