- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试显示一个简单的纹理梯形(透视中的道路)。为此,我使用 SpriteBatch.draw以顶点数组作为参数。但结果却出人意料。
究竟出了什么问题?或者也许我使用了错误的方法?
这是代码:
@Override
public void create () {
texture = new Texture("road.jpg");
spriteBatch = new SpriteBatch();
float color = Color.toFloatBits(255, 255, 255, 255);
verts = new float[]{
0, 0, color, 0, 0,
Gdx.graphics.getWidth()/2-100, 300, color, 0, 1,
Gdx.graphics.getWidth()/2+100, 300, color, 1, 1,
Gdx.graphics.getWidth(), 0, color, 1, 0,
};
shapeRenderer = new ShapeRenderer();
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 0.5f, 1f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.rect(0, 0, 640, 300);
shapeRenderer.end();
spriteBatch.begin();
spriteBatch.draw(texture, verts, 0, verts.length);
spriteBatch.end();
}
最佳答案
draw(Texture texture, float[] spriteVertices, int offset, int count)
Draws a rectangle using the given vertices.
LibGDX 将这些矩形绘制为两个三角形,因此它分割了纹理。问题在于,矩形中的这些三角形大小相同,但梯形中的大小不同,因此它们会变形。
解决方案是使用投影或网格。
关于java - Libgdx:SpriteBatch.draw spriteVertecies 奇怪的 UV 坐标行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39258507/
这是一个关于 XNA 中 SpriteBatches 的性能问题。当你想在 XNA 中开始绘图时,你必须使用 spritebatch.Begin()。这就是你指定一堆东西的方式,比如使用的着色器。这会
SpriteBatch.SetProjectionMatrix(cam.combined) 使 Spritebatch 不绘制 block 和我的角色,但相机移动有效,但如果我不使用这行代码,一切都被
当游戏重置但 spritebatch 没有绘制时,我试图在屏幕上绘制一个快速加载的 Sprite 。我在 game.spritebatch.begin(); 上设置了一个断点,当我逐步执行时,没有绘制
当游戏重置但 spritebatch 没有绘制时,我试图在屏幕上绘制一个快速加载的 Sprite 。我在 game.spritebatch.begin(); 上设置了一个断点,当我逐步执行时,没有绘制
我一直想知道 spriteBatch 中的变换矩阵是如何实现的。我创建了一个2D相机,变换矩阵如下: if (needUpdate) transform
但是,我有一个奇怪的问题,在绘制时,图像的外部 1px 似乎被拉伸(stretch)以适合矩形,但内部仅拉伸(stretch)到一定范围,我正在绘制 48x48 的图 block ,但绘制了 500x
我想要做的是能够将变换矩阵推送和弹出到 SpriteBatch 中。我有 2 个 Sprite ,父级和子级,子级应该相对于父级进行缩放、旋转、平移。 我目前有一个使用纹理四边形的实现,但我认为使用内
我正在使用 LibGDX 开发一款自上而下的 RPG 游戏,并正在为我的游戏创建 Ortho.. 相机。然而,这样做时,现在只有我的图 block 纹理会渲染。渲染代码如下所示: 相机初始化为new
标题说明了一切。 使用同一个 SpriteBatcher 对象调用多个 Stage 的 draw() 方法是否仅发生在单个批处理中,或者它是一个 Stage =一批? 我有一种情况,我不想使用 Act
我想在单击按钮时旋转此 SpriteBatch 本身 @Override public void render() { SpriteBatch batch = new SpriteBatch(
我是 xna 编程的新手,我需要一些帮助... 我构建了一个静态背景的 2D 游戏在我当前的屏幕中有背景图像,左侧有 4 个大图像,我需要在右侧绘制 16 个小图像(50x50 或多或少) 所以这是我
使用 C# 和 XNA Framework,在调用 SpriteBatch.DrawString 方法时,“position”和“origin”参数有什么区别? 最佳答案 原点是与位置相关的偏移量。
SpriteBatch batcher = new SpriteBatch(); batcher.draw(TextureRegion region, float x,
我有一个 2d Sprite 数组,其中包含大约。 50 个 Sprite 。我想在渲染方法中绘制它们。我不知道什么会给我最好的表现。这是我想出的两种选择: batch.begin(); for(Sp
所以我一直在浏览和试验一些东西,但不太明白如何删除屏幕上预先存在的 spriteBatch。 基本上我发起了 batcher.begin(); (blah blah blah) AssetLoader
我想知道是否可以在纹理中保存 spriteBatch。 SpriteBatch batch = new SpriteBatch(); 在批处理中绘制了一些东西之后,我想将所有包含 SpriteBat
我已经实现了一个 OpenGL spritebatch,但是当对多个 sprite 使用相同的纹理时它只绘制第一个 sprite。例如:如果我用它来呈现字符串“Hello”的字形,它只会呈现“H”。
对我来说,这是 LibGDX 中发生过的最奇怪的事情之一。我已经在游戏中的所有其他状态中使用了这些确切的规范,但在不同的名称下,它们都工作正常,除了我的 ShopState,它根本不会渲染任何东西!这
我是 XNA 的新手,想在其基础上开发一个轻量级的 2D 引擎,并将实体组织成父子层次结构。我在画 child 的时候想到了矩阵,因为他们的位置、旋转和缩放都取决于他们的 parent 。 如果我使用
我在这里绘制了一组 Sprite ,在缩小时使用较小的 (4x4) 纹理,在放大时使用较大的 (16x16) 纹理。当缩放级别达到阈值时,就会发生交换。 然而,为了实现平滑过渡, Sprite (位于
我是一名优秀的程序员,十分优秀!