android-AndEngine:动画精灵无法与物理处理程序一起使用

android-AndEngine:动画精灵无法与物理处理程序一起使用,第1张

概述动画精灵未使用物理处理程序执行动画:我正在使用AndEngineGLES2的AnalogOnScreenControl移动精灵.该精灵是一个人,因此为了显示腿部动作,我将其制作为动画精灵:finalAnimatedSpriteperson=newAnimatedSprite(personX,personY,this.mPersonTextureRegion,vert

动画精灵未使用物理处理程序执行动画:

我正在使用AndEngine GLES2的AnalogonScreenControl移动精灵.该精灵是一个人,因此为了显示腿部动作,我将其制作为动画精灵:

final AnimatedSprite person = new AnimatedSprite(personX, personY,            this.mPersonTextureRegion, vertexBufferObjectManager);    person.setScaleCenterY(this.mPersonTextureRegion.getHeight());    person.setScale(2);

为了运动,我正在创建一个物理处理程序:

final PhysicsHandler physicsHandler = new PhysicsHandler(person);person.registerUpdateHandler(physicsHandler);scene.attachChild(person);

这是屏幕控件的代码:

    final AnalogonScreenControl analogonScreenControl = new AnalogonScreenControl(            0, CAMERA_HEIGHT                    - this.mOnScreenControlBaseTextureRegion.getHeight(),            this.mCamera, this.mOnScreenControlBaseTextureRegion,            this.mOnScreenControlKnobTextureRegion, 0.1f, 200,            this.getVertexBufferObjectManager(),            new IAnalogonScreenControlListener() {                @OverrIDe                public voID onControlChange(                        final BaSEOnScreenControl pBaSEOnScreenControl,                        final float pValueX, final float pValueY) {                     physicsHandler                     .setVeLocity(pValueX * 100, pValueY * 100);                     person.animate(new long[] { 200, 200, 200 }, 3, 5,                     false);                }

屏幕控件可完美地用于动画精灵,但是当我创建物理处理程序时,它不会设置动画.
但是,当我不创建物理处理程序时,它就会动画.
那么为什么在创建物理处理程序时不设置动画?

解决方法:

如果您始终重新启动动画,则动画将仅显示第一个图块.
使用“ isAnimationRunning()”检查动画是否正在运行.

public voID onControlChange(final BaSEOnScreenControl pBaSEOnScreenControl, final float pValueX, final float pValueY) {    if(person!= null)    {        //Move your person        final Vector2 veLocity = Vector2Pool.obtain(pValueX * 10, pValueY * 10);        person.setlinearVeLocity(veLocity);        Vector2Pool.recycle(veLocity);        //Check if person is moving. Don't start a new animation, when your animation is already running        if((pValueX != 0 || pValueY != 0) && person.isAnimationRunning() == false)        {            person.animate(new long[] { 200, 200, 200 },0,2,false);        }         //Stop animation, when there is no movement        else if(pValueX == 0 && pValueY == 0 && person.isAnimationRunning() == true)        {            person.stopAnimation();        }    }}
总结

以上是内存溢出为你收集整理的android-AndEngine:动画精灵无法与物理处理程序一起使用全部内容,希望文章能够帮你解决android-AndEngine:动画精灵无法与物理处理程序一起使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1076284.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存