再看一下FirstActor。

      声明一个Texture用于绘制。在构造方法中获取到高度和宽度,以便于后期的hit时间判断。

Java代码
  1. package com.cnblogs.htynkn.domain;    

  2. import com.badlogic.gdx.Gdx;    

  3. import com.badlogic.gdx.graphics.Texture;    

  4. import com.badlogic.gdx.graphics.g2d.SpriteBatch;    

  5. import com.badlogic.gdx.scenes.scene2d.Actor;    

  6. public class FirstActor extends Actor {    

  7. Texture texture;    

  8. @Override    

  9. public void draw(SpriteBatch batch, float parentAlpha) {    

  10. batch.draw(texture, this.x, this.y);    

  11. }    

  12. @Override    

  13. public Actor hit(float x, float y) {    

  14. if (x > 0 && y > 0 && this.height > y && this.width > x) {    

  15. return this;    

  16. } else {    

  17. return null;    

  18. }    

  19. }    

  20. @Override    

  21. public boolean touchDown(float x, float y, int pointer) {    

  22. // TODO Auto-generated method stub    

  23. return false;    

  24. }    

  25. @Override    

  26. public void touchDragged(float x, float y, int pointer) {    

  27. // TODO Auto-generated method stub    

  28. }    

  29. @Override    

  30. public void touchUp(float x, float y, int pointer) {    

  31. // TODO Auto-generated method stub    

  32. }    

  33. public FirstActor(String name) {    

  34. android开发,青软培训