@Override protected void createWorld (World world) { world.setContactListener(this);
world.setContactListener(new ContactListener() { @Override public void beginContact (Contact contact) {
@Override protected void createWorld (World world) { world.setContactListener(this);
private void setUpWorld() { world = WorldUtils.createWorld(); world.setContactListener(this); setUpBackground(); setUpGround(); setUpRunner(); createEnemy(); }
boolean doSleep = true; world = new World(gravity, doSleep); world.setContactListener(this);
public PlayScreen(MarioBros game){ atlas = new TextureAtlas("Mario_and_Enemies.pack"); this.game = game; //create cam used to follow mario through cam world gamecam = new OrthographicCamera(); //create a FitViewport to maintain virtual aspect ratio despite screen size gamePort = new FitViewport(MarioBros.V_WIDTH / MarioBros.PPM, MarioBros.V_HEIGHT / MarioBros.PPM, gamecam); //create our game HUD for scores/timers/level info hud = new Hud(game.batch); //Load our map and setup our map renderer maploader = new TmxMapLoader(); map = maploader.load("level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / MarioBros.PPM); //initially set our gamcam to be centered correctly at the start of of map gamecam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0); //create our Box2D world, setting no gravity in X, -10 gravity in Y, and allow bodies to sleep world = new World(new Vector2(0, -10), true); //allows for debug lines of our box2d world. b2dr = new Box2DDebugRenderer(); creator = new B2WorldCreator(this); //create mario in our game world player = new Mario(this); world.setContactListener(new WorldContactListener()); music = MarioBros.manager.get("audio/music/mario_music.ogg", Music.class); music.setLooping(true); music.setVolume(0.3f); //music.play(); items = new Array<Item>(); itemsToSpawn = new LinkedBlockingQueue<ItemDef>(); }
world.setContactListener(new ContactListener() { public void beginContact(Contact c) { Body b = c.getFixtureA().getBody();
@Override public void create () { super.create(); viewport = new FitViewport(SCENE_WIDTH, SCENE_HEIGHT); // Center camera to get (0,0) as the origin of the Box2D world viewport.getCamera().position.set(viewport.getCamera().position.x + SCENE_WIDTH*0.5f, viewport.getCamera().position.y + SCENE_HEIGHT*0.5f , 0); viewport.getCamera().update(); point = new Vector3(); batch = new SpriteBatch(); Gdx.input.setInputProcessor(this); // Create Physics World world = new World(new Vector2(0,-9.8f), true); // Creates a ground to avoid objects falling forever createGround(); pointerBody = createSharpObject(); // Set physics properties for the balloon balloonFD = new FixtureDef(); balloonFD.density = balloonDensity; balloonFD.friction = balloonFriction; balloonFD.restitution = balloonRestitution; // Box2DCollisionReaction will be able to listen for contacts between fixtures world.setContactListener(this); debugRenderer = new Box2DDebugRenderer(); }
@Override public void create () { super.create(); viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT); // Center camera to get (0,0) as the origin of the Box2D world viewport.getCamera().position.set(viewport.getCamera().position.x + WORLD_WIDTH*0.5f, viewport.getCamera().position.y + WORLD_HEIGHT*0.5f , 0); viewport.getCamera().update(); batch = new SpriteBatch(); Gdx.input.setInputProcessor(this); // Create Physics World world = new World(new Vector2(0,-10), true); // Instantiate DebugRenderer for rendering shapes debugRenderer = new Box2DDebugRenderer(); // Creates a ground to avoid objects falling forever createGround(); dinoTex = new Texture(Gdx.files.internal("data/blur/dinosaur.png")); playerTex = new Texture(Gdx.files.internal("data/caveman.png")); dinosaur1 = new Enemy(dinoTex, 7f,2f); dinosaur2 = new Enemy(dinoTex, 9f,2f); player1 = new Player(playerTex, 3f, 2f); player2 = new Player(playerTex, 5f, 2f); world.setContactListener(this); }
box2dWorld.setContactListener(new GameWorldContactListener());
b2dWorld.setContactListener(new B2DWorldContactListener()); b2dRenderer = new Box2DDebugRenderer();