2
這個觸摸事件永遠不會觸發緩解作用。我一直在通過例子和源代碼,現在我對做我想做的最好的方法有些困惑。如何正確使用觸摸監聽器/事件和andEngine
我畫一個精靈到現場。我希望該精靈能夠通過EaseFunction移動到用戶觸摸事件的座標。
這是到目前爲止的代碼:
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
// ===========================================================
// Fields
// ===========================================================
private Camera mCamera;
private BitmapTextureAtlas mTexture;
private TextureRegion mFaceTextureRegion;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public Engine onLoadEngine() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}
@Override
public void onLoadResources() {
this.mTexture = new BitmapTextureAtlas(64, 32, TextureOptions.BILINEAR);
this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/boxface.png", 0, 0);
this.getEngine().getTextureManager().loadTexture(this.mTexture);
}
@Override
public Scene onLoadScene() {
this.getEngine().registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
final int x = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth())/2;
final int y = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight())/2;
final Sprite face = new Sprite(x, y, this.mFaceTextureRegion);
scene.attachChild(face);
face.setPosition(134, 200);
//這是我嘗試實現觸摸監聽器和代碼//是不是?
scene.setOnAreaTouchListener(new IOnAreaTouchListener() {
//@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,ITouchArea pTouchArea, float pTouchAreaLocalX,float pTouchAreaLocalY) {
if(pSceneTouchEvent.isActionDown()) {
int facePosX = (int) (pSceneTouchEvent.getX() - face.getWidth()/2);
int facePosY = (int) (pSceneTouchEvent.getY() - face.getHeight()/2);
face.registerEntityModifier(new MoveModifier(500, face.getX(), facePosX, face.getY(),facePosY,EaseQuadIn.getInstance()));
}
return false;
}
});
return scene;
}
@Override
public void onLoadComplete() {
}
終於我很確定我需要使用pScene.registerTouchArea(face);和 pScene.setTouchAreaBindingEnabled(true);
任何澄清會有很大的用途。 謝謝
我找到了答案。但即時新的。所以我必須等待4個小時才能回答我自己的帖子。 – 2012-02-19 06:31:44