关闭 L've2D 中的抗锯齿功能
我正在使用 Löve2D 编写一个小游戏。 Löve2D 是 Lua 的开源游戏引擎。 我遇到的问题是,当您在非整数位置绘制精灵时,某些抗锯齿过滤器会自动应用于精灵。
love.graphics.draw( sprite, x, y )
因此,当 x 或 y 不是圆形时(例如,x=100.24),精灵会显得模糊。 当精灵大小不均匀时也会发生同样的情况,因为 (x,y) 指向精灵的中心。 例如,一个 31x30 大的精灵将再次显得模糊,因为它的像素被绘制在非整数位置。
由于我使用的是像素艺术,所以我想完全避免这种情况,否则艺术会被这种效果破坏。 到目前为止,我使用的解决方法是通过在代码中调用 math.floor() 来强制坐标为圆形,并通过使用绘画程序添加一行或一列透明像素来强制所有精灵具有均匀的大小, 如果需要的话。
是否有一些命令可以在程序启动时调用来停用抗锯齿功能?
I'm using Löve2D for writing a small game. Löve2D is an open source game engine for Lua. The problem I'm encountering is that some antialias filter is automatically applied to your sprites when you draw it at non-integer positions.
love.graphics.draw( sprite, x, y )
So when x or y is not round (for example, x=100.24), the sprite appears blurred. The same happens when the sprite size is not even, because (x,y) points to the center of the sprite. For example, a sprite which is 31x30 big will appear blurred again, because its pixels are painted in non-integer positions.
Since I am using pixel art, I want to avoid this all the way, otherwise the art is destroyed by this effect. The workaround I am using so far is to force the coordinates to be round by littering the code with calls to math.floor(), and forcing all the sprites to have even sizes by adding a row or column of transparent pixels with the paint program, if needed.
Is there some command to deactivate the antialiasing I can call at program startup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果关闭抗锯齿功能,就会出现锯齿现象,因此得名! 为什么要在非整数位置绘制,您希望它对这些小数部分做什么? (将它们舍入到最接近的值?截断它们?如果它们为负怎么办?)
就我个人而言,我会保留低级图形,并更改代码以使用 x 和 y 的访问器来执行您需要的舍入或截断。 这可以保证您的像素艺术最终绘制在整数边界上,同时保留您稍后可能需要的抗锯齿功能。
If you turn off anti-aliasing you will just get aliasing, hence the name! Why are you drawing at non-integral positions, and what do you want it to do about those fractional parts? (Round them to the nearest value? Truncate them? What about if they're negative?)
Personally I would leave the low level graphics alone and alter your code to use accessors for x and y that perform the rounding or truncation that you require. This guarantees your pixel art ends up drawn on integer boundaries while keeping the anti-aliasing on that you might need later.
另一种可能的解决方法可能是使用 math.floor() 对整数进行四舍五入,作为一种廉价的解决方法。
Another possible work around may be to use math.floor() to round your integers as a cheap workaround.
如果有人感兴趣,我一直在其他地方询问,发现我所问的内容已经被请求为功能: http://love2d.org/forum/tracker.php?p=2&t=7
所以,我正在使用的 Löve 当前版本( 0.5.0)仍然不允许禁用抗锯齿过滤器,但该功能已经存在于引擎的 SVN 版本中。
In case anyone is interested, I've been asking in other places and found out that what I am asking is already requested as feature: http://love2d.org/forum/tracker.php?p=2&t=7
So, the current version of Löve that I'm using (0.5.0) still doesn't allow to disable the antialias filter, but the feature is already in the SVN version of the engine.
您可以通过将
love.graphics.setDefaultFilter("nearest", "nearest", 1)
添加到love.load()
来关闭抗锯齿功能you can turn off anti-aliasing by adding
love.graphics.setDefaultFilter("nearest", "nearest", 1)
tolove.load()