在libgdx中做一些ontouch

时间:2015-03-21 20:19:47

标签: java android libgdx

我写了以下代码。它是屏幕中间的简单矩形。我希望矩形在y方向上移动-50 onClick(方向仅用于说明目的)。尽管尝试了各种方法。我无法让代码工作。我不确定我是否做了一些根本错误的事情。我希望从更好的学习思想中获得一些指导。

package com.mygdx.gameobjects;

import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class Hero extends Rectangle implements InputProcessor{

private Rectangle hero;
private Vector2 position;

public Hero(){
    position = new Vector2(x, y);
    hero = new Rectangle(position.x+68-10, position.y+204-30-20, 20, 20);
}

public void update (float delta) {

}

public void onClick() {
    position.y = -50;
}

public Rectangle getHero() {
    return hero;
}

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    onClick();
    return true;
}

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    return false;
}

@Override
public boolean keyDown(int keycode) {
    return false;
}

@Override
public boolean keyUp(int keycode) {
    return false;
}

@Override
public boolean keyTyped(char character) {
    return false;
}

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    return false;
}

@Override
public boolean mouseMoved(int screenX, int screenY) {
    return false;
}

@Override
public boolean scrolled(int amount) {
    return false;
}
}

0 个答案:

没有答案