繁体   English   中英

控制精灵不能完全正常工作

[英]Control of sprite not completely working

public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
            final Body carBody = CityRacerActivity.this.mCarBody;

            final Vector2 velocity = Vector2Pool.obtain(pValueX * 5, pValueY * 5);
            carBody.setLinearVelocity(velocity);
            Vector2Pool.recycle(velocity);

            final float rotationInRad = (float)Math.atan2(-pValueX, pValueY);
            carBody.setTransform(carBody.getWorldCenter(), rotationInRad);

            CityRacerActivity.this.mCar.setRotation(MathUtils.radToDeg(rotationInRad));
        }

所以这部分工作。

OnControlChange以正确的方向移动精灵但是当我放开控制时,它似乎每次都将车辆向上移动。

我在Android上使用andengine。

我的代码基于racergameactivity示例,但这个错误似乎已经存在于示例本身。

        public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
            final Body carBody = CityRacerActivity.this.mCarBody;

            final float rotationInRad = (float)Math.atan2(-pValueX, pValueY);

            if ((pValueX == 0) && (pValueY == 0))
            {
                    //Don't turn the body/sprite of the car


            }else
            {
                    carBody.setTransform(carBody.getWorldCenter(), rotationInRad);
                    //turn the car body in the direction of movement
                    CityRacerActivity.this.mCar.setRotation(MathUtils.radToDeg(rotationInRad));
            }

            //set the velocity
            final Vector2 velocity = Vector2Pool.obtain(pValueX * 5, pValueY * 5);
            carBody.setLinearVelocity(velocity);
            Vector2Pool.recycle(velocity);
        }

这就像我想要的那样,但我不确定这是否是我应该处理它的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM