使用下面的代碼滾動 我有一個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