AndEngine场景触摸事件
我正在使用 AndEngines onSceneTouchEvent 方法为精灵创建跳跃效果。
我遇到的问题是,如果用户触摸屏幕,例如三次点击屏幕,精灵将继续跳跃,我想要的是它只接收 1 次点击,并为一次触摸执行一次跳跃。
这是我正在使用的导致此问题的原因。 正如你所看到的,我尝试使用 mIsJumping 布尔值,当玩家与不可见的矩形碰撞时,它再次设置为 false 以允许再次跳跃。
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if(pSceneTouchEvent.isActionUp()){
if(mIsJumping == false){
SequenceEntityModifier jumpModifier = new SequenceEntityModifier(
new MoveYModifier(.6f, player.getY(), player.getY() - 250, EaseQuadOut.getInstance()),
new MoveYModifier(.6f, player.getY() - 250, player.getY(), EaseBounceOut.getInstance()));
player.registerEntityModifier(jumpModifier);
}
}
return false;
}
根据我上面的描述,我如何才能只注册一次触摸并跳跃一次,直到精灵与矩形碰撞?
I am using AndEngines onSceneTouchEvent method to create a jump affect for a sprite.
The issue i am having is that if the user touches the screen for instance they triple tap the screen the sprite will keep jumping, what i want is for it to receive only 1 click and do one jump for the one touch.
Here is what i am using which is causing this issue.
As you see i try to use a mIsJumping boolean and when the player collides with a invisible rectangle, it is set to false again to allow for jumping again.
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if(pSceneTouchEvent.isActionUp()){
if(mIsJumping == false){
SequenceEntityModifier jumpModifier = new SequenceEntityModifier(
new MoveYModifier(.6f, player.getY(), player.getY() - 250, EaseQuadOut.getInstance()),
new MoveYModifier(.6f, player.getY() - 250, player.getY(), EaseBounceOut.getInstance()));
player.registerEntityModifier(jumpModifier);
}
}
return false;
}
From my description above how can i only register one touch even and jump once until the sprite collides with the rectangle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还有一个更简单的解决方案 - 使用
IEntityModifierListener
。以这种方式创建侦听器:
将其注册到将玩家向下移动的
MoveYModifier
。所以,当修改结束(跳转修改结束)时,mIsJumping
将为假。另外,请记住在跳转开始时将mIsJumping
设置为true
。There's even an easier solution - use an
IEntityModifierListener
.Create the listener this way:
Register it to the
MoveYModifier
that moves the player down. So, when the modifying ends (The jump modification ends),mIsJumping
will be false. Also, remember to setmIsJumping
totrue
when the jump starts.