Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 12:39 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Jul 11, 2012 1:01 am 
Offline

Joined: Mon Apr 09, 2012 8:03 pm
Posts: 9
My camera is just a float x and y and I use g.translate(-cam.cameraX+400, -cam.cameraY+300); to translate the graphics. I have the numbers hard coded just for testing purposes.

How would I take into account the camera so my mouse picking works correctly.

Code:
double mousetileX = Math.floor((double)mouseX/tiles.tileWidth);
    double mousetileY = Math.floor((double)mouseY/tiles.tileHeight);

    double playertileX = Math.floor(playerX/tiles.tileWidth);
    double playertileY = Math.floor(playerY/tiles.tileHeight);

    double lengthX = Math.abs((float)playertileX - mousetileX);
    double lengthY = Math.abs((float)playertileY - mousetileY);
    double distance = Math.sqrt((lengthX*lengthX)+(lengthY*lengthY));

    if(input.isMousePressed(Input.MOUSE_LEFT_BUTTON) && distance < 4) {
        if(tiles.map[(int)mousetileX][(int)mousetileY] == 1) {
            tiles.map[(int)mousetileX][(int)mousetileY] = 0;
        }
    }


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 11:57 am 
Offline
Site Admin

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 140
You can use the setOffset method from the Input class. This will adjust the mouseX and mouseY vaues by the offset you want (the cameraX, cameraY)

http://slick.cokeandcode.com/javadoc/org/newdawn/slick/Input.html#setOffset(float,%20float)


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 3:52 pm 
Offline

Joined: Mon Apr 09, 2012 8:03 pm
Posts: 9
Thanks that works perfect


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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