Libgdx-重置Vector3以在不同的情况下多次使用它



好吧,伙计们,我需要你们的帮助,

我正试图弄清楚如何重置Vector3,在多种情况下使用它,。。。

例如,我得到了一个代码,其中为了测试目的,我有几个按钮,其中第一个使用引用Vector3的Matrix4来翻译播放器,

我该怎么做:按钮1按下

Vector3: 1,2,3

按钮2按下

Vector3: reset,  new values 2,4,6

用于理解的伪代码。。

似乎找不到正确的方法,现在不在电脑后面,代码会及时到来,

也许如果其他如果可以做的把戏,但不确定:3

有什么提示吗?

供参考,编辑qn:

stage.addActor(tpS);
ghost = new Matrix4();
tpIleApprentis.addListener((new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
TpS.hide();
translation = new Vector3(86.83f,96f,63.5f);
ghost.getTranslation(translation);
translation.set(0,0,0);
PlayerSystem.characterComponent.ghostObject.setWorldTransform(ghost);
return false;
}
}));

好吧,当我在Ashley ECS和Bullet System工作时,我最终使用了这样的方法,基本上删除了播放器并重新创建了播放器,是的,这个解决方案不是最优的,但它是有效的,事实上,这已经足够了:

tpIleApprentis0.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
gameWorld.remove(gameWorld.character);
gameWorld.remove(gameWorld.characterHair);
gameWorld.remove(gameWorld.characterEar);
gameWorld.remove(gameWorld.characterScar);
gameWorld.remove(gameWorld.characterMouth);
System.out.println("Teleportation Ville des Apprentis");
gameWorld.createPlayer(86.8f,64.4f,-96.6f);
return false;
}
});

Ashley引擎创建并位于游戏世界级;remove方法是ashley-ecs系统的一部分,涉及子弹部件对于创建方法,它是相同的:

public void remove(Entity entity)
{
engine.removeEntity(entity);
bulletSystem.removeBody(entity);
}
public void createPlayer(float x, float y, float z)
{
character = playerFactory.createMaleCharacter(bulletSystem, x, y, z);
characterHair = playerFactory.createMaleHair(x, y, z);
characterEar = playerFactory.createMaleEar(x, y, z);
characterMouth = playerFactory.createMaleMouth(x, y, z);
characterScar = playerFactory.createMaleScar(x, y, z);
engine.addEntity(character);
engine.addEntity(characterHair);
engine.addEntity(characterEar);
engine.addEntity(characterMouth);
engine.addEntity(characterScar);

如果有人能找到更好的解决方案?但正如所说,实际上这个解决方案符合我的需求

在重用Vector3之前,您不需要"重置"它,只需使用其中一个set方法用新值覆盖它即可。

https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/math/Vector3.html#set-浮动浮动

Vector3 vector = new Vector3(1, 2, 3);
...
vector.set(2, 4, 6); // reuse

相关内容

最新更新