-1
如何獲得鼠標位置的精靈座標?遊戲引擎Slick2d。平鋪地圖16x16。獲取鼠標位置的精靈座標java slick2D瓷磚地圖
相機
public class Camera {
public int x, y;
Object object;
public Camera(int x, int y)
{
this.x = x;
this.y = y;
}
public void tick()
{
if(object != null)
{
if(object instanceof Player)
{
Player player = (Player) object;
this.x = player.getX() - Jail.getJail().gm.getWidth()/2;
this.y = player.getY() - Jail.getJail().gm.getHeight()/2;
}
else if(object instanceof Item)
{
Item item = (Item) object;
this.x = item.getX() - Jail.getJail().gm.getWidth()/2;
this.y = item.getY() - Jail.getJail().gm.getHeight()/2;
}
else if(object instanceof Vector2)
{
Vector2 vector = (Vector2) object;
this.x = (int) vector.getX() - Jail.getJail().gm.getWidth()/2;
this.y = (int) vector.getY() - Jail.getJail().gm.getWidth()/2;
}
else
{
System.out.println("Unknown object.");
}
}
else
{
System.out.println("Camera null object.");
}
}
public void setObject(Object object)
{
this.object = object;
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
}
鼠標點擊
for (int l = 0; l < Jail.itemlist.size(); ++l)
{
Item item = (Item)Jail.itemlist.get(l);
jail.cam.setObject(new Vector2(Mouse.getEventX(), Mouse.getEventY()));
System.out.println("Mouse x: " + jail.cam.getX()/16);
System.out.println("Mouse y: " + jail.cam.getY()/16);
System.out.println("Item x: " + item.getX()/16);
System.out.println("Item y: " + item.getY()/16);
if (item.mousePressed(this.jail, par1, par2))
{
System.out.println("CLICK ON ITEM");
}
else
{
System.out.println("CLICK NO ITEM");
}
jail.cam.setObject(jail.player);
}
在不同位置的球員,不同的鼠標座標。如何解決這個問題?
鼠標X:8 鼠標Y:5 項X:10 項目Y:10 玩家X:37 遊戲者Y:23
鼠標X:9 鼠標Y:-5 項X :10 項目Y:10 玩家X:37 遊戲者Y:13
鼠標X:-2 鼠標Y:-5 項X:10 項目Y:10 球員x:25 球員y:13
您應該將圖像嵌入到您的帖子中,因爲鏈接可能會在一段時間後丟失。進一步你的問題應該顯示你試圖自己解決它的最低限度 – Christian 2014-09-10 21:26:43
我沒有評級,插入圖片。 我不知道該怎麼做,所以我問。 – user3066068 2014-09-11 11:37:24
請在imgur上發佈您的圖片,並在此處鏈接。 – Unihedron 2014-09-14 17:06:08