Buena tarde comunidad, tengo una pregunda y es referente a box2d: - TopicsExpress



          

Buena tarde comunidad, tengo una pregunda y es referente a box2d: estoy creando un suelo como una caja y quiero que el suelo tenga la misma dimension en x que tiene la cámara en su campo de vision en lo ancho, pero cuando la creo escede el tamaño, no se ve al inicio pero cuando muevo la cámara me doy cuenta de ese detalle, y quiero saber por que pasa, o como se soluciona. espero haber sido claro en mi pregunta y espero que me ayuden. gracias. Código: import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.BodyDef; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; import com.badlogic.gdx.physics.box2d.CircleShape; import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; public class ScreenPrueba extends ScreenAdapter{ private World world; private Box2DDebugRenderer b2dr; private OrthographicCamera camera; public void show() { //Gdx.input. world = new World(new Vector2(0, -9.81f), true); b2dr = new Box2DDebugRenderer(); camera = new OrthographicCamera(); camera.setToOrtho(false, 416, 256); BodyDef bdef = new BodyDef(); FixtureDef fdef = new FixtureDef(); //piso bdef.type = BodyDef.BodyType.StaticBody; bdef.position.set(0, 20); PolygonShape shape = new PolygonShape(); shape.setAsBox(416, 32); fdef.shape = shape; fdef.density = 0; Body body = world.createBody(bdef); body.createFixture(fdef); shape.dispose(); //bola bdef = new BodyDef(); fdef = new FixtureDef(); bdef.type = BodyDef.BodyType.DynamicBody; bdef.position.set(208, 150); CircleShape circle = new CircleShape(); circle.setRadius(6); fdef.shape = circle; body = world.createBody(bdef); body.createFixture(fdef); circle.dispose(); } public void render(float deltaTime) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); world.step(deltaTime, 6, 2); b2dr.render(world, camerabined); if(Gdx.input.isKeyPressed(Keys.LEFT)) { camera.position.x -= (100 * deltaTime); camera.update();} if(Gdx.input.isKeyPressed(Keys.RIGHT)){ camera.position.x += (100 * deltaTime); camera.update();} if(Gdx.input.isKeyPressed(Keys.UP)){ camera.position.y += (100 * deltaTime); camera.update();} if(Gdx.input.isKeyPressed(Keys.DOWN)){ camera.position.y -= (100 * deltaTime); camera.update();} } public void dispose() { } }
Posted on: Fri, 12 Sep 2014 20:33:57 +0000

Trending Topics



Recently Viewed Topics




© 2015