Alright, so I have 16x16px tiles with some metadata stored for collision and tile type in a lookup table. All is working great...no problems.
For one of the tile types, I need to gauge where the player is in relation to the tile itself, and I can't seem to extract the tile position in pixels for that comparison.
For instance, I use this subroutine to get the 'tile number' in the table:
GetTile:
LDA tempy
AND #%11110000
STA temp
LDA tempx
LSR A
LSR A
LSR A
LSR A
ORA temp
TAY
RTS
This gives me the tile that is lined up on the 16x16 grid based on a plugged in point in pixels.
Now for a slightly different purpose, I need to reverse that to find the x of the left of the tile in pixels and the y of the top of the tile in pixels so I can determine a point's position in relation to that corner point of a particular tile. Should be pretty simple, but can't get it working.
Any suggestions? Thanks!
*EDIT* My concept was simple - something like :
LDA tempx
AND #%11110000
STA tempx
LDA tempy
AND #%11110000
STA tempy
...but it didn't work as expected. Does that seem a reasonable method to get these values? Should I be looking for the gremlin somewhere else in the routine? Thanks!
For one of the tile types, I need to gauge where the player is in relation to the tile itself, and I can't seem to extract the tile position in pixels for that comparison.
For instance, I use this subroutine to get the 'tile number' in the table:
Code:
GetTile:
LDA tempy
AND #%11110000
STA temp
LDA tempx
LSR A
LSR A
LSR A
LSR A
ORA temp
TAY
RTS
This gives me the tile that is lined up on the 16x16 grid based on a plugged in point in pixels.
Now for a slightly different purpose, I need to reverse that to find the x of the left of the tile in pixels and the y of the top of the tile in pixels so I can determine a point's position in relation to that corner point of a particular tile. Should be pretty simple, but can't get it working.
Any suggestions? Thanks!
*EDIT* My concept was simple - something like :
Code:
LDA tempx
AND #%11110000
STA tempx
LDA tempy
AND #%11110000
STA tempy
...but it didn't work as expected. Does that seem a reasonable method to get these values? Should I be looking for the gremlin somewhere else in the routine? Thanks!