
TileHelper.GetTileFromCursor does not work as exepcted
isaacalger opened this issue ยท 4 comments
Tiles that are have a negative X or Y coordinate are not returning the expected Tile coordinates.
This is reproduceable in buildings where the 0,0 coordinate is in the top left of the rendered building but extends well in the negative directions.
If you turn on DebugMode and DataLayer Grid mode you will notice the issue on any tile that is pass 0 on the X and 0 on the Y coordinates.
All negative tiles are essentially off by one because the calculation of (Game1.viewport.X + x) could return a negative value that is less than the Game1.tileSize which results in 0 instead of -1.
Here is my fix that solves the issue for me.
public static Vector2 GetTileFromScreenPosition(float x, float y)
{
int tileSize = Game1.tileSize;
int screenX = (int)(Game1.viewport.X + x);
int screenY = (int)(Game1.viewport.Y + y);
int tileX = screenX / tileSize;
int tileY = screenY / tileSize;
if (screenX % tileSize < 0 && tileX <= 0)
tileX--;
if (screenY % tileSize < 0 && tileY <= 0)
tileY--;
return new Vector2(tileX, tileY);
}
Thanks for looking into it! Pull requests are welcome, and there's no restrictions on them. Do you get an error when you try to submit one?
Maybe I am doing something wrong but yeah I am getting an error when trying to create a pull request using source tree.
I am trying to do a pull request from my local git repo to origin because I am not able to push branches to your repo either. I would imagine that you probably don't want a bunch of weird branches created in your repo so that would make sense why I cant do that. I wanted to point that out though incase you really have your repo open and I should be able to create branches too.
I have tried using the HTTPS as well as the SSH repo url and get the same error which really looks like my user is being blocked from the repo.
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin TestBranch:develop
Pushing to github.com:Pathoschild/StardewMods.git
ERROR: Permission to Pathoschild/StardewMods.git denied to isaacalger.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Completed with errors, see above.
This is really the first Public repo that I a have tried to work on so there is a very good chance that I am doing this wrong. Should I be creating a Fork or something and do the pull request from there. That seems wrong but maybe that is my issue.