Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I used the following post to help me render my isometric map in Slick2D:

Slick2D Isometric TiledMap Rendering Problem

Big thanks and credit to arminb for the code supplied and for the fix to be able to use it.

My question is, how would I go about getting the properties of the isometric tiles. I have a little character that can walk around on the map, but he can walk on the blocked tiles. I have no code to be able to detect the properties.

This is the code I am using. The map is generated correctly, and the character is generated correctly.

How would I get the properties of a tile that I walk on?

import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer; 
import org.newdawn.slick.BasicGame; 
import org.newdawn.slick.GameContainer; 
import org.newdawn.slick.Graphics; 
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; 
import org.newdawn.slick.tiled.TiledMap;  

public class Game extends BasicGame {

    private TiledMap map;
    private Animation sprite, up, down, left, right;
    private float x = 350f, y = 250f;
    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new Game());

        app.setDisplayMode(800, 600, false);
        app.setShowFPS(true);
        app.start();
    }

    public Game() {
        super("Test");
    }

    @Override
    public void render(GameContainer arg0, Graphics arg1) throws SlickException {
        map.render(350, 250);
        sprite.draw((int)x, (int)y);
    }

    @Override
    public void init(GameContainer arg0) throws SlickException {
        Image [] movementUp = {new Image("data/wiz_up_one.jpg"), 
                new Image("data/wiz_up_two.jpg")};

        Image [] movementDown = {new Image("data/wiz_down_one.jpg"),
                          new Image("data/wiz_down_two.jpg")};

        Image [] movementLeft = {new Image("data/wiz_left_one.jpg"), 
                          new Image("data/wiz_left_two.jpg")};

        Image [] movementRight = {new Image("data/wiz_right_one.jpg"), 
                           new Image("data/wiz_right_two.jpg")};
        int [] duration = {300, 300}; 

        up = new Animation(movementUp, duration, false);
        down = new Animation(movementDown, duration, false);
        left = new Animation(movementLeft, duration, false);
        right = new Animation(movementRight, duration, false);

        // Original orientation of the sprite. It will look right.
        sprite = right;
        map = new TiledMap("data/iso.tmx"); //path is valid!
    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {
        Input input = gc.getInput();
        if (input.isKeyDown(Input.KEY_UP))
        {
            sprite = up;

            sprite.update(delta);
            // The lower the delta the slowest the sprite will animate.
            y -= delta * 0.1f;

        }
        else if (input.isKeyDown(Input.KEY_DOWN))
        {
            sprite = down;

            sprite.update(delta);
            y += delta * 0.1f;

        }
        else if (input.isKeyDown(Input.KEY_LEFT))
        {
            sprite = left;

            sprite.update(delta);
            x -= delta * 0.1f;

        }
        else if (input.isKeyDown(Input.KEY_RIGHT))
        {
            sprite = right;

            sprite.update(delta);
            x += delta * 0.1f;

        }
    }


}

enter code here
share|improve this question

closed as too localized by Byte56, Josh Petrie, Laurent Couvidou, Trevor Powell, Sean Middleditch Feb 4 '13 at 4:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You haven't told us what you've tried and how it's not working. Asking us how to modify your code to implement the feature you want is too localized in my opinion. I'm voting to close this question for that reason. –  Byte56 Jan 20 '13 at 20:13
    
The questions is how do I go about doing it? "How would I get the properties of a tile that I walk on?" I know how to do it for a regular map, but I don't see how it would work. I really just want a push in the right. –  n0774k3n Jan 20 '13 at 20:14

1 Answer 1

up vote 2 down vote accepted

Read the documentation for the TiledMap class. You'll find a method called getTileID(). It takes a x and y position and a layer ID. Pass in the position and layer ID of the player. This will give you the ID of the tile the player is at. Use that ID to retrieve information about the tile.

share|improve this answer
    
Are the positions read the same as a Orthogonal map? The very top being 0,0 then down and right is 0,1? Or just the x,y position of my character? –  n0774k3n Jan 20 '13 at 20:30
    
x,y position of the character as far as I know. I've never used the TiledMap before. This would be easy to implement and test to see if it's working correctly. –  Byte56 Jan 20 '13 at 20:46
    
I did what you said and it works to a point. I can't use the location of the character, only the location of the actual tile in the map. I will keep playing around with it to see if I can get it to work right. Thanks a lot for your help. –  n0774k3n Jan 20 '13 at 22:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.