Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does it mean to convert tile positions to pixel positions in a tilebased map?

 
John Quach
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Developing Games in Java by David Brackeen

In earlier demos in the book, the sprite's position was relative to the screen, but in this game, the sprite's position is relative to the tile map. You can use the TileMapRender.tilesToPixels() static function to convert tile positions to pixel positions in the map. This function multiplies the number of tiles by the tile size:

int pixelSize = numTiles * TILE_SIZE;

This way, sprites can move around to any position in the map and don't have to be justified with the tile boundaries.




I think I have some idea of this concept. But I'm still lost after a few days of trying to figure it out.
 
Antonio Principato
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you have a tilebased map and it is 3X3 that means that if it were a 2d array storing the tile data it would look like this. With each number representing the index of the array that corresponds to the tile.

(0,0)(1,0)(2,0)
(0,1)(1,1)(2,1)
(1,2(1 ,2)(2, 2) But that's referring to the data in tiles. so if the you were referring to the middle of the screen it would be x == 1 y == 1


If you were referring to these locations in pixels it would be in a format like this. With each number referring to the location on the screen in pixels
(assuming that each tile is 32x32)

(0,0) (32,0) (64,0)
(0,32)(32,32)(64,32)
(0,64)(32,64)(64,64)

Im just assuming that this is the answer that you are looking for
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic