final Sprite sprite = new Sprite(400, 420, 100, 50, vbo) { @Override public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y) { if (pSceneTouchEvent.isActionUp()) { // execute action } return true; }; }; scene.registerTouchArea(sprite); scene.attachChild(sprite);
二行目で記載しているように、タッチエリアをSceneに登録するのを忘れないでください。さもないと何も起こりません。 この例では、 isActionUp 条件を使用しています(プレイヤーがタッチして指を離す度にアクションが実行されることを意味します)。
Handling Touch Events:You can easily control Entitie`s touch events, by simply overriding onAreaTouched. In this short example, we will create new Sprite, register touch area and we will execute certain action everytime player touch our sprite.final Sprite sprite = new Sprite(400, 420, 100, 50, vbo) { @Override public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y) { if (pSceneTouchEvent.isActionUp()) { // execute action } return true; }; }; scene.registerTouchArea(sprite); scene.attachChild(sprite); You have to remember to register touch area to the scene, as we did in the penultimate line, otherwise nothing will happen. In our example we use isActionUp condition (which means action is executed every time player touch and than release his finger) |
More Touch Event Conditions:
|
注意事項
|