Relative... mouse... stuff...

BlitzPlus Forums/BlitzPlus Programming/Relative... mouse... stuff...

schilcote(Posted 2010) [#1]
(breaking one of the cardinal rules of coding, programming tired...)

I have a little gamey thing that moves stuff around. It makes the stuff move by adding an X or Y value to the XY values of every object, giving the illusion that the viewpoint is moving. This is just fine, but now I need to figure out if the mouse cursor is one one of these things.

I'm using this code to get the "relative mouse position", relative to the viewpoint.

adjMouseX=x+MouseX()
adjMouseY=y+MouseY()


I've also got a little square that gets drawn at these coordinates. The problem is, while the screen is fixated on 0,0 it works fine, but once I move the screen it desyncs and stays at where the cursor would be if I was focused on 0,0.

I basically need a way to translate the screen coordinates of the mouse into the game coordinates of my objects.


schilcote(Posted 2010) [#2]
Ermm... Hello?


ford escort(Posted 2010) [#3]
to be sure, you move all the objects by the same value ?

do you do something like that ?

xbase=50
ybase=50

coord of obj1=xbase+obj1x , ybase+obj1y
coord of obj2=xbase+obj2x , ybase+obj2y
coord of obj3=xbase+obj3x , ybase+obj3y

so

mouse coords = xbase+mousex,ybase+mousey


is this correct ? or i misunderstood something?

Last edited 2010


schilcote(Posted 2010) [#4]
Err, no. I'm ALLREADY doing that, I just seem to be having trouble making the mouse cursor sync up with the rest if the game.

There's more game than can be displayed on one screen, so I have a system set up so that when the player presses the left arrow key the entire game moves right and due to relativity it looks like the player has moved left. The drawing routines figure this stuff out, the main game just needs to tell them where the player is supposed to be.

I just can't figure out how to translate the mouse cursor's position on the screen to the mouse cursor's position in the game relative to the player's current position so that the player can click on things.


MCP(Posted 2010) [#5]
If you've written your code as above then you will have problems.
You need to add any offsets to your mouse's screen position to find the mouse's virtual game world position.
You need to subtract any offsets from each of your world objects ONLY when wishing to convert to screen coordinates for drawing (assuming you're using traditional 2D sprites.)