3

我已经使用 spritesheet(使用 TexturePacker 生成)成功地显示了动画。但是当我为场景设置透明背景时,它不起作用!它以黑色背景显示。但是对于其他颜色,它显示的是指定的颜色。

m_Scene.setBackground(new Background(Color.RED));//displayed with red Bg

m_Scene.setBackground(new Background(Color.TRANSPARENT));//displayed with black Bg

下面是我的完整方法 onCreateScene() 和我的 Activity 扩展 SimpleBaseGameActivity

这个问题的原因可能是什么?谁能帮我解决这个问题?

@Override
protected Scene onCreateScene() {

    m_Scene = new Scene();
    m_Scene.setBackground(new Background(Color.TRANSPARENT));
    mTiledTextureRegion = getTiledTextureFromPack("sample");
    mAnimatedSprite = new AnimatedSprite(0, 0, mTiledTextureRegion,
            this.getVertexBufferObjectManager());
    m_Scene.attachChild(mAnimatedSprite);
    mAnimatedSprite.animate(160);
    return m_Scene;
}

我有两个活动“FirstActivity”和“SecondActivity”。“FirstActivity”扩展了 Activity,“SecondActivity”扩展了 SimpleBaseGameActivity。我正在做的是,我在单击按钮时从 FirstActivity 启动 SecondActivity。

   public void onGoButtonCLick(View view) {

      startActivity(new IntentFirstActivity.this,SecondActivity.class));
}

并且在清单中将 SecondActivity 设为透明

android:theme="@android:style/Theme.Translucent"

现在输出屏幕在其他地方显示透明但如果设置场景区域变黑m_Scene.setBackground(new Background(Color.TRANSPARENT));

请检查以下链接以查看输出:

m_Scene.setBackground(new Background(Color.RED));//以红色Bg显示

https://docs.google.com/file/d/0BwMxWp4Tk7MEUE53dEVnM3NoTlk/edit

m_Scene.setBackground(new Background(Color.TRANSPARENT));//以黑色Bg显示

https://docs.google.com/file/d/0BwMxWp4Tk7MEVWZYWGJDa3o2Ums/edit

4

1 回答 1

0

首先,我认为您想让手机屏幕像窗口一样透明,因为最终必须在背景中;p 但是后来我看到您以错误的方式使用场景。

可能onCreateScene 方法用于扩展Scene 的类中。这意味着您不能在另一个场景之上创建另一个场景。而不是创造new Scene()使用this.attachChild(sprite)

于 2014-05-21T20:31:15.907 回答