【问题标题】:Andengine getLastChild() errorAndengine getLastChild() 错误
【发布时间】:2014-07-30 12:59:35
【问题描述】:

我在运行 andengine 活动时收到以下错误

java:找不到符号符号:方法 getLastChild() 位置: org.anddev.andengine.entity.scene.Scene 类型的可变场景

我已经包含了所有的andengine jar 文件并将其添加为引用库。请帮助。这种方法现在是多余的吗?如果是这样,还有其他选择吗?或者是因为我在没有图形的计算机上开发我的游戏。我为安卓开发了许多应用程序。但是我在这个和引擎游戏开发方面遇到了问题。请帮忙。这是有错误的代码块。

public Scene onLoadScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());
    final Scene scene = new Scene(1);
    final int centerX = (CAMERA_WIDTH - this.mSplashTextureRegion.getWidth()) / 2;
    final int centerY = (CAMERA_HEIGHT - this.mSplashTextureRegion.getHeight()) / 2;
    final Sprite splash = new Sprite(centerX, centerY, this.mSplashTextureRegion);
    scene.getLastChild().attachChild(splash);
    return scene;
}

【问题讨论】:

    标签: java android eclipse opengl-es andengine


    【解决方案1】:

    1- 您正在使用已弃用的构造函数实例化 Scene

    2- 如果您只是想将 Sprite 添加到 Scene 中,请更改您的代码:

    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
        final Scene scene = new Scene();
        final int centerX =
                (CAMERA_WIDTH - this.mSplashTextureRegion.getWidth()) / 2;
        final int centerY =
                (CAMERA_HEIGHT -
                        this.mSplashTextureRegion.getHeight()) / 2;
        final Sprite splash = new Sprite(centerX,
                centerY, this.mSplashTextureRegion);
        scene.attachChild(splash);
        return scene;
    }
    

    3- 另一方面,如果您想要将Sprite 附加为另一个Entity 的子级,只需保留父级Entity 的引用,您将在其中附加其他子级, 在添加到Scene 之前或之后(没关系)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多