首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pixel perfect 2d相机

Pixel perfect 2d相机
EN

Stack Overflow用户
提问于 2018-02-01 07:40:22
回答 1查看 1.3K关注 0票数 0

我有一个非常简单的脚本,它更新我的正交相机在给定的分辨率,以便它准确地缩放视图,以像素完美。

下面是一些相关的代码:

代码语言:javascript
复制
OrthographicSetting get_override(int size)
{
    return Overrides.FirstOrDefault(x => x.OrthographicSize == size);
}

void update_ortho()
{
    m_last_size = Screen.height;

    float ref_size = (OrthographicSize / PixelsPerUnit) * 0.5f;

    OrthographicSetting or = get_override(m_last_size);
    float ppu = or != null ? or.PixelsPerUnit : PixelsPerUnit;
    float ortho_size = (m_last_size / ppu) * 0.5f;
    float multiplier = Mathf.Max(1, Mathf.Round(ortho_size / ref_size));

    ortho_size /= multiplier;

    this.GetComponent<Camera>().orthographicSize = ortho_size;

    Debug.Log(m_last_size + " " + ortho_size + " " + multiplier + " " + ppu);
}

[System.Serializable]
public class OrthographicSetting
{
    public int OrthographicSize;
    public float PixelsPerUnit;
}

OrthographicSetting get_override(int size)
{
    return Overrides.FirstOrDefault(x => x.OrthographicSize == size);
}

有了这个,我可以为每个解决方案指定一组覆盖。

我目前的设置是每单位使用100像素。我所有的精灵都使用无压缩的点过滤。然而,我仍然得到了奇怪的结果。90%的精灵渲染正常,但有些似乎渲染不正确。

这里有一个截图来说明:

EN

回答 1

Stack Overflow用户

发布于 2018-02-01 08:17:32

我可能已经解决了这个问题。我使用的是开启了像素捕捉的精灵着色器。如果我关闭像素捕捉,这个问题似乎或多或少会消失。我仍然偶尔会遇到游戏对象位置不好的问题,但我不知道如何避免这个问题……

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48553246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档