2

我目前有一个游戏,其中有一张 480x3200 的地图,一个人从顶部掉下来。摄像机跟随人,人落下时有平台。平台需要是可触摸的,这样我才能在游戏过程中旋转和移动它们,所以我把它做成了一个图像,而它最初只是一个精灵。

当我将它从精灵更改为图像时,一切正常,除了当人跌倒时(相机开始向下移动并跟随人),平台也随着相机移动,所以看起来它也在下落。平台应该只停留在一个位置,而不是随着相机移动,这样随着相机不断向下移动,平台最终会从视野中消失。

设置平台并将其添加到舞台

@Override
public void show() {
    ...
    platform = new Image(new Texture(Gdx.files.internal("img_platform.png")));
    platform.setX(2);
    platform.setY(110);
    platform.setOrigin(platform.getWidth() / 2, platform.getHeight() / 2);

@Override
public void render(float delta) {
    ....
    stage.addActor(platform);   
}

我查看了 API,无法确定是否需要更改相机、舞台或图像,或者其他我没有想到的东西。有任何想法吗?

编辑:

public WorldRenderer(FallDown game, SpriteBatch batch, World w) {
    this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT); 
    this.cam.position.set(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2, 0);
    this.cam.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
    cam.position.set(CAMERA_WIDTH / 2, 105, 0);
    stage = new Stage(480, 800, true);

    platformTexture = new Image(new Texture(Gdx.files.internal("img_platform.png")));
    platformTexture.setX(2);
    platformTexture.setY(100);
    platformTexture.setOrigin(platformTexture.getWidth() / 2, platformTexture.getHeight() / 2);
    ...

}

public void render(float delta) { 
    stage.addActor(platformTexture);
    moveCamera();
    ...
}

private void moveCamera() {
    if (Person.getPosition().y < cam.position.y) 
        cam.position.y = Person.getPosition().y;
    cam.update();
}

...
4

2 回答 2

1

通常这件事是通过将你的相机设置在演员身上(它正在下降)并向下移动你的演员来实现的。随着演员向下移动,相机将跟随它保持平台静止。

这有帮助吗??

于 2013-07-04T05:43:06.410 回答
0

我决定不使用图像,而是只使用 Sprite。它允许我做我需要做的一切,而且我没有舞台只是当前屏幕的问题

于 2013-07-10T23:34:53.873 回答