本文整理汇总了Java中com.badlogic.gdx.utils.ScreenUtils类的典型用法代码示例。如果您正苦于以下问题:Java ScreenUtils类的具体用法?Java ScreenUtils怎么用?Java ScreenUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScreenUtils类属于com.badlogic.gdx.utils包,在下文中一共展示了ScreenUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: takeScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public static void takeScreenshot() {
byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0,
Gdx.graphics.getBackBufferWidth(),
Gdx.graphics.getBackBufferHeight(), true);
Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss");
PixmapIO.writePNG(
Gdx.files.external(dateFormat.format(new Date()) + ".png"),
pixmap);
pixmap.dispose();
}
示例2: takeScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public static void takeScreenshot() {
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(),
Gdx.graphics.getBackBufferHeight());
FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
dir.mkdirs();
FileHandle f = dir.child(System.currentTimeMillis() + ".png");
try {
PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
try {
writer.setFlipY(true);
writer.write(f, pixmap);
} finally {
writer.dispose();
}
} catch (IOException ex) {
throw new CubesException("Error writing PNG: " + f, ex);
} finally {
pixmap.dispose();
}
Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
示例3: takeScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public static void takeScreenshot() {
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
dir.mkdirs();
FileHandle f = dir.child(System.currentTimeMillis() + ".png");
try {
PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
try {
writer.setFlipY(true);
writer.write(f, pixmap);
} finally {
writer.dispose();
}
} catch (IOException ex) {
throw new CubesException("Error writing PNG: " + f, ex);
} finally {
pixmap.dispose();
}
Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
示例4: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
private static Pixmap getScreenshot (int x, int y, int w, int h, boolean yDown) {
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例5: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
private static Pixmap getScreenshot(final int x, final int y, final int w, final int h, final boolean yDown)
{
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown)
{
// Flip the pixmap upside down
final ByteBuffer pixels = pixmap.getPixels();
final int numBytes = w * h * 4;
final byte[] lines = new byte[numBytes];
final int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++)
{
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例6: renderScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
@Override
public void renderScreenshot(IWritableScreenshot ss, Rect glRect) {
final ITextureData texData;
if (ss.isVolatile()) {
TextureRegion textureRegion = ScreenUtils.getFrameBufferTexture(glRect.x, glRect.y, glRect.w, glRect.h);
GdxTextureUtil.setDefaultTextureParams(textureRegion.getTexture());
textureRegion.flip(false, true);
texData = VolatileTextureData.fromRegion(textureRegion, false);
} else {
Pixmap pixels = GdxScreenshotUtil.screenshot(glRect);
texData = PixelTextureData.fromPremultipliedPixmap(pixels);
}
Rect glSize = renderEnv.getGLClip();
ss.setPixels(texData, Dim.of(glSize.w, glSize.h));
}
示例7: screenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public void screenshot(String filename) {
if (fbo != null) {
FileHandle local = Gdx.files.local(filename);
try {
FileHandle fh;
do {
fh = local;
} while (fh.exists());
byte[] frameBufferPixels = ScreenUtils.getFrameBufferPixels(0, 0, G.CANVAS_WIDTH, G.CANVAS_HEIGHT, true);
Pixmap pixmap = new Pixmap(G.CANVAS_WIDTH, G.CANVAS_HEIGHT, Pixmap.Format.RGBA8888);
pixmap.getPixels().put(frameBufferPixels);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
fbo.end();
fbo.dispose();
} catch (Exception e) {
}
}
}
示例8: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例9: render
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
if (screenshot == null) {
int width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight();
for (int i = 0; i < 100; i++)
batch.draw(badlogic, MathUtils.random(width), MathUtils.random(height));
batch.flush();
FileHandle file = FileHandle.tempFile("screenshot-");
System.out.println(file.file().getAbsolutePath());
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
try {
PNG writer = new PNG((int)(pixmap.getWidth() * pixmap.getHeight() * 1.5f));
// writer.setCompression(Deflater.NO_COMPRESSION);
writer.write(file, pixmap);
writer.dispose();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
screenshot = new Texture(file);
}
batch.draw(screenshot, 0, 0);
batch.end();
}
示例10: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例11: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown) {
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例12: getScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
}
return pixmap;
}
示例13: show
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
/**
* Initializes the mesh with the pixels of the given group.
*
* The result vectors must be in {@link #scaledView} coordinates.
*
* @param toEdit
* @param resultOrigin
* @param resultSize
*/
public void show(Group toEdit, Vector2 resultOrigin, Vector2 resultSize) {
int x = MathUtils.round(resultOrigin.x), y = MathUtils
.round(resultOrigin.y), width = (int) resultSize.x, height = (int) resultSize.y;
minX = x;
minY = y;
maxX = minX + width;
maxY = minY + height;
scaledView.localToStageCoordinates(temp.set(x, y));
int stageX = MathUtils.round(temp.x), stageY = MathUtils.round(temp.y);
Batch batch = controller.getPlatform().getBatch();
batch.setProjectionMatrix(combinedMatrix);
fbo.begin();
batch.begin();
toEdit.draw(batch, 1f);
batch.end();
currModifiedPixmap = new PixmapRegion(ScreenUtils.getFrameBufferPixmap(
stageX, stageY, width, height), stageX, stageY);
fbo.end();
}
示例14: getMapScreenShot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
public Pixmap getMapScreenShot()
{
float oldCameraZoom = getCamera().zoom;
float oldCameraX = getCamera().position.x;
float oldCameraY = getCamera().position.y;
MapUtils.adjustCamera(getCamera(), grid);
final FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, WIDTH, HEIGHT, false);
fbo.begin();
batch.setProjectionMatrix(getCamera().combined);
batch.begin();
for(int i = 0; i < grid.getHexs().length; i++)
{
drawHexagon(grid.getHexs()[i], batch);
}
batch.end();
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, WIDTH, HEIGHT);
fbo.end();
//fbo.dispose();
getCamera().zoom = oldCameraZoom;
getCamera().position.x = oldCameraX;
getCamera().position.y = oldCameraY;
return pixmap;
}
示例15: takeScreenshot
import com.badlogic.gdx.utils.ScreenUtils; //导入依赖的package包/类
/**
* Takes a screenshot of the current game state and saves it in the assets directory
*/
public void takeScreenshot() {
byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
PixmapIO.writePNG(Gdx.files.local("screenshots/screenshot.png"), pixmap);
pixmap.dispose();
}