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.
@Override
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
  super.mouseMoved(oldx, oldy, newx, newy); 
}

we can get the mouse location in this method via newx, newy . i want to know is there any such way to get the location in slick2D? when we press the arrow keys and move a image of a man on the game surface(tile map)?

share|improve this question
    
This looks similar to your other question. Are you asking something different and does the answer to the other question not answer this? –  Richard Marskell - Drackir Aug 19 '11 at 18:32
    
yes i'm asking different thing here, other question is sounds similar though. –  ranganaMIT Aug 19 '11 at 19:12
add comment

1 Answer 1

up vote 1 down vote accepted

I think you are confusing some concepts..... If you use your keyboard to move your player, then you usually store the location of the player's position in the player's object.

If you use your mouse to move the player, then you use the location of the mouse on the screen to set the player's position on the game.

So, there is no such thing as location of keyboard as there is for location of mouse pointer.

In any case, whichever way you update the location of your player, his position is still stored in the object. I.e.

class Sprite {
    Point position;
    Texture texture;
}

class Level implements MouseListener, KeyListener {
    Sprite player;
    ...
    void update(...) {
        // THIS IS THE POSITION OF YOUR PLAYER  
        //whether you updated it with mouse or keybaord
        Point position = player.getPosition(); 

        // Do something with this...
    }

    // Update player position using mouse
    public void mouseMoved(int oldx, int oldy, int newx, int newy) {
        player.setPosition(new Point(newx, newy);
    }

    // Update player position using keyboard
    public void keyPressed(int key, char c) {
        if (key == Input.KEY_W) {
            player.getPosition().X += 1;
        } else if (key == Input.KEY_S) {
            player.getPosition().X -= 1;
        } else if (key == Input.KEY_A) {
            player.getPoisition().Y -= 1;
        } else if (key == Input.KEY_D) {
            player.getPosition().Y += 1;
        }
    }
}

Hope this helped clear some things...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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