通过多点触控创建多精灵?
我正在使用 AndEngine 多点触控功能为我的游戏创建多精灵。但我有一个问题:
- 当我创建精灵时(在场景着陆事件中),我调用它的 StartGrowSize 方法。
- 当用户停止触摸(松开手指)精灵时,我需要调用其 StopGrowSize 方法。
问题是,我无法确定用户何时释放手指以及哪个手指(创建该精灵的手指)。
这是我的游戏中的一些代码:
@Override
public boolean onSceneTouchEvent(Scene arg0, TouchEvent arg1) {
if (arg1.isActionDown()) {
//Create a balloon
int balloonType = rndGenerator.nextInt(GlobalStatic.BalloonTypeTotal);
currentBalloon = new clsBalloon(arg1.getX(), arg1.getY(),
ANDBallonTextureRegion[balloonType].clone(), balloonType, this);
balloons.add(currentBalloon);
scnGameScene.ettBalloon.attachChild(currentBalloon);
}
return true;
}
在 clsBalloon 中:
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
if (pSceneTouchEvent.isActionUp()) {
StopGrowSize();
return true;
}
return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
}
但它不起作用。请帮助我,谢谢。
I'm using AndEngine multi-touch functions to create multi-sprite for my game. But I've a problem:
- When I create the sprite (in the Scene touch down event), I call its StartGrowSize method.
- When user stops touching (release his/her finger) at a sprite, I need call its StopGrowSize method.
The problem is, I CAN'T determine when the user releases her finger, and which finger (the finger that create that sprite).
This is some code in my game:
@Override
public boolean onSceneTouchEvent(Scene arg0, TouchEvent arg1) {
if (arg1.isActionDown()) {
//Create a balloon
int balloonType = rndGenerator.nextInt(GlobalStatic.BalloonTypeTotal);
currentBalloon = new clsBalloon(arg1.getX(), arg1.getY(),
ANDBallonTextureRegion[balloonType].clone(), balloonType, this);
balloons.add(currentBalloon);
scnGameScene.ettBalloon.attachChild(currentBalloon);
}
return true;
}
In the clsBalloon:
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
if (pSceneTouchEvent.isActionUp()) {
StopGrowSize();
return true;
}
return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
}
But it didn't work. Please help me, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,现在我的解决方案是创建一个预精灵来填充屏幕并注册其触摸处理程序,调整大小并设置其新面。
OK, so now my solution is that create a pre-sprite that fill the screen and register its touch handler, resize and set its new face.