2

このビデオと同じようにスプライトを動かそうとしています。AndEngineを使用しています。AndEngine Box2D物理拡張機能を使用して、移動とジャンプを完了した忍者(スプライト)を移動するにはどうすればよいですか。

これが私のMainActivity1.classです:

public class MainActivity1 extends BaseGameActivity {

    Scene scene;
    private TiledTextureRegion mPlayerTextureRegion;
    private BoundCamera mBoundChaseCamera;
    private static final int CAMERA_WIDTH = 1024;
    private static final int CAMERA_HEIGHT = 600;
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private BitmapTextureAtlas mBitmapTextureAtlasp;
    private BitmapTextureAtlas mBitmapTextureAtlashm;
    private TextureRegion mhomeTextureRegion;
    private BitmapTextureAtlas mBitmapTextureAtlas1;
    AnimatedSprite player;
    private Body playerBody;
    private PhysicsWorld mPhysicsWorld;
    private BitmapTextureAtlas sheetBitmapTextureAtlas1;
    private BitmapTextureAtlas sheetBitmapTextureAtlasplaybtn1;
    private TiledTextureRegion mTargetTextureRegionplaybtn1;


    public void onLoadComplete() {
        // TODO Auto-generated method stub

    }

    public Engine onLoadEngine() {
        // TODO Auto-generated method stub
        final Display display = getWindowManager().getDefaultDisplay();
        int cameraWidth = display.getWidth();
        int cameraHeight = display.getHeight();
    //      Toast.makeText(this, "The tile the player is walking on will be highlighted.", Toast.LENGTH_LONG).show();
        this.mBoundChaseCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(cameraWidth, cameraHeight), this.mBoundChaseCamera));
    }

    public void onLoadResources() {
        // TODO Auto-generated method stub

        mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
                TextureOptions.BILINEAR_PREMULTIPLYALPHA);

        mBitmapTextureAtlas1 = new BitmapTextureAtlas(1024, 1024,
                TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.sheetBitmapTextureAtlasplaybtn1 = new BitmapTextureAtlas(512, 512);
        mTargetTextureRegionplaybtn1 = BitmapTextureAtlasTextureRegionFactory
                .createTiledFromAsset(sheetBitmapTextureAtlasplaybtn1, this,
                        "gfx/gameplay_stormstrike_full.png",  0, 212,1, 1);
    this.mBitmapTextureAtlasp = new BitmapTextureAtlas(512, 512, TextureOptions.DEFAULT);
        this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlasp, this, "gfx/storm_strike.png", 0, 0, 1, 1); // 72x128


        mTargetTextureRegion1 = BitmapTextureAtlasTextureRegionFactory
                .createTiledFromAsset(sheetBitmapTextureAtlas1, this,
                        "gfx/kolobok_04_walk.png",  0, 212,12, 1);

        this.mEngine.getTextureManager().loadTexture(this.sheetBitmapTextureAtlas);
        this.mEngine.getTextureManager().loadTexture(this.sheetBitmapTextureAtlas1);
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlashm, this, "gfx/loading_ipad.png", 0, 0);
        mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);
        mEngine.getTextureManager().loadTexture(sheetBitmapTextureAtlasplaybtn1);

        mEngine.getTextureManager().loadTexture(mBitmapTextureAtlasp);
        mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas1);
        mEngine.getTextureManager().loadTexture(mBitmapTextureAtlashm);

    }

    public Scene onLoadScene() {
        // TODO Auto-generated method stub
        this.mEngine.registerUpdateHandler(new FPSLogger());

        scene = new Scene();
        scene.setBackground(new ColorBackground(0, 0, 0.8784f));


        this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 8, 1);
        final Sprite help = new Sprite(50, 70, mProjectileTextureRegionhelp);
        scene.attachChild(help);
        help.setVisible(false);




        player = new AnimatedSprite(100, 200, 150,150,this.mPlayerTextureRegion)
        {
            @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                switch(pSceneTouchEvent.getAction()) {
                    case TouchEvent.ACTION_DOWN:


                     playerBody.setLinearVelocity(10f,-10f);


                        break;
                    case TouchEvent.ACTION_MOVE:




                        break;
                    case TouchEvent.ACTION_UP:

                        break;
                }
                return true;
            }
        };
        scene.attachChild(player);
        scene.registerTouchArea(player);
        projectilesToBeAdded.add(player);





        AnimatedSprite playerbtn = new AnimatedSprite(10, 200, this.mTargetTextureRegionplaybtn1)
        {
            @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                switch(pSceneTouchEvent.getAction()) {
                    case TouchEvent.ACTION_DOWN:

                        playerBody.applyForce(new Vector2(200,-1500), new Vector2(playerBody.getWorldCenter()));






                        break;
                    case TouchEvent.ACTION_MOVE:



                        break;
                }
                return true;
            }
        };
        scene.attachChild(playerbtn);
        scene.registerTouchArea(playerbtn);


        final FixtureDef carFixtureDef = PhysicsFactory.createFixtureDef(10.0f, 0.5f, 0.5f);
        this.playerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, this.player, BodyType.DynamicBody, carFixtureDef);

        this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(this.player, this.playerBody, true,false));






        scene.setTouchAreaBindingEnabled(true);

        this.scene.registerUpdateHandler(this.mPhysicsWorld);


        return scene;
    }
}
4

1 に答える 1

2

サンプルビデオで行われる動きには、いくつかの異なる概念が含まれます。AndEngineの例を読んでいる必要があります。特に、次の2つを見てください。

  • org.andengine.examples.PhysicsExample
  • org.andengine.examples.PhysicsJumpExample

ジャンプを開始するには、忍者の物理ボディでapplyForce()を呼び出します。バウンスを生成するには、忍者と彼がバウンドしている表面に摩擦が必要です。以下のコメントに従って、いくつかの追加の定義を提供します。ちなみに、これらは私からのものではなく、マニュアルからのものです。

密度

フィクスチャ密度は、親ボディの質量特性を計算するために使用されます。密度はゼロまたは正にすることができます。通常、すべての器具に同様の密度を使用する必要があります。これにより、スタッキングの安定性が向上します。密度を設定しても、ボディの質量は調整されません。これを行うには、ResetMassDataを呼び出す必要があります。

速度

キネマティクスでは、速度はオブジェクトの位置の変化率であり、オブジェクトの速度と運動方向の仕様に相当します。速度はオブジェクトの移動速度のみを表し、速度はオブジェクトの移動速度と方向の両方を示します。

摩擦

摩擦は、オブジェクトを互いにリアルにスライドさせるために使用されます。Box2Dは静的摩擦と動的摩擦をサポートしていますが、両方に同じパラメーターを使用しています。Box2Dでは摩擦が正確にシミュレートされ、摩擦強度は法線力に比例します(これはクーロン摩擦と呼ばれます)。摩擦パラメータは通常0から1の間に設定されますが、負でない値にすることもできます。摩擦値が0の場合は摩擦がオフになり、値が1の場合は摩擦が強くなります。2つの形状間で摩擦力を計算する場合、Box2Dは2つの親フィクスチャの摩擦パラメータを組み合わせる必要があります。これは幾何平均で行われます:

float32 friction;

friction = sqrtf(shape1->friction * shape2->friction);

したがって、1つの固定具の摩擦がゼロの場合、接点の摩擦はゼロになります。

于 2013-02-22T01:01:59.187 に答える