public void onEnter() { super.onEnter(); float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(); camera.setToOrtho(false, (w / h) * 640, 640); camera.update(); map = new TmxMapLoader().load("Resource/tiles.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 2f);//1f / 32f); func = CC.Scheduler().renderAfterSchedulePerFrame((t)->{ camera.position.set(500, 320, 0); camera.update(); renderer.setView( camera.combined, 0, 0, 1000, 500); renderer.render(); return false; }, 0, false); }
/** * Lädt die Map aus der Datei in den Speicher. * * Wird von {@link #initMap()} aufgerufen. */ private void loadMap() { FileHandle mapFile = Gdx.files.internal("data/maps/" + mapName + ".tmx"); if (!mapFile.exists() || mapFile.isDirectory()) { Gdx.app.error("ERROR", "The map file " + mapName + ".tmx doesn't exists!"); levelManager.exitToMenu(); return; } TmxMapLoader.Parameters mapLoaderParameters = new TmxMapLoader.Parameters(); mapLoaderParameters.textureMagFilter = Texture.TextureFilter.Nearest; mapLoaderParameters.textureMinFilter = Texture.TextureFilter.Nearest; tileMap = new TmxMapLoader().load(mapFile.path(), mapLoaderParameters); }
public static void init() { assetManager.setLoader(TiledMap.class, new TmxMapLoader()); for (Assets.Fonts font : Assets.Fonts.values()) { assetManager.load(font.getPath(), BitmapFont.class); } for (Assets.Textures texture : Assets.Textures.values()) { assetManager.load(texture.getPath(), Texture.class); } for (Assets.Maps map : Assets.Maps.values()) { assetManager.load(map.getPath(), TiledMap.class); } for (Assets.Musics music : Assets.Musics.values()) { assetManager.load(music.getPath(), Music.class); } for (Assets.Sounds sound : Assets.Sounds.values()) { assetManager.load(sound.getPath(), Sound.class); } assetManager.finishLoading(); }
public MapLoader(OrthographicCamera camera, SendCommand sendCommand) { this.camera = camera; this.tiledMap = new TmxMapLoader().load(Constants.TESTMAPPATH); this.tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap); this.blockLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Blocks"); this.floorLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Floor"); this.bombLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Bombs"); this.itemLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Items"); this.sendCommand = sendCommand; Constants.MAPTEXTUREWIDTH = blockLayer.getTileWidth(); Constants.MAPTEXTUREHEIGHT = blockLayer.getTileWidth(); findAllItemFields(); }
/**-------------------Getter & Setter-------------------**/ public void setNewMap(String path) { this.tiledMap = new TmxMapLoader().load(path); this.tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap); this.blockLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Blocks"); this.floorLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Floor"); this.bombLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Bombs"); this.itemLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Items"); Constants.MAPTEXTUREWIDTH = blockLayer.getTileWidth(); Constants.MAPTEXTUREHEIGHT = blockLayer.getTileWidth(); findAllItemFields(); }
public TiledMapLevelLoadable(int levelId) { this.id = levelId; respawnPosition = new Vector2(); freeBodyDefinitions = new Array<FixtureBodyDefinition>(); entityDefinitions = new Array<EntityDefinition>(); scriptDefinitions = new Array<ScriptDefinition>(); canvasMap = new LinkedHashMap<IRender, Integer>(); bodySkeletonMap = new HashMap<String, MapObject>(); String tileMapName = Globals.getLevelTileMapName(levelId); filename = AssetManager.getFilePath("levels", tileMapName + ".tmx"); TmxMapLoader.Parameters params = new TmxMapLoader.Parameters(); params.flipY = false; tiledMap = new TmxMapLoader().load(filename, params); background = new ParallaxBackground(); setBackground(); processLayers(); }
public TmxMap(String levelName) { map = new TmxMapLoader().load(levelName); tileLayer = (TiledMapTileLayer) map.getLayers().get(0); objectsLayer = map.getLayers().get(1); MapProperties properties = tileLayer.getProperties(); worldType = WorldTypeEnum.valueOf(((String)properties.get(TilemapPropertiesConstants.WORLD)).toUpperCase()); musicTheme = ((String)properties.get("music")).toUpperCase(); String sScrollableTo = (String)properties.get("scrollableTo"); scrollMaxValue = sScrollableTo!=null && !sScrollableTo.equals("") ? Float.parseFloat(sScrollableTo) : 1000; String sCastle = (String)properties.get("castle"); endLevelCastleType = worldType !=WorldTypeEnum.CASTLE ? sCastle!=null && !sCastle.equals("") ? CastleTypeEnum.valueOf(sCastle.toUpperCase()) : CastleTypeEnum.SMALL : null; initBlocks(worldType); initMapObjects(); initBackgrounds(properties); }
public CoffeeLevel(String mapPath) { this.map = new TmxMapLoader().load(mapPath); //configuration des variables de tailles this.tileWidth = ((Integer) this.map.getProperties().get("tilewidth")); this.tileHeight = ((Integer) this.map.getProperties().get("tileheight")); mapWidthTiled = (Integer) this.map.getProperties().get("width"); mapHeightTiled = (Integer) this.map.getProperties().get("height"); this.mapWidthPixel = mapWidthTiled * tileWidth; this.mapHeightPixel = mapHeightTiled * tileHeight; vannes = new HashSet<Vanne>(); indicateurs = new HashSet<KoffeeMeter>(); this.canalisation = new Canalisation(map,mapWidthTiled,mapHeightTiled); }
public void loadTiledMap(String mapName){ logger.debug("Loading TiledMap: " + mapName); this.clear(); try{ map = new TmxMapLoader().load(mapName); } catch(Exception e){ logger.error("Map load failed .. " + e.getMessage()); return; } mapRenderer = new OrthogonalTiledMapRenderer(map,batch); createPhysics(map); createEntities(map); createSpawnZones(map); createDropOffPoints(map); }
/** * */ public GameScreen(SupaBox game) { this.game = game; //float aspectRatio = (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth(); camera = new OrthographicCamera(); viewport = new FitViewport(24, 16, camera); viewport.apply(); camera.position.set(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2, 0); debugRenderer = new Box2DDebugRenderer(); world = new World(new Vector2(0, -9.8f), true); mapLoader = new TmxMapLoader(); map = mapLoader.load("crate.tmx"); mapRenderer = new OrthogonalTiledMapRenderer(map, 1f / SupaBox.PPM); bodyBuilder = new BodyBuilder(); bodyBuilder.createBodies(entities, world, map); }
@Override public void create () { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(); camera.setToOrtho(false, (w / h) * 10, 10); camera.update(); cameraController = new OrthoCamController(camera); Gdx.input.setInputProcessor(cameraController); font = new BitmapFont(); batch = new SpriteBatch(); map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f); }
@Override public void create () { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(); camera.setToOrtho(false, (w / h) * 10, 10); camera.zoom = 2; camera.update(); cameraController = new OrthoCamController(camera); Gdx.input.setInputProcessor(cameraController); font = new BitmapFont(); batch = new SpriteBatch(); assetManager = new AssetManager(); assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); assetManager.load("data/maps/tiled/isometric_grass_and_water.tmx", TiledMap.class); assetManager.finishLoading(); map = assetManager.get("data/maps/tiled/isometric_grass_and_water.tmx"); renderer = new IsometricTiledMapRenderer(map, 1f / 64f); }
public static void loadMap(String fileName) { TiledMap map = new TmxMapLoader().load(fileName); for (int i = 0; i < map.getLayers().getCount(); i++) { TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers() .get(i); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { Cell cell = layer.getCell(x, layer.getHeight() - 1 - y); if (cell == null) { continue; } Entity e = EntityManager.createTile((String) cell.getTile() .getProperties().get("name"), x * 16, y * 16); EntityManager.setEntityLayer(e, Name.LAYER_FLOOR); } } } }
public SpriteManager(Robin2DX game) { this.game = game; // Inicia la cámara para jugar camera = new OrthographicCamera(); // La cámara mostrará 30 celdas de ancho por 30 celdas de alto camera.setToOrtho(false, 30, 30); camera.zoom = 1 / 2f; camera.update(); // Carga el mapa y obtiene la capa de colisión (objetos con los que el personaje puede chocar) map = new TmxMapLoader().load("levels/tiledmap1.tmx"); collisionLayer = (TiledMapTileLayer) map.getLayers().get("base"); // Crea el renderizador del tiledmap mapRenderer = new OrthogonalTiledMapRenderer(map); // Hay que utilizar el spritebatch del mapa para pintar el nivel. // En caso contrario no ubica ni escala bien al personaje en el mapa batch = mapRenderer.getSpriteBatch(); // Posiciona al jugador en el mapa player = new Player(15 * Constants.TILE_WIDTH, 10 * Constants.TILE_HEIGHT); }
private static boolean loadNonBlocking(){ if(!readinglock){ clear(); loadAssets(); readinglock = true; } // once update returns true then condition is satisfied and the lock stops update call if(!updatinglock) if(assetMan.update()){ assetMan.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); getAssets(); updatinglock = true; if(Scene.splashDuration != 0) Scene.nextSceneWithDelay(Scene.splashDuration); else Scene.nextScene(); } return updatinglock; }
public TestMap(Box2DWorld box2dworld, EffectsInterface effectManager) { super(box2dworld, effectManager); // Load map file with tileset tileMap = new TmxMapLoader().load("testmap.tmx"); // Create Polygon objects from "collision" object layer MapProcessor.createGroundObjects(this, tileMap.getLayers().get("collision"), box2dworld); // Create coins from "coins" object layer MapProcessor.createCoins(this, tileMap.getLayers().get("coins"), box2dworld); // Set player position according to position of Ellipse object added to collision layer player.transform(MapProcessor.getPlayerPosition(this, tileMap.getLayers().get("collision"))); tileWidth = (Integer)tileMap.getProperties().get("tilewidth"); tileHeight = (Integer)tileMap.getProperties().get("tileheight"); width = (Integer)tileMap.getProperties().get("width"); height = (Integer)tileMap.getProperties().get("height"); }
public TestMap(MapDescriptor mapDesc, Box2DWorld box2dworld, EffectsInterface effectManager) { super(box2dworld, effectManager); // Load map file with tileset tileMap = new TmxMapLoader().load("testmap.tmx"); // Create Polygon objects from "collision" object layer MapProcessor.createGroundObjects(this, tileMap.getLayers().get("collision"), box2dworld); // Create coins MapProcessor.createCoinsFromMapDesc(this, mapDesc, box2dworld); // Set player position player.transform(mapDesc.getPlayerPos()); // Set gameTime gameTime = mapDesc.getGameTime(); tileWidth = (Integer)tileMap.getProperties().get("tilewidth"); tileHeight = (Integer)tileMap.getProperties().get("tileheight"); width = (Integer)tileMap.getProperties().get("width"); height = (Integer)tileMap.getProperties().get("height"); }
public Level() { super("Game"); cam = new OrthographicCamera(); // Setup camera viewport cam.setToOrtho(false, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); cam.update(); batch = new SpriteBatch(); // Load map map = new TmxMapLoader().load("maps/Lvl1.tmx"); mapRenderer = new OrthogonalTiledMapRenderer(map); // Load walls as rectangles in an array MapObjects wallobjects = map.getLayers().get("Walls").getObjects(); for(int i = 0; i < wallobjects.getCount(); i++) { RectangleMapObject obj = (RectangleMapObject) wallobjects.get(i); Rectangle rect = obj.getRectangle(); walls.add(new Rectangle(rect.x, rect.y, 16, 16)); } Texture[] tex = new Texture[]{new Texture("sprites/Player_Side_Left.png"),new Texture("sprites/Player_Side_Right.png"), new Texture("sprites/Player_Behind_1.png"), new Texture("sprites/Player_Behind_2.png"),new Texture("sprites/Player_Forward1.png"),new Texture("sprites/Player.png")}; player = new Player("sprites/Player.png", 120, 120, walls, tex); wall = new Texture("tiles/Wall.png"); }
private void loadAssetsGame() { Gdx.app.log(Constants.LOG, "Load ResourcesManager Game"); this.load(DEFAULT_FONT, BitmapFont.class); this.load(DEBUG_FONT, BitmapFont.class); this.load(HEADER_FONT, BitmapFont.class); this.load(DEBUG_BACKGROUND, Texture.class); this.load(MENU_BACKGROUND, Texture.class); this.load(STATS_BACKGROUND, Texture.class); this.load(SPRITE_ATLAS, TextureAtlas.class); this.load(VARIOS_ATLAS, TextureAtlas.class); this.load(OBJECTS_ATLAS, TextureAtlas.class); this.load(GUI_ATLAS, TextureAtlas.class); this.load(GUI_PACK_ATLAS, TextureAtlas.class); this.load(UISKIN_ATLAS, TextureAtlas.class); this.load(PARTICLE_EFFECT, ParticleEffect.class); this.load(PARTICLE_EFFECT_CONTACT, ParticleEffect.class); this.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); this.load(MUSIC_MENU,Music.class); }
/** initializes a TMX Tiled Map with a TMX file */ public boolean initWithTMXFile(String tmxFile) { if(_tileMap != null) { _tileMap.dispose(); } TmxMapLoader newLoader = new TmxMapLoader() { public FileHandle resolve(String fileName) { return CC.File(fileName); } }; _tileMap = newLoader.load(tmxFile); _initProperties(); _tileMapRender = new OrthogonalTiledMapRenderer(_tileMap, 1f); return true; }
public boolean initWithTMXFile(FileHandle tmxFile) { if(_tileMap != null) { _tileMap.dispose(); } TmxMapLoader newLoader = new TmxMapLoader() { public FileHandle resolve(String fileName) { return tmxFile; } }; _tileMap = newLoader.load(null); return true; }
public GameTester(String map_name) { TiledMap testmap = new TmxMapLoader().load(map_name); model = new GameModel(testmap); //For positions and other stuff initialization noMotionDuringTime(0); }
public PlayScreen(NoObjectionGame game) { atlas = new TextureAtlas("dudestuff3.pack"); this.game = game; bg = new Texture("main_background.png"); gameCam = new OrthographicCamera(); gamePort = new FitViewport(NoObjectionGame.V_WIDTH / NoObjectionGame.PPM, NoObjectionGame.V_HEIGHT / NoObjectionGame.PPM, gameCam); hud = new Hud(game.batch); maploader = new TmxMapLoader(); map = maploader.load("map1.tmx"); renderer = new OrthoCachedTiledMapRenderer(map, 1 / NoObjectionGame.PPM); gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0); world = new World(new Vector2(0, -10), true); b2dr = new Box2DDebugRenderer(); new B2WorldCreator(world, map); hero = new Hero(world, this); controller = new Controller(); worldContactListener = new WorldContactListener(); world.setContactListener(worldContactListener); //timer sb = new SpriteBatch(); viewport = new FitViewport(NoObjectionGame.V_WIDTH, NoObjectionGame.V_HEIGHT, new OrthographicCamera()); stage = new Stage(viewport, sb); table = new Table(); table.top(); table.setFillParent(true); countDownLabel = new Label(Float.toString(playTime), new Label.LabelStyle(new BitmapFont(), Color.WHITE)); table.add(countDownLabel).expandX(); stage.addActor(table); }
public void init() { // Load TMX Map spawnPoints = new Array<Vector2>(); tiledMap = new TmxMapLoader().load(mapName); spawnLayer = tiledMap.getLayers().get("BasicAlienSpawn"); loadSpawnLocations(spawnLayer); }
MapMode(final MapDefinition initialMap, final TileCoordinate initialLocation, final AssetManager assetManager) { this.initialMap = initialMap; this.initialLocation = initialLocation; this.assetManager = assetManager; assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); this.heroSpriteSet = GameState.getParty().getLeader().getSpriteSetDefinition(); stateMachine = initStateMachine(); }
public PlayScreen(QuackHack game) { this.game = game; gamecam = new OrthographicCamera(); gamePort = new ExtendViewport(QuackHack.V_WIDTH * 4 / QuackHack.PPM, QuackHack.V_HEIGHT * 4 / QuackHack.PPM, gamecam); hud = new Hud(game); maploader = new TmxMapLoader(); map = maploader.load("Tunnelv0.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / QuackHack.PPM); gameMusic = Gdx.audio.newMusic(Gdx.files.internal("Airborn.wav")); gameMusic.setLooping(true); gameMusic.play(); gamecam.position.set(gamePort.getMinWorldWidth() / 2, gamePort.getMinWorldHeight() / 2, 0); world = new World(new Vector2(0, -100), true); //b2dr = new Box2DDebugRenderer(); new B2WorldCreator(world, map, this); world.setContactListener(new WorldContactListener()); game.getServer().registerNetListener(this); rayHandler = rayHandlerGenerator(); for(Connection c: game.getServer().getPlayers()) { System.out.println("New Player! id: "+game.getServer().getPlayerType(c.getID()).toString()); players.put(c.getID(), new Player(c.getID(), world, this, game.getServer().getPlayerType(c.getID()))); } game.getServer().sendCommand(NetCommand.PLAYER_JOIN); //http://www.badlogicgames.com/forum/viewtopic.php?f=17&t=1795 rbg = new ParallaxBackground(new ParallaxLayer[]{ new ParallaxLayer(new TextureRegion(new Texture(Gdx.files.internal("blue_grass.png"))),new Vector2(0.5f, 0.5f),new Vector2(0, 300)), //new ParallaxLayer(atlas.findRegion("bg2"),new Vector2(1.0f,1.0f),new Vector2(0, 500)), }, 800, 480,new Vector2(150,0)); }
private static void loadInternal() { if (Gdx.files == null) throw new RuntimeException("LibGDX is not initialized yet!"); instance = new AssetManager(); // TODO make FileHandleResolver injectible instance.setLoader(TiledMap.class, new TmxMapLoader()); instance.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(new InternalFileHandleResolver())); }
private void loadMap(Camera camera, String mapName) { map = new TmxMapLoader().load(mapName); renderer = new OrthogonalTiledMapRenderer(map, 1 / Constants.BLOCK_SIZE); renderer.setView((OrthographicCamera) camera); mapLayers = map.getLayers(); }
public void restart() { /** * TEST */ GameAssetManager.instance().loadAnimations("imgs/sprites/animations.json"); GameAssetManager.instance().loadSprites("imgs/sprites/sprites.json"); GameAssetManager.instance().loadSounds("sounds/sounds.json"); this.am = new AssetManager(); this.am.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); this.am.load(getLevel(0).getLevel(), TiledMap.class); this.am.finishLoading(); float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); this.camera = new OrthographicCamera(); this.camera.setToOrtho(false, w, h); this.camera.update(); getLevel(0).restart(); /*world = new World(); world.setSystem(new SpriteSimulate(GameSettings.tickDelayGame)); world.setSystem(new WorldSys(GameSettings.tickDelayGame)); world.setSystem(new MapRender()); world.setSystem(new SpriteRender()); world.setSystem(new GameInput(GameSettings.tickDelayGame));*/ setScreen(new ScreenActiveGame()); Gdx.input.setInputProcessor(inputHandler); }
public static void resetMaps(){ Level1 = new TmxMapLoader().load("MapsObjects/Path1Level1.tmx"); Level2 = new TmxMapLoader().load("MapsObjects/Path1Level2.tmx"); Level3 = new TmxMapLoader().load("MapsObjects/Path1Level3.tmx"); Level4 = new TmxMapLoader().load("MapsObjects/Path1Level4.tmx"); Level5 = new TmxMapLoader().load("MapsObjects/Path1Level5.tmx"); }
public Scene(String ID){ ID = ID.replaceAll(" ", ""); this.ID=ID; tileMap = new TmxMapLoader().load("assets/maps/" + ID + ".tmx"); MapProperties prop = tileMap.getProperties(); width = prop.get("width", Integer.class)*Vars.TILE_SIZE; height = prop.get("height", Integer.class)*Vars.TILE_SIZE; title = prop.get("name", String.class); if(title==null) title = ID; //determine if scen is outside String light,s; if((light = prop.get("ambient", String.class))!=null){ if(light.toLowerCase().trim().equals("daynight")){ outside = true; if((s = prop.get("outside", String.class))!=null){ if(Vars.isBoolean(s)) outside = Boolean.parseBoolean(s); } } else { outside = false; if((s = prop.get("outside", String.class))!=null){ if(Vars.isBoolean(s)) outside = Boolean.parseBoolean(s); } } } else outside = false; }
public Terrain() { int height, width; // Récupération d'une map this.map = new TmxMapLoader().load("arrivee_remarquable/map.tmx"); this.renderer = new OrthogonalTiledMapRenderer(map); // Récupération de ses dimensions width = Integer.valueOf((String)map.getProperties().get("width")); height = Integer.valueOf((String)map.getProperties().get("height")); this.cases = new Case[width][height]; // Récupération des layers nécessaires TiledMapTileLayer obstaclesLayer = (TiledMapTileLayer)map.getLayers().get("obstacles"); // Création des cases for (int i=0; i < width; i++) { for (int j=0; j < height; j++) { cases[i][j] = new Case(i, j, obstaclesLayer.getCell(i,j) != null); } } // Récupération des points de départ et d'arrivée String[] mapDepart = ((String)map.getProperties().get("start")).split(","); String[] mapFin = ((String)map.getProperties().get("end")).split(","); this.depart = cases[Integer.valueOf(mapDepart[0])][Integer.valueOf(mapDepart[1])]; this.fin = cases[Integer.valueOf(mapFin[0])][Integer.valueOf(mapFin[1])]; }
public PlayScreen(MarioBros game) { this.game = game; gameCam = new OrthographicCamera(); gamePort = new FitViewport(MarioBros.V_WIDTH / MarioBros.PPM, MarioBros.V_HEIGHT / MarioBros.PPM, gameCam); hud = new Hud(game.batch); mapLoader = new TmxMapLoader(); map = mapLoader.load("level1.tmx"); atlas = new TextureAtlas("Mario_and_Enemies.pack"); renderer = new OrthogonalTiledMapRenderer(map, 1 / MarioBros.PPM); //set gamecam to the center at the start of the game gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0); world = new World(new Vector2(0, -10), true); b2dr = new Box2DDebugRenderer(); creator = new B2WorldCreator(this); player = new Mario(this); world.setContactListener(new WorldContactListener()); music = MarioBros.manager.get("audio/music/mario_music.ogg", Music.class); music.setLooping(true); music.play(); items = new Array<Item>(); itemsToSpawn = new LinkedBlockingQueue<ItemDef>(); }
public void loadLevel(String level, boolean isServer, String name) { this.isServer = isServer; map = new TmxMapLoader().load(level); TiledMapTileLayer layer = (TiledMapTileLayer) map. getLayers().get("terrain"); VIEWPORT_WIDTH = (int) (layer.getTileWidth() * layer.getWidth()); VIEWPORT_HEIGHT = (int) (layer.getTileHeight() * layer.getHeight()); viewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, camera); renderer = new OrthogonalTiledMapRenderer(map); name = name.trim(); if (name.length() == 0) name = "noname"; if (name.length() >= 10){ name = name.substring(0, 10); } ClientDetailsMessage clientDetails = new ClientDetailsMessage(); clientDetails.name = name; clientDetails.protocolVersion = Constants.PROTOCOL_VERSION; if (isServer) { MapLayer collision = map. getLayers().get("collision"); for(MapObject object: collision.getObjects()) { worldManager.createWorldObject(object); } worldManager.addIncomingEvent(MessageObjectPool.instance. eventPool.obtain().set(State.RECEIVED, clientDetails)); } else { client.sendTCP(clientDetails); } controls = new onScreenControls(); }
public Assets(String assetFile) { logger = new Logger(TAG, Env.debugLevel); logger.info("initialising"); manager = new AssetManager(); // manager.setErrorListener(this); manager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver())); manager.setLoader(PhysicsData.class, new PhysicsLoader(new InternalFileHandleResolver())); manager.setLoader(SpriteAnimationData.class, new SpriteAnimationLoader(new InternalFileHandleResolver())); manager.setLoader(SkeletonData.class, new SkeletonDataLoader(new InternalFileHandleResolver())); manager.setLoader(AnimationStateData.class, new AnimationStateDataLoader(new InternalFileHandleResolver())); loadGroups(assetFile); }
public RTSAbstractMap(RTSGame game, String tiledMapPath, boolean useFogOfWar) { super(); this.game = game; // Lets initialize the tiled map tiledMap = new TmxMapLoader().load(tiledMapPath); MapLayers mapLayers = tiledMap.getLayers(); baseLayer = (TiledMapTileLayer) mapLayers.get(BASE_LAYER_NAME); baseLayerOverlay = (TiledMapTileLayer) mapLayers.get(BASE_LAYER_OVERLAY_NAME); MapLayer objectsLayer = mapLayers.get(OBJECTS_LAYER_NAME); if (objectsLayer != null) mapObjects = objectsLayer.getObjects(); mapBatch = new SpriteBatch(100, RTSGame.game.mapShader); // Initialize map renderer mapRenderer = new OrthogonalTiledMapRenderer(tiledMap, mapBatch); initializeMapGenAndRenderer(); // And now let's initialize the quadtree map = mapGen.generateMap(tiledMap); astar = new AStar<IBoundsObject>(map); // Number of tiles that fit in the canvas, to render. renderTileWidth = Gdx.graphics.getWidth() / (int) baseLayer.getTileWidth(); renderTileHeight = Gdx.graphics.getHeight() / (int) baseLayer.getTileHeight(); // Fog of war this.useFogOfWar = useFogOfWar; if (useFogOfWar) { fogOfWar = new FogOfWar((int) (baseLayer.getWidth()), (int) (baseLayer.getHeight()), (int) baseLayer.getTileWidth()); } }
@Override public void create () { // load the koala frames, split them, and assign them to Animations koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png"); TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0]; stand = new Animation(0, regions[0]); jump = new Animation(0, regions[1]); walk = new Animation(0.15f, regions[2], regions[3], regions[4]); walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG); // figure out the width and height of the koala for collision // detection and rendering by converting a koala frames pixel // size into world units (1 unit == 16 pixels) Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth(); Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight(); // load the map, set the unit scale to 1/16 (1 unit == 16 pixels) map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f); // create an orthographic camera, shows us 30x20 units of the world camera = new OrthographicCamera(); camera.setToOrtho(false, 30, 20); camera.update(); // create the Koala we want to move around the world koala = new Koala(); koala.position.set(20, 20); }
/** * <p> * Loads all of the levels in the given list. They must exist. * <p> * <strong>Warning:</strong Calling this function while levels are loaded * will delete all loaded levels. * </p> * * @param prefix * The prefix to prepend to all level paths in nameList. Can be null. * @param nameList * A list of paths to levels. */ protected void loadLevelsFromList(String prefix, String[] nameList) { if (nameList == null) { throw new IllegalArgumentException("Trying to load levels from null list."); } else if (levels != null) { dispose(); } TmxMapLoader loader = new TmxMapLoader(); levels = new ArrayList<String>(nameList.length); levelSpawns = new HashMap<String, Vector2>(nameList.length); collisionMaps = new HashMap<String, TerrainCollisionMap>(nameList.length); for (String s : nameList) { if (prefix != null) { s = prefix + s; } FileHandle handle = Gdx.files.internal(s); if (!handle.exists()) { Gdx.app.debug("LOAD_LEVELS", "Level does not exist: " + s + " when loading from list. Skipping."); continue; } else { loadLevel(loader, handle); } } }
/** * Carga el mapa de la pantalla actual */ public static void loadMap() { LevelManager.map = new TmxMapLoader().load(LevelManager.getCurrentLevelPath()); TiledMapManager.collisionLayer = (TiledMapTileLayer) LevelManager.map.getLayers().get("terrain"); TiledMapManager.objectLayer = (MapLayer) LevelManager.map.getLayers().get("objects"); loadAnimateTiles(); loadEnemies(); loadPlatforms(); }
@Override public void show() { // Carga toda la pantalla desde cero if (empiezaPartida) { // Evita que nos fuerce a que el fichero de tiles sea potencia de 2 Texture.setEnforcePotImages(false); // Crea el mapa y el renderizador map = new TmxMapLoader().load("levels/level1.tmx"); mapRenderer = new OrthogonalTiledMapRenderer(map); // Crea una cámara y muestra 30x20 unidades del mundo camera = new OrthographicCamera(); camera.setToOrtho(false, 30, 20); camera.update(); // Obtiene la referencia a la capa de terreno del mapa TiledMapTileLayer collisionLayer = (TiledMapTileLayer) map.getLayers().get(0); // Crea el jugador y lo posiciona al inicio de la pantalla player = new Player(collisionLayer, game); // posición inicial del jugador player.position.set(0 * map.getProperties().get("tilewidth", Integer.class), 2 * map.getProperties().get("tileheight", Integer.class) + 32); // Coloca tiles animados TiledMapManager.animateTiles(map, collisionLayer, "coin", 4); TiledMapManager.animateTiles(map, collisionLayer, "plant", 3); TiledMapManager.animateTiles(map, collisionLayer, "box", 4); // Música durante la partida game.levelSound.loop(); empiezaPartida = false; } }