0

TMXTiledMap で BoundCamera を使用しており、AnalogOnScreenControl を使用して HUD に接続しています。しかし、マップを別の位置にスクロールすると、コントロールが使用できなくなります。助けてください! ありがとう!

私のコード:

private void createControls() {
        mOnScreenControlTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.BILINEAR);
        mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0);
        mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0);
        mOnScreenControlTexture.load();
}

private void setAnalogControls() {
        analogOnScreenControl = new AnalogOnScreenControl(
                10, Constants.HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight() - 10, this.camera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, 200, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() {
                    @Override
                    public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
                        float velX = 0, velY = 0;
                        velX = pValueX;
                        velY = pValueY;
                        spaceShip.setVelocity(velX * 200, velY * 200);
                    }

                    @Override
                    public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
                    }
                });
        analogOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        analogOnScreenControl.getControlBase().setAlpha(0.3f);
        analogOnScreenControl.getControlBase().setScaleCenter(0, 128);
        analogOnScreenControl.getControlBase().setScale(0.7f);
        analogOnScreenControl.getControlKnob().setAlpha(0.4f);
        analogOnScreenControl.getControlKnob().setScale(0.7f);
        analogOnScreenControl.refreshControlKnobPosition();

        hud.setChildScene(analogOnScreenControl);
}

public void loadLevel(int level) {
        try {
            final TMXLoader tmxLoader = new TMXLoader(activity.getAssets(),
                    this.engine.getTextureManager(),
                    TextureOptions.BILINEAR_PREMULTIPLYALPHA,
                    activity.getVertexBufferObjectManager());
            this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/lvl" + level
                    + ".tmx");
        } catch (final TMXLoadException e) {
            Debug.e(e);
        }

        final TMXLayer tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);
        mBoundChaseCamera.setBounds(0, 0, tmxLayer.getWidth(), tmxLayer.getHeight());
        mBoundChaseCamera.setBoundsEnabled(true);

        final Sprite invisibleSprite = new Sprite(0, 0, activity.getRegLifeLeft(), getVertexBufferObjectManager());
        invisibleSprite.setPosition((Constants.WIDTH - invisibleSprite.getWidth()) / 2, (Constants.HEIGHT - invisibleSprite.getHeight()) / 2);
        invisibleSprite.registerEntityModifier(new MoveXModifier(1000, invisibleSprite.getX(), tmxLayer.getWidth()));
        gameScene.attachChild(invisibleSprite);

        mBoundChaseCamera.setChaseEntity(invisibleSprite);
        gameScene.attachChild(tmxLayer);

        ArrayList<TMXObjectGroup> groups = mTMXTiledMap.getTMXObjectGroups();
        for (TMXObjectGroup group : groups) {
            if (group.getName().equals("enemies")) {
                ArrayList<TMXObject> enemies = group.getTMXObjects();
                int i = 0;
                for (TMXObject enemy : enemies) {
// DO SOMETHING
                }
            }
        }
}

private void startGame() {
                loadLevel(1);
}

@Override
public EngineOptions onCreateEngineOptions() {
        this.mBoundChaseCamera = new BoundCamera(0, 0, Constants.WIDTH, Constants.HEIGHT);
        camera = new Camera(0, 0, Constants.WIDTH, Constants.HEIGHT);
        EngineOptions en = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(Constants.WIDTH, Constants.HEIGHT), this.mBoundChaseCamera);

        return en;
}

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

@Override
protected Scene onCreateScene() {
        hud = new HUD();
        mainScene = new Scene();
        mainScene.setBackground(new Background(Color.BLACK));

        gameScene = new Scene();
        gameScene.setBackground(new Background(Color.BLACK));

        startGame();

        mBoundChaseCamera.setHUD(hud);

                mainScene.setChildScene(gameScene);

        return mainScene;
}

誰か助けてください!

4

0 に答える 0