简体   繁体   English

Libgdx像素化GUI效果

[英]Libgdx Pixellated GUI Effect

In LibGDX, I am currently trying to achieve the effect of a pixellated GUI, meaning the buttons are pixellated, like an 8-bit theme. 在LibGDX中,我目前正在尝试实现像素化GUI的效果,这意味着按钮是像素化的,就像8位主题一样。

When I make my GUI elements, such as a TextButton, I am using images that are small, say 34x16 pixels, but I am rendering them on a large resolution like 1920x1080 . 当我制作我的GUI元素(例如TextButton)时,我使用的是较小的图像,例如34x16像素,但我使用像1920x1080这样的大分辨率渲染它们。 What is the best way to render such a small image at a high resolution? 以高分辨率渲染如此小图像的最佳方法是什么?

My thoughts were to use stage.setViewport(WIDTH,HEIGHT) , and set the width and height to a scaled down resolution, so the gui elements wouldn't be so big. 我的想法是使用stage.setViewport(WIDTH,HEIGHT) ,并将宽度和高度设置为按比例缩小的分辨率,因此gui元素不会那么大。 This works, however when adding elements things go wrong. 这有效,但是当添加元素时出错了。 在此输入图像描述

This my stage/table currently, using a scaled down resolution. 这是我的舞台/桌子,使用缩小的分辨率。 I am adding widgets using to the table like this: 我正在使用这样的表添加小部件:

    table.add(playButton);
    table.row();
    table.add(title);

but as you can see, the table.row() makes a row that is much too large, perhaps a row fit for a larger resolution. 但正如您所看到的, table.row()会产生一个太大的行,可能是一行适合更大的分辨率。 Is there any way to change the gap that is made by the row? 有没有办法改变行所造成的差距? I would have thought that the gap would be zero, and by using table.add().pad() you could change the gap, but I am not doing any of that. table.add().pad()认为差距为零,并且通过使用table.add().pad()你可以改变差距,但我没有做任何事情。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Ninepatch Ninepatch

This is a common issue in all apps. 这是所有应用中的常见问题。 To overcome this, images which can be safely resized in parts are used. 为了克服这个问题,使用可以安全地重新调整大小的图像。 they are called ninepatches. 他们被称为九个补丁。

Here is a nice Tutorial about using them in libgdx. 这是一篇关于在libgdx中使用它们的好教程


Distance Field Fonts 距离场字体

Although you haven't mentioned it here, you'd also find font sizing (pixellated fonts) as an issue. 虽然你在这里没有提到它,但你也会发现字体大小(像素化字体)是一个问题。 For that Distance Field Fonts are used. 对于该距离 ,使用字段字体

Hope this helps. 希望这可以帮助。

I would say don't worry about scaling them up and making the virtual resolution bigger. 我想说不要担心扩大它们并使虚拟分辨率更大。 If you want to see picture still pixelated when you scale it use Texture filter. 如果要在缩放时看到图像仍然像素化,请使用纹理滤镜。 For your case you want to use Nearest filter. 对于您的情况,您想使用最近的过滤器。 use it like this: 像这样用它:

yourTexture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);

where yourTexture is the texture that you have all your bitmaps and skin elements on. 其中yourTexture是您拥有所有位图和外观元素的纹理。 If you are using texturePacker than you can specify the filter before packing too. 如果您使用的是TexturePacker,那么您也可以在打包之前指定过滤器。 Or just open the .pack file and on the top you will see filtering options, and edit those to Nearest. 或者只是打开.pack文件,在顶部你会看到过滤选项,并编辑它们到最近。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM