1

Problem when detecting corner cell of tile map???

private void getTiles(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {

TiledMapTileLayer layer=(TiledMapTileLayer)WorldRenderer.map.getLayers().getLayer(0);

TiledMapTileLayer layer1 = (TiledMapTileLayer)WorldRenderer.map.getLayers().getLayer(1);

        layer_Height=layer1.getHeight();
        layer_width=layer1.getWidth();

        leftcornerCell=layer1.getCell(0, 0);

It calculate the screen x/y while i want to give map x/y.

and gives result nullpointer exception.... Meeans not finding the cell at perticuler position.

How to find out corner cell of any Tilemap in LibGdx???

Daahrien
  • 10,190
  • 6
  • 39
  • 71
Neha Agarwal
  • 622
  • 7
  • 24
  • 1
    If you're getting an NPE in the above code, its not because `leftcornerCell` is null. Nothing dereferences that. Probably `layer1` is null. – P.T. May 03 '13 at 07:07
  • No P.T. **Layer1** is not null it gives current position cell is null. if there is another solution to find corner cell of tile map than please post. – Neha Agarwal May 03 '13 at 07:33
  • 1
    yea a Cell can be null if there isnt any Tile at the map. You dont save empty cells. So catch if the Cell is null ... – bemeyer May 03 '13 at 17:01
  • 2
    Cells which would be empty at load time are never created as a memory optimization. As @BennX noted, verify the cell is non-null before using it. – nEx.Software May 07 '13 at 14:18
  • @nEx.Software the name of the Asker is MobiDev hehehe :p – Daahrien Jan 08 '14 at 23:58

0 Answers0