programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Tim Cooke
• Liutauras Vilda
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• fred rosenberger
• salvin francis
Bartenders:
• Piet Souris
• Frits Walraven
• Carey Brown

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

Ranch Hand
Posts: 50
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.

Greenhorn
Posts: 10
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

 They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton