def create(self): w = Gdx.graphics.getWidth() h = Gdx.graphics.getHeight() self.camera = OrthographicCamera() self.camera.setToOrtho(False, (w / h) * 320, 320) self.camera.update() self.cameraController = OrthoCamController(self.camera) Gdx.input.setInputProcessor(self.cameraController) self.font = BitmapFont() self.batch = SpriteBatch() self.tiles = Texture( Gdx.files.internal('../../data/maps/tiled/tiles.png')) splitTiles = TextureRegion.split(self.tiles, 32, 32) self.map = TiledMap() layers = self.map.getLayers() for l in range(20): layer = TiledMapTileLayer(150, 100, 32, 32) for x in range(150): for y in range(100): ty = int(Math.random() * len(splitTiles)) tx = int(Math.random() * len(splitTiles[ty])) cell = Cell() cell.setTile(StaticTiledMapTile(splitTiles[ty][tx])) layer.setCell(x, y, cell) layers.add(layer) self.renderer = OrthogonalTiledMapRenderer(self.map)
def create(self): ''' setup the camera. In Box2D we operate on a meter scale, pixels won't do it. So we use an orthographic camera with a viewport of 48 meters in width and 32 meters in height. we also position the camera so that it looks at (0, 16) (that's where the middle of the screen will be located). ''' self.camera = OrthographicCamera(48, 32) self.camera.position.set(0, 15, 0) # create the debug renderer self.renderer = Box2DDebugRenderer() # create the world self.world = World(Vector2(0, -10), True) # we also need an invisible zero size ground body # to which we can connect the mouse joint bodyDef = BodyDef() self.groundBody = self.world.createBody(bodyDef) # call abstract method to populate the world self.createWorld(self.world) self.batch = SpriteBatch() self.font = BitmapFont(Gdx.files.internal('../data/arial-15.fnt'), False) Gdx.input.setInputProcessor(self)