复制当前屏幕的图片只是比赛暂停之前对其进行模糊处理和渲染屏幕在游戏中暂停的持续时间 [英] Copy a picture of the current screen just before game pause blur it and render to screen in the duration of game pause
问题描述
我有一个实施暂停游戏画面模糊的状态gamepause过程中呈现的麻烦。我需要将当前屏幕即gamerunning的状态的图片或纹理,只是当用户暂停屏幕。也许其保存至内存,模糊它然后渲染它来屏来实现一个漂亮的模糊,高斯模糊效果,就像他们在流行的游戏,像愤怒的小鸟做的。
I am having trouble implementing a game pause blur screen to render during the gamepause state. I need to take a picture or texture of the current screen i.e gamerunning state, just when the user pauses the screen . Maybe store it to memory, blur it then render it to screen to achieve a nice blur, Gaussian blur effect like they do in popular games like Angry birds.
我试图用截图实施,但屏幕捕获的过程使得游戏冻结几秒钟,这是不是很好。
I tried implementing using a screenshot, but the process of screen capture makes the game freeze for a few seconds which is not nice.
下面是我的渲染code的一部分
Here is part of my render code
private void updatePlayerForUserInput(float delta)
{
if (Gdx.input.isKeyPressed(Keys.P) || pause)
{
ScreenShotSaver.saveScreenShot();
state = State.GAME_PAUSED;
if(!DEBUG_MODE)
{
toggleGestureProcessor(false);
setBackgroundTexture(new TextureRegion(applyBlurEffect(Gdx.files.external("madboy/screenshot.png"))));
gameScreenGamePauseMenu.sendInMenu();
}
}
}
有人能帮助实施的屏幕这样的
Can someone help implement s screen like this
这是我的愿望大大的影响的例子
1
:这里输入链接的描述
这是另外一个,类似的事情虽然
2:在这里输入链接的描述
This is an example of the effect I desire greatly 1 :enter link description here This is another one, similar thing though 2:enter link description here
这是根据游戏状态
private void render(float delta)
{
switch (state)
{
case GAME_READY:
renderReady();
break;
case GAME_RUNNING:
renderRunning(delta);
break;
case GAME_PAUSED:
renderPaused();
break;
case GAME_LEVEL_END:
renderLevelEnd();
break;
case GAME_OVER:
renderGameOver();
break;
}
}
private void update(float delta)
{
switch(state)
{
case GAME_READY:
updateReady();
break;
case GAME_RUNNING:
updateRunning(delta);
break;
case GAME_PAUSED:
updatePaused();
break;
case GAME_LEVEL_END:
updateLevelEnd();
break;
case GAME_OVER:
updateGameOver();
break;
}
}
荫使用Libgdx库和编程在Java
Iam using Libgdx library and programming in java
推荐答案
取而代之的是截图的图像保存到文件中,请尝试使用以下
Instead of saving the image of the screenshot to a file, try using the following
<一个href=\"http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureRegion.html#TextureRegion-com.badlogic.gdx.graphics.Texture-\"相对=nofollow> TextureRegion(纹理)
<一个href=\"http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html#Texture-com.badlogic.gdx.graphics.Pixmap-\"相对=nofollow>纹理(像素图)
<一个href=\"http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html#Pixmap-byte:A-int-int-%20Pixmap\"相对=nofollow>像素图(字节[],INT,INT)
在像素图的构造应该包含图像的字节的字节数组,这两个整数的偏移量和长度
The byte array in Pixmap's constructor should contain the image bytes, the two ints are offset and length
你怎么能拿图像作为字节示例:
Example of how you could get the image as bytes:
BufferedImage bufferedImage = new Robot().createScreenCapture(new Rectangle(startX, startY, width, height));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, format, outputStream);
outputStream.flush();
byte[] data = outputStream.toByteArray();
outputStream.close();
其中,格式
可以在一个字符串(下面的例子)的形式任何图像格式:
Where format
can be any image format in the form of a String (example below):
String format = "png";
String format = "jpg";
这篇关于复制当前屏幕的图片只是比赛暂停之前对其进行模糊处理和渲染屏幕在游戏中暂停的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!