Changes

Jump to navigation Jump to search
→‎Positions: add conversion formulas, reformat for readability
Line 10: Line 10:  
===Positions===
 
===Positions===
 
The game uses three related coordinate systems:
 
The game uses three related coordinate systems:
* Things placed in the world have a ''[[#Tiles|tile position]]'', relative to the top-left corner of the map.
+
 
* Things in the world may also have an ''absolute pixel position'', relative to the top-left corner of the map. To convert a tile coordinate to a pixel coordinate, multiply it by <tt>Game1.tileSize</tt>; divide by <tt>Game1.tileSize</tt> for the reverse.
+
{| class="wikitable"
* Items are usually drawn on the screen using a ''screen pixel position'', relative to the top-left corner of the visible screen. To convert an absolute pixel coordinate to a screen coordinate, subtract it from <tt>Game1.viewport.X</tt> and <tt>Game1.viewport.Y</tt>.
+
|-
 +
! coordinate system
 +
! relative to
 +
! notes
 +
|-
 +
| tile position
 +
| top-left corner of the map
 +
| measured in [[#Tiles|tiles]]; used when placing things on the map (e.g. <tt>location.Objects</tt> uses tile positions).
 +
|-
 +
| absolute position
 +
| top-left corner of the map
 +
| measured in pixels; used when more granular measurements are needed (e.g. NPC movement).
 +
|-
 +
| screen position
 +
| top-left corner of the visible screen
 +
| measured in pixels; used when drawing to the screen.
 +
|}
 +
 
 +
Here's how to convert between them:
 +
 
 +
{| class="wikitable"
 +
|-
 +
!colspan="3"| conversion
 +
! formula
 +
|-
 +
| absolute || → || screen
 +
| <code>x - Game1.viewport.X, y - Game1.viewport.Y</code>
 +
|-
 +
| absolute || → || tile
 +
| <code>x / Game1.tileSize, y / Game1.tileSize</code>
 +
|-
 +
| screen || → || absolute
 +
| <code>x + Game1.viewport.X, y + Game1.viewport.Y</code>
 +
|-
 +
| screen || → || tile
 +
| <code>(x + Game1.viewport.X) / Game1.tileSize, (y + Game1.viewport.Y) / Game1.tileSize</code>
 +
|-
 +
| tile || → || absolute
 +
| <code>x * Game1.tileSize, y * Game1.tileSize</code>
 +
|-
 +
| tile || → || screen
 +
| <code>(x * Game1.tileSize) - Game1.viewport.X, (y * Game1.tileSize) - Game1.viewport.Y</code>
 +
|}
    
===Net fields===
 
===Net fields===
translators
8,403

edits

Navigation menu