AndEngine GLES2有一个完整的场景运动条纹/模糊的例子,效果很好,但我想将运动模糊应用于特定的精灵。
有点像我不希望我的角色运动模糊,只需要法术(精灵)。
这就是我现在用来做运动模糊的东西,它只是AndEngine的例子,但问题是它似乎拍摄整个屏幕的快照,应用aplha,然后将其合并到下一个屏幕的框架,我只想将这种“alpha”模糊效果应用于各个精灵。
@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
return new Engine(pEngineOptions) {
private static final int RENDERTEXTURE_COUNT = 2;
private boolean mRenderTextureInitialized;
private final RenderTexture[] mRenderTextures = new RenderTexture[RENDERTEXTURE_COUNT];
private final Sprite[] mRenderTextureSprites = new Sprite[RENDERTEXTURE_COUNT];
private int mCurrentRenderTextureIndex = 0;
@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 = this.mCamera.getSurfaceWidth();
final int surfaceHeight = this.mCamera.getSurfaceHeight();
final int currentRenderTextureIndex = this.mCurrentRenderTextureIndex;
final int otherRenderTextureIndex = (currentRenderTextureIndex + 1) % RENDERTEXTURE_COUNT;
this.mRenderTextures[currentRenderTextureIndex].begin(pGLState, false, true);
{
/* Draw current frame. */
super.onDrawFrame(pGLState);
/* Draw previous frame with reduced alpha. */
if(!firstFrame) {
if(Info.motionStreaking) {
this.mRenderTextureSprites[otherRenderTextureIndex].setAlpha(0.9f);
this.mRenderTextureSprites[otherRenderTextureIndex].onDraw(pGLState, this.mCamera);
}
}
}
this.mRenderTextures[currentRenderTextureIndex].end(pGLState);
/* Draw combined frame with full alpha. */
{
pGLState.pushProjectionGLMatrix();
pGLState.orthoProjectionGLMatrixf(0, surfaceWidth, 0, surfaceHeight, -1, 1);
{
this.mRenderTextureSprites[otherRenderTextureIndex].setAlpha(1);
this.mRenderTextureSprites[otherRenderTextureIndex].onDraw(pGLState, this.mCamera);
}
pGLState.popProjectionGLMatrix();
}
/* Flip RenderTextures. */
this.mCurrentRenderTextureIndex = otherRenderTextureIndex;
}
private void initRenderTextures(final GLState pGLState) {
final int surfaceWidth = this.mCamera.getSurfaceWidth();
final int surfaceHeight = this.mCamera.getSurfaceHeight();
final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
for(int i = 0; i <= 1; i++) {
this.mRenderTextures[i] = new RenderTexture(DodgingGame.this.getTextureManager(), surfaceWidth, surfaceHeight);
this.mRenderTextures[i].init(pGLState);
final ITextureRegion renderTextureATextureRegion = TextureRegionFactory.extractFromTexture(this.mRenderTextures[i]);
this.mRenderTextureSprites[i] = new Sprite(0, 0, renderTextureATextureRegion, vertexBufferObjectManager);
}
}
};
}
如何更改它以适用于特定的精灵而不是整个可见屏幕?
答案 0 :(得分:0)
您可以使用粒子系统来创建运动模糊效果。