将box2dLight附加到scene2d.Actor

问题描述 投票:0回答:1

作为我游戏的一部分,我正在舞台上移动一辆车并尝试将大灯放在同一个地方。我正在对CAR进行操作,以便CAR的位置更新将由scene2d.actions.Actions处理。这是我用来设置灯光的代码:

rayHandler.setCombinedMatrix(stage.getCamera().combined);
rayHandler.useCustomViewport(viewport.getScreenX(), viewport.getScreenY(),
                viewport.getScreenWidth(), viewport.getScreenHeight());
coneLight = new ConeLight(rayHandler, 50, Color.YELLOW, 150, 400, 150,0,45);

但问题是,它需要光线定位的位置,现在将车灯的位置放在车内很棘手(或者我错过了全世界都知道的东西),因为汽车可以驶向任何地方方向,有没有办法将光线附加到演员身上?或者我们应该总是计算光的位置

有点像actor.getX() + cosDeg(actor.direction())*length;

例如,见图像enter image description here

java libgdx scene2d box2dlights
1个回答
0
投票

获取精灵顶点的位置解决了这个问题

import static com.badlogic.gdx.graphics.g2d.Batch.X2;
import static com.badlogic.gdx.graphics.g2d.Batch.X3;
import static com.badlogic.gdx.graphics.g2d.Batch.Y2;
import static com.badlogic.gdx.graphics.g2d.Batch.Y3;

... #somewhere in render method.
coneLight.setPosition(sprite.getVectors()[X2], sprite.getVectors()[Y2]);
© www.soinside.com 2019 - 2024. All rights reserved.