我已经使用 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 extends 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;
}
我有两个 Activity “FirstActivity”和“SecondActivity”。 “FirstActivity”扩展了 Activity,“SecondActivity”扩展了 SimpleBaseGameActivity。 我正在做的是,通过单击按钮从 FirstActivity 启动 SecondActivity。
public void onGoButtonCLick(View view) {
startActivity(new IntentFirstActivity.this,SecondActivity.class));
}
并且 SecondActivity 在 list 中变得透明
android:theme="@android:style/Theme.Translucent"
如果设置m_Scene.setBackground(new Background(Color.TRANSPARENT));
请检查以下链接以查看输出:
m_Scene.setBackground(new Background(Color.RED));
//显示红色背景
https://docs.google.com/file/d/0BwMxWp4Tk7MEUE53dEVnM3NoTlk/edit
m_Scene.setBackground(new Background(Color.TRANSPARENT));
//黑色背景显示
https://docs.google.com/file/d/0BwMxWp4Tk7MEVWZYWGJDa3o2Ums/edit
最佳答案
起初我以为你想让你的手机屏幕像 window 一样透明,因为最终一定有东西在背景中;p 但后来我看到你以错误的方式使用场景。
可能onCreateScene 方法用于扩展Scene 的类。这意味着您不能在另一个场景之上创建另一个场景。而不是创建 new Scene()
使用 this.attachChild(sprite)
关于android - AndEngine如何获取透明动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23781474/