gpt4 book ai didi

android - SetTexture 和 Sprites 没有按预期工作! (LibGDX)

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:39 25 4
gpt4 key购买 nike

我在互联网上搜索和广泛搜索,但我还没有找到答案。我有一个名为 GameIcon 的对象,它扩展了 Sprite。关于它的一切都很好,除了质地。这是我的 GameIcon 类代码。

package com.xx4everPixelatedxx.gaterunner.sprites;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.xx4everPixelatedxx.gaterunner.GateRunner;

import javax.xml.soap.Text;

/**
* Created by Michael Jan on 8/17/2015.
*/
public class GameIcon extends Sprite {
private int vX = 3;
private int vY = 3;
private int r = 9;
private int rotation;

private Vector3 position;

private Texture texture;

public GameIcon(int x, int y) {
position = new Vector3(x, y, 0);
texture = new Texture(Gdx.files.internal("icon_players/icon1.png"));
setTexture(texture);
}

public void update() {
position.add(vX, vY, 0);
rotation = rotation + r;

rotation = rotation % 360;

setRotation(rotation);
setOriginCenter();
}

public void addPosition(int x, int y) {
position.add(x, y, 0);
setOriginCenter();
}

public void negateVelocityX() {
vX = -vX;
}

public void negateRotation() {
r = -r;
}

public Vector3 getPosition() {
return position;
}

public int getvY() {
return vY;
}

public void setvY(int vY) {
this.vY = vY;
}

public int getvX() {
return vX;
}

public void setvX(int vX) {
this.vX = vX;
}
}

这是 icon1.png: https://i.gyazo.com/1d52f5e58b227f08809f6c14ae4c94a4.png

这是我得到的: https://i.gyazo.com/1881a9392955af34de5c55b9b8fac391.png

请注意,图像和粒子的旋转是有意的。问题是大方 block 应该是纹理(icon1.png),我不知道如何解决这个问题。

(没有足够的声誉来发布图片)

最佳答案

我不熟悉 LibGDX,但这可能与您可能覆盖 TextureRegion.texture 这一事实有关。您可以尝试使用您的父类 Sprite(Texture)像这样的构造函数:

...
public class GameIcon extends Sprite {
private int vX = 3;
private int vY = 3;
private int r = 9;
private int rotation;

private Vector3 position;

//private Texture texture;

public GameIcon(int x, int y) {
super(new Texture(Gdx.files.internal("icon_players/icon1.png")))
position = new Vector3(x, y, 0);
}
...

如 Tenfour04 在评论中所述,此方法有效是因为父级的构造函数应用了纹理的宽度和高度,而 setTexture() 没有。

关于android - SetTexture 和 Sprites 没有按预期工作! (LibGDX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32373104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com