gpt4 book ai didi

android - Andengine MotionStreak示例及截图

转载 作者:行者123 更新时间:2023-11-29 22:08:14 25 4
gpt4 key购买 nike

我想通过将场景渲染到 RenderTexture 中来捕获屏幕,我已在 MotionStreakExample 中尝试过这样做一切正常,但是当我将代码复制到我的项目时,我得到了这张图片(也许纹理有一些问题......我无法理解): enter image description here

@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
return new Engine(pEngineOptions) {

private boolean mRenderTextureInitialized;

private RenderTexture mRenderTextures ;
private Sprite mRenderTextureSprites ;

@Override
public void onDrawFrame(final GLState pGLState) throws InterruptedException {
final boolean firstFrame = !this.mRenderTextureInitialized;

if(firstFrame) {
this.initRenderTextures(pGLState);
this.mRenderTextureInitialized = true;
}

final int surfaceWidth = WIDTH*2;
final int surfaceHeight = HEIGHT;


this.mRenderTextures.begin(pGLState, false, true);
{
/* Draw current frame. */
super.onDrawFrame(pGLState);

/* Draw previous frame with reduced alpha. */
}
this.mRenderTextures.end(pGLState);


{
pGLState.pushProjectionGLMatrix();
pGLState.orthoProjectionGLMatrixf(0, surfaceWidth, 0, surfaceHeight, -1, 1);
{
this.mRenderTextureSprites.setAlpha(1);
this.mRenderTextureSprites.onDraw(pGLState, this.mCamera);
}
pGLState.popProjectionGLMatrix();
}

if (needToSave)
{
needToSave = false;
FSHelper.saveBitmapToFile(this.mRenderTextures.getBitmap(pGLState), SAVED_PATH+"/test.png");
}

/* Flip RenderTextures. */

}

private void initRenderTextures(final GLState pGLState) {
final int surfaceWidth = WIDTH*2;
final int surfaceHeight = HEIGHT;

final VertexBufferObjectManager vertexBufferObjectManager = mEngine.getVertexBufferObjectManager();
this.mRenderTextures = new RenderTexture(mEngine.getTextureManager(), surfaceWidth, surfaceHeight);
this.mRenderTextures.init(pGLState);

final ITextureRegion renderTextureATextureRegion = TextureRegionFactory.extractFromTexture(this.mRenderTextures);
this.mRenderTextureSprites = new Sprite(0, 0, renderTextureATextureRegion, vertexBufferObjectManager);
}
};
}

附言。这个红色背景的十字架是我场景中的 Sprite 。

最佳答案

Andengine 已经有了截屏的基础设施,你试过用那个吗?看看这个例子: https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/ScreenCaptureExample.java

关于android - Andengine MotionStreak示例及截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10248232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com