1

私はandEngineに非常に慣れていないので、画面にスプライトを追加して、指のタッチでスプライトを動かしたりズームしたりしたいと思っています。現在、シーンに複数のスプライトを追加でき、タッチでドラッグできます。

これが私のコードです:

public class Main extends SimpleBaseGameActivity {

    @Override

    private Camera camera;
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private ITextureRegion mFaceTextureRegion;
    private ITextureRegion mFaceTextureRegion2;

    private static final int CAMERA_WIDTH = 800;
    private static final int CAMERA_HEIGHT = 480;

    @Override
    public EngineOptions onCreateEngineOptions() {
            camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
            EngineOptions engineOptions = new EngineOptions(true,
                            ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
                                            CAMERA_WIDTH, CAMERA_HEIGHT), camera);
            return engineOptions;
    }

    @Override
    protected void onCreateResources() {
            BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

            this.mBitmapTextureAtlas = new BitmapTextureAtlas(
                            this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST);

            // background
            // this.background = new Sprite(0, 0,
            // BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas,
            // this, "ui_ball_1.png", 0, 0, 1, 1),
            // this.getVertexBufferObjectManager());
            this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
                            .createFromAsset(this.mBitmapTextureAtlas, this,
                                            "ui_ball_1.png", 0, 0);
            this.mFaceTextureRegion2 = BitmapTextureAtlasTextureRegionFactory
                            .createFromAsset(this.mBitmapTextureAtlas, this,
                                            "ui_ball_1.png", 0, 0);
            this.mBitmapTextureAtlas.load();
            // this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
            /*
             * this.mBitmapTextureAtlas = new
             * BitmapTextureAtlas(this.getTextureManager(), 32, 32,
             * TextureOptions.BILINEAR); this.mFaceTextureRegion =
             * BitmapTextureAtlasTextureRegionFactory
             * .createFromAsset(this.mBitmapTextureAtlas, this, "ui_ball_1.png", 0,
             * 0); this.mBitmapTextureAtlas.load();
             */
    }

    @Override
    protected Scene onCreateScene() {

            /*
             * this.scene = new Scene(); this.scene.attachChild(this.background);
             * this.scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
             * return this.scene;
             */
            this.mEngine.registerUpdateHandler(new FPSLogger());

            final Scene scene = new Scene();
            scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

            final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion
                            .getWidth()) / 2;
            final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion
                            .getHeight()) / 2;

            final Sprite face = new Sprite(centerX, centerY,
                            this.mFaceTextureRegion, this.getVertexBufferObjectManager()) {
                    @Override
                    public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                                    final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                            this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                                            pSceneTouchEvent.getY() - this.getHeight() / 2);
                            return true;
                    }
            };
            face.setScale(2);
            scene.attachChild(face);
            scene.registerTouchArea(face);

            final Sprite face2 = new Sprite(0, 0, this.mFaceTextureRegion2,
                            this.getVertexBufferObjectManager()) {
                    @Override
                    public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                                    final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                            this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                                            pSceneTouchEvent.getY() - this.getHeight() / 2);
                            return true;
                    }
            };

            face2.setScale(2);
            scene.attachChild(face2);
            scene.registerTouchArea(face2);

            scene.setTouchAreaBindingOnActionDownEnabled(true);
            return scene;

    }

}

今、タッチで各スプライトをズームしたいのですが、スプライトを特定の位置に移動するために使用できる setPosition のようなメソッドを見つけることができません。現在の機能に影響を与えずにこれを達成するのを手伝ってくれる人はいますか? これを行うためのコードまたは何らかの指示/方法の形式である可能性があります。前もって感謝します :)

4

1 に答える 1

0

EntityModifierを使用して、次の効果を得ることができます。

 @Override
      public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                        final float pTouchAreaLocalX, final float pTouchAreaLocalY) {

                this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                                pSceneTouchEvent.getY() - this.getHeight() / 2);
                this.clearEntityModifiers();
                this.RegisterEntityModifier(new ScaleModifier(1f,2f,4f));
                 //1f = time to convert the scale of sprite of 2f to 4f
                 //2f = initial scale
                 //4f = finish scale

                 //when you dont touch the sprite back to normal scale
                if(event.getAction()== MotionEvent.ACTION_UP) {
                  this.clearEntityModifiers();
                  this.RegisterEntityModifier(new ScaleModifier(1f,4f,2f));
                  }
                 //you also can work with "MotionEvent.ACTION_DOWN" and
                 //MotionEvent.ACTION_MOVE
                return true;
        }
于 2012-12-13T02:44:58.973 に答える