Slight problem with placing tiles in my editor

Problem is that tiles aren’t always placed in “cell” I click, sometime there is one tile offset when I click near edges of tile. Problem is either with my formula (which is 99% correct, as I’ve done extensive testing of it against various data in spreadsheet) or round function used by GD. If latter assumption is correct and round in fact is giving out wrong results, then I’d like to propose following replacement:

int round (double d) { double tempd = d - (int)d; if (tempd<=0.5d) { return (int)d; } else { return (int)(d+1); } }

which would give 100% correct results.

Change your formula to:

round(MouseX("",1)/32)*32 - 15
round(MouseY("",1)/32)*32 - 15

Then it works fine.


floor(MouseX("",1)/32)*32 floor(MouseY("",1)/32)*32
gives also a perfect result :slight_smile:

Thanks! Now I have to make tile selector…