Main Menu

moving a mouse pointer in steps

Started by RaverDave, January 11, 2006, 10:02:04 AM

Previous topic - Next topic

RaverDave

I need a way to move the mouse into steps of 32/16
that is to say through an array that is 15*14 in size, for my level editor, so each tile is 32*16 in size and I need to draw them at the mouse location but keeping with the location of the array! At the moment I am simply moving a custom cursor with the arrow keys but I imagine if there's alot of tiles to put down then this can be pretty laborious!

Digital Awakening

You could have a box drawn around the selected tile without having the mouse itself snap to tiles. To find out the selected tile just devide the mouse coordinates and turn them into integers. There should be a command like int() but I'm not 100% familiar with the PB commands yet and I'm not on a computer with PB. Integers are whole numbers and that's what you need (not decimals like 5.4286). Remeber to subtract any top and left margins from the mouse coordinates. To draw the box just multiply the integer values with the width and hight of the tiles to get the upper left corner of the tile.
Wisit my site at: DigitalAwakening.net

kevin

#2
It just requires a bit of math to convert the mouse coord to a grid (array) coordinate..

All you do is divide the MouseX & Y  by the Width/Height of the grid tiles




; set grid width/height in pixels
Grid_Width=32
Grid_Height=64


Do
cls 0

; Get mouse position
  MX=MouseX()
  MY=MouseY()

; Divide the Mouse Positions by the grid width and height
; this converts the mouse pos to a grid pos

 GridX = Mx/Grid_Width
 GridY = My/Grid_Height


; draw the tile/grid region your over
 
 x1=GridX*Grid_Width
 y1=GridY*Grid_Height
 x2=x1+Grid_width
 y2=y1+Grid_Height
 boxc x1,y1,x2,y2,true,rgb(100,200,50)

;draw a dot as the aligned mouse position
 dot GridX*Grid_Width,GridY*Grid_Height


Sync
loop

RaverDave

Thanks for that, implemented and works fine! :D