Android游戏引擎libgdx使用教程:舞台和演员的游戏实例(二)
再看一下FirstActor。
声明一个Texture用于绘制。在构造方法中获取到高度和宽度,以便于后期的hit时间判断。
package com.cnblogs.htynkn.domain;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class FirstActor extends Actor {
Texture texture;
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
batch.draw(texture, this.x, this.y);
}
@Override
public Actor hit(float x, float y) {
if (x > 0 && y > 0 && this.height > y && this.width > x) {
return this;
} else {
return null;
}
}
@Override
public boolean touchDown(float x, float y, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public void touchDragged(float x, float y, int pointer) {
// TODO Auto-generated method stub
}
@Override
public void touchUp(float x, float y, int pointer) {
// TODO Auto-generated method stub
}
public FirstActor(String name) {
android开发,青软培训