gpt4 book ai didi

android - AndEngine 追逐相机不跟随 body

转载 作者:行者123 更新时间:2023-11-29 22:12:41 24 4
gpt4 key购买 nike

我很难让追逐相机跟随车身。我正在修补 Racer Game 示例项目。瓷砖 map 为 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);

}

最佳答案

问题的一个可能原因是您的摄像头尺寸也是 1024x786,因此会显示完整的摄像头矩形,并且由于您启用了边界,摄像头不会跟随汽车。

省略行 this.mBoundChaseCamera.setBoundsEnabled(true);

另一个问题是 - 一旦 onCreateScene 完成执行,相机将跟随您失去对它的引用的 player 对象。您没有使用 PhysicsConnector 类将 player 对象连接到物理体,因此它没有理由移动。

否则如果车身和实体是在initCar方法中创建的,则您不会将汽车设置为追逐实体。

关于android - AndEngine 追逐相机不跟随 body ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9256335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com