AndEngine Chase Camera Not Following Body

Трудно ми е да накарам камерата за преследване да следва купето на автомобила. Занимавам се с примерния проект на Racer Game. Картата с плочки е 1024 x 786 и камерата е настроена да преследва купето на колата. Ето кода:

@Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        this.mScene = new Scene();
        //this.mScene.setBackground(new Background(0, 0, 0));

        /** Tiled Map Test **/
        try {
            final TMXLoader tmxLoader = new TMXLoader(this.getAssets(), this.mEngine.getTextureManager(), TextureOptions.BILINEAR_PREMULTIPLYALPHA, 
                    this.getVertexBufferObjectManager(), new ITMXTilePropertiesListener() {
                @Override
                public void onTMXTileWithPropertiesCreated(final TMXTiledMap pTMXTiledMap, final TMXLayer pTMXLayer, final TMXTile pTMXTile, 
                        final TMXProperties<TMXTileProperty> pTMXTileProperties) {
                    /* We are going to count the tiles that have the property "box=true" or "boxBool=true" set. */
                    if(pTMXTileProperties.containsTMXProperty("box", "true")) {
                        SpeedsterGameActivity.this.numBoxes++;
                    }
                }
            });
            // Load the TMX file into an Object
            this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/level3.tmx");

            this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText( SpeedsterGameActivity.this, "Box count in this TMXTiledMap: " + SpeedsterGameActivity.this.numBoxes, Toast.LENGTH_LONG).show();
                }
            });
        } catch (final TMXLoadException e) {
            Debug.e(e);
        }

        // Get the first TMX Layer and add it to the scene
        final TMXLayer tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);
        this.mScene.attachChild(tmxLayer);

        /* Make the camera not exceed the bounds of the TMXEntity. */
        this.mBoundChaseCamera.setBounds(0, 0, tmxLayer.getHeight(), tmxLayer.getWidth());
        this.mBoundChaseCamera.setBoundsEnabled(true);

        /* Debugging stuff */
        Debug.i( "Game Info", "Height & Width: " + tmxLayer.getHeight() + " x " + tmxLayer.getWidth() );

        int[] maxTextureSize = new int[1];
        GLES20.glGetIntegerv( GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
        Debug.i("Game Info", "Max texture size = " + maxTextureSize[0]);
        /**********/

        /* Calculate the coordinates for the face, so its centered on the camera. */
        final float centerX = (CAMERA_WIDTH - this.mVehiclesTextureRegion.getWidth()) / 2;
        final float centerY = (CAMERA_HEIGHT - this.mVehiclesTextureRegion.getHeight()) / 2;

        /* Create the sprite and add it to the scene. */
        final AnimatedSprite player = new AnimatedSprite(centerX, centerY, this.mVehiclesTextureRegion, this.getVertexBufferObjectManager());
        this.mBoundChaseCamera.setChaseEntity(player);
        /********************/

        this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 8, 1);

        //this.initRacetrack();
        //this.initRacetrackBorders();

        this.initCar();
        this.initObstacles();
        this.initOnScreenControls();

        this.mScene.registerUpdateHandler(this.mPhysicsWorld);

}

person Free Lancer    schedule 13.02.2012    source източник


Отговори (1)


Възможна причина за проблема е, че размерът на вашата камера също е 1024x786, следователно се показва целият правоъгълник на камерата и тъй като сте активирали граници, камерата не следва колата.

Пропуснете реда this.mBoundChaseCamera.setBoundsEnabled(true);.

Друг проблем е - камерата следва player обекта, към който губите препратката, след като onCreateScene завърши изпълнението. Вие не свързвате player обекта с физическо тяло, използвайки PhysicsConnector клас, така че няма причина да се мести.

В противен случай, ако каросерията и обектът на автомобила са създадени в initCarmethod, вие не задавате автомобила като обект на преследване.

person Jong    schedule 13.02.2012
comment
Да, така че очевидно не съм свързал физическото тяло с обекта на играча. Сега работи чудесно. Благодаря ти - person Free Lancer; 14.02.2012
comment
Chase Camera работи ли само с TMXTiledMap? Опитвам се да настроя преследващия обект, но не постигам успех. - person Dharmendra; 15.08.2012