自定义视图中的绘制函数出现问题(Android Honeycomb)
我制作了一款游戏(名为 Block Crusher),可以从 Market Today 下载。由于现在有越来越多的 HoneyComb 平板电脑问世,我想让我的游戏与这些平板电脑兼容。
但当我尝试在摩托罗拉 Xoom 上运行游戏时遇到了一些问题。
在这个游戏中我有一个自定义视图。该视图将游戏板绘制到屏幕上。它用不同种类的颜色绘制块。当你点击它们时,你会摧毁这些方块,其余的就会掉下来。
在蜂窝之前的设备上,这可以正常工作。在 Motorola Xoom 上我遇到绘图问题。不知何故,块的旧位置没有被清除,这使得块很长,而不是掉落。 (不确定我写下来是否可以理解,但我希望如此)。
我什至在我的绘图函数中添加了以下代码,以便在在其上绘制新框架之前完全擦除画布:
@Override
public void draw(Canvas canvas)
{
// Disable super.draw call to make the control transparent.
// super.draw(canvas);
// Clear the entire screen before starting drawing.
mTransparantPaint = new Paint();
mTransparantPaint.setColor(0x00000000);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mTransparantPaint);
但不知何故,当块掉落时,我在重新绘制时遇到了一些问题。
有人知道为什么我在 Honeycomb 上遇到这个问题吗?和HoneyComb的硬件加速2D图形管线有什么关系吗?我没有为此启用或禁用任何内容。
如果您有 Honeycomb 平板电脑并想查看问题,可以从 http://peerke.no-ip.info/morbur/Svn-267.1/MorburActivity-release.apk
I made a game (called Block Crusher) that's downloadable from the Market Today. Since there are more and more HoneyComb tablet's come out these days, I wanted to make my game compatible for those tablet's.
But I run into some problems when I tried to run my Game on the Motorola Xoom.
In this game I have a custom View. This view draws the game board onto the screen. It draws blocks in different kind of colors. When you click on them you destroy the blocks and the rest will fall down.
On a pre-Honeycomb device this works without problems. On the Motorola Xoom I have drawing problems. Somehow the old position of the blocks is not wiped out and that makes the blocks very long, instead of falling down. (Not sure if I wrote this down that it's understandable, but I hope so).
I even added the following code to my draw function to completly wipe the canvas before drawing a new frame on it:
@Override
public void draw(Canvas canvas)
{
// Disable super.draw call to make the control transparent.
// super.draw(canvas);
// Clear the entire screen before starting drawing.
mTransparantPaint = new Paint();
mTransparantPaint.setColor(0x00000000);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mTransparantPaint);
But somehow I have some problems with redrawing when the blocks are falling down.
Anyone knows why I'm having this problems on Honeycomb? Has it anything to do with the hardware accellerated 2D graphics pipeline of HoneyComb? I have not enabled or disabled anything for that.
If you have a Honeycomb tablet and want to see the problem, you can download a development build from http://peerke.no-ip.info/morbur/Svn-267.1/MorburActivity-release.apk
我发现 Honeycomb 上总是需要 super.draw(canvas) 。这在以前版本的 Android 中不会出现问题。
I figured out that the super.draw(canvas) is always needed on Honeycomb. That didn't give problems in previous versions of android.