使用下面的代码滚动 我有一个Surfaceview线程和正在生成(更改),第一行(行),每帧,然后复制一个位置(行)在常规的SurfaceView位图上做滚动效果,然后我继续绘制其他的东西。那么这就是我真正想要的,但是即使我为屏幕外位图创建单独的画布,我也无法使其工作。它只是不滚动。如何滚动屏幕内存位图
我换句话说,我有一个内存位图,与Surfaceview画布相同,我需要每帧滚动(移位)一行,然后用新的随机纹理替换顶部行,然后在常规Surfaceview上绘制它帆布。
这是我认为会工作;
我surfaceChanged,我指定位图,画布和启动线程:
@Override
public void surfaceCreated(SurfaceHolder holder) {
intSurfaceWidth = mSurfaceView.getWidth();
intSurfaceHeight = mSurfaceView.getHeight();
memBitmap = Bitmap.createBitmap(intSurfaceWidth, intSurfaceHeight,
Bitmap.Config.ARGB_8888);
memCanvas = new Canvas(memCanvas);
myThread = new MyThread(holder, this);
myThread.setRunning(true);
blnPause = false;
myThread.start();
}
我的线索,只显示必要的中间传动部分:
@Override
public void run() {
while (running) {
c = null;
try {
// Lock canvas for drawing
c = myHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
// Scroll down off screen canvas and hopefully underlying bitmap bitmap
Rect src = new Rect(0, 0, intSurfaceWidth, intSurfaceHeight - 1);
Rect dst = new Rect(0, 1, intSurfaceWidth, intSurfaceHeight);
memCanvas.drawBitmap(memBitmap, src, dst, null);
// Note scrolling up like this works fine
// Rect src = new Rect(0, 1, intSurfaceWidth, intSurfaceHeight + 1);
// Rect dst = new Rect(0, 0, intSurfaceWidth, intSurfaceHeight);
// memCanvas.drawBitmap(memBitmap, src, dst, null);
// Create random one line(row) texture bitmap
textureBitmap = Bitmap.createBitmap(imgTexture, 0, rnd.nextInt(intTextureImageHeight), intSurfaceWidth, 1);
// Now add this texture bitmap to top of screen canvas and hopefully underlying bitmap
memCanvas.drawBitmap(textureBitmap,
intSurfaceWidth, 0, null);
// Draw above updated off screen bitmap to regular canvas, at least I thought it would update (save changes) shifting down and add the texture line to off screen bitmap the off screen canvas was pointing to.
c.drawBitmap(memBitmap, 0, 0, null);
// Other drawing to canvas comes here
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
myHolder.unlockCanvasAndPost(c);
}
}
}
}
对于我的比赛隧道运行,https://market.android.com/details?id=com.zubima.TunnelRun,现在我有一个工作的解决方案,我有一个位图阵列,表面高度的大小,我用我的随机纹理填充,然后在每个帧的循环中下移。我每秒获得50帧,但我认为我可以通过滚动位图来做得更好。
完成题外话,但在市场上的应用程序描述是全文,没有段落,没有什么......你应该构造它!首先想到的是:tldr – WarrenFaith 2012-01-08 15:08:44
好的建议,补充段落谢谢,但不知道你的意思是“全文......没有”。这是一个纯文本字段,我不能将图像添加到此。 – DKDiveDude 2012-01-08 16:05:36
是的,但是你的文本格式非常难看。我不想在说明中提供完整的“如何使用/播放”指南。想想它更像是一个广告文字。总结列表中的一些很酷的功能,让读者对你的游戏感兴趣。 – WarrenFaith 2012-01-08 17:46:35