Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 11:09 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Using tile properties?
PostPosted: Sun Jan 29, 2012 9:20 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
I have a top-down game, and a tile with the property "type" with a value of "lava". How would I detect when the player steps on it and start reducing the HP while they are on it?


Top
 Profile  
 
PostPosted: Sun Jan 29, 2012 10:51 pm 
Offline

Joined: Sun Jan 29, 2012 3:59 am
Posts: 2
Basically, try something like this :
Code:
      TiledMap myMap;
      try {
         myMap = new TiledMap("coolmapwithlava.tmx");
         int x = (int) hero.getX() / myMap.getTileWidth();
         int y = (int) hero.getY() / myMap.getTileHeight();
         int tileID = myMap.getTileId(x, y, myMap.getLayerIndex("layerWithLava"));
         String lavaProperty = myMap.getTileProperty(tileID, "lava", "0");
         boolean isLava = "1".equals(lavaProperty);
      } catch (SlickException e) {
         e.printStackTrace();
      }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group