tile is far away from mouse suddenly?

Non-platform specific questions.

tile is far away from mouse suddenly?

Postby Hblade » Thu Jan 03, 2013 1:52 am

So, on my old tile editor, it didn't matter where the view was, the mouse would always connect to the tile. However; this happens with the same code, which is:
Code: Select all
x=(view.x+round(xmouse/32)*32)+16;
y=(view.y+round(ymouse/32)*32)+16;


Now, as you can see in this screen shot this... no longer applies o.O
umyar.png


The ^ represents where the mouse is. I -kind of- fixed it by doing this:
Code: Select all
x=(view.x-(view.x)+round(xmouse/32)*32)+5;
y=(view.y-(view.y)+round(ymouse/32)*32)-3;


but the tile appears 16 pixels away from the mouse. (I don't know why +5 and +3 need to be there but they do otherwise it doesn't align to the grid) The view's X and Y are set to -198 and -24 to make the top left corner of the grid equal to 0, 0 in X Y co-ord.

This caused the code to malfunction for some reason. I can kind of guess why, because the view goes below 0. But how to fix this?


EDIT: FIXED :D
Code: Select all
x=(view.x-(view.x)+round((xmouse+16)/32)*32)+5;
y=(view.y-(view.y)+round((ymouse+16)/32)*32)-3;


FIXED ^^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: tile is far away from mouse suddenly?

Postby skydereign » Thu Jan 03, 2013 2:23 am

[quote="Hblade"
Code: Select all
x=(view.x-(view.x)+round((xmouse+16)/32)*32)+5;
y=(view.y-(view.y)+round((ymouse+16)/32)*32)-3;


FIXED ^^[/quote]
Look at that carefully.
Code: Select all
x=(view.x-(view.x)+round((xmouse+16)/32)*32)+5;

view.x-(view.x) is equal to 0 therefore the code should really be this.
Code: Select all
x = (round((xmouse+16)/32)*32)+5;

Now, in terms of wanting to improve, this is one of those cases where you shouldn't be satisfied. Why is there a 5 in there? And for the y case, there is a -3? There are better ways of fixing it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: tile is far away from mouse suddenly?

Postby Hblade » Thu Jan 03, 2013 3:03 am

Honestly I'm happy you didn't just brush me off and say "Well thats good" Or "..." or something like that. I feel like you really don't mind guiding me to be a better programmer. Usually I feel uncomfortable around advanced programmers because I feel they'd all think I'm an idiot (Because programming isnt my strong point, I've been called an idiot before). Ever since then I thought programmers had giant egos but Sky your different, you actually make others want to be a better programmer.

And thanks for fixing in the pm
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron