を示すゲームの写真です。私の意見では、照明のためにシェーダを使うことができますが、あなたが望む効果はbox2d bodyとbox2dlightを使用することによってのみ達成できます。
public class MyGdxGame extends ApplicationAdapter implements InputProcessor{
SpriteBatch batch;
OrthographicCamera cam;
RayHandler rayHandler;
World world;
Texture texture;
PointLight box2d;
Box2DDebugRenderer renderer;
Vector3 vector3;
Array<Body> bodies;
@Override
public void create() {
Pixmap pixmap=new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fillRectangle(0,0, pixmap.getWidth(), pixmap.getHeight());
world=new World(new Vector2(0,-9.8f),false);
rayHandler=new RayHandler(world);
renderer=new Box2DDebugRenderer();
bodies=new Array<>();
vector3=new Vector3();
batch=new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(true,40,64);
texture=new Texture(pixmap);
rayHandler.setAmbientLight(0,0,0,.5f);
box2d=new PointLight(rayHandler, 100, new Color(1,1,1,1), 25, 10, 10);
Gdx.input.setInputProcessor(this);
{
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(20, 10);
bodyDef.type = BodyDef.BodyType.StaticBody;
PolygonShape p = new PolygonShape();
p.setAsBox(8, 1.5f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = p;
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
Sprite sprite=new Sprite(texture);
sprite.setSize(8*2,1.5f*2);
body.setUserData(sprite);
}
{
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(20, 40);
bodyDef.type = BodyDef.BodyType.StaticBody;
PolygonShape p = new PolygonShape();
p.setAsBox(8, 1.5f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = p;
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
Sprite sprite=new Sprite(texture);
sprite.setSize(8*2,1.5f*2);
body.setUserData(sprite);
}
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(1,1,1,1);
world.step(1/60f,4,6);
renderer.render(world,cam.combined);
batch.setProjectionMatrix(cam.combined);
batch.begin();
world.getBodies(bodies);
for (Body body:bodies){
Sprite sprite=(Sprite) body.getUserData();
sprite.setPosition(body.getPosition().x-sprite.getWidth()/2,body.getPosition().y-sprite.getHeight()/2);
sprite.draw(batch);
}
batch.draw(texture,100,100);
batch.end();
rayHandler.setCombinedMatrix(cam);
rayHandler.updateAndRender();
}
@Override
public void resize(int width, int height) {
}
@Override
public void dispose() {
batch.dispose();
rayHandler.dispose();
}
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
vector3.set(screenX,screenY,0);
Vector3 v=cam.unproject(vector3);
box2d.setPosition(v.x,v.y);
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
}
出力は、次のとおりです。
恐ろしい!それは完全に動作します、ありがとう。 – Joao