List of usage examples for com.badlogic.gdx Gdx files
Files files
To view the source code for com.badlogic.gdx Gdx files.
Click Source Link
From source file:com.canyinghao.canopengl.demo.SpineBoy.java
License:Open Source License
public void create() { camera = new OrthographicCamera(); batch = new SpriteBatch(); renderer = new SkeletonRenderer(); renderer.setPremultipliedAlpha(true); // PMA results in correct blending without outlines. debugRenderer = new SkeletonRendererDebug(); debugRenderer.setBoundingBoxes(false); debugRenderer.setRegionAttachments(false); atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas")); json = new SkeletonJson(atlas); // This loads skeleton JSON data, which is stateless. json.setScale(0.3f); // Load the skeleton at 60% the size it was in Spine. SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json")); skeleton = new Skeleton(skeletonData); // Skeleton holds skeleton state (bone positions, slot attachments, etc). skeleton.setPosition(100, 20);/*from w w w . j ava 2 s .c o m*/ AnimationStateData stateData = new AnimationStateData(skeletonData); // Defines mixing (crossfading) between animations. stateData.setMix("run", "jump", 0.2f); stateData.setMix("jump", "run", 0.2f); state = new AnimationState(stateData); // Holds the animation state for a skeleton (current animation, time, etc). state.setTimeScale(0.5f); // Slow all animations down to 50% speed. // Queue animations on track 0. state.setAnimation(0, "run", true); state.addAnimation(0, "run", true, 0); // Run after the jump. }
From source file:com.car.utils.TiledMapHelper.java
License:Apache License
public TiledMapHelper(String tmxFile, String packDirectory) { racePositions = new HashMap<Integer, CarPosition>(); packFileDirectory = Gdx.files.internal(packDirectory); map = TiledLoader.createMap(Gdx.files.internal(tmxFile)); tileAtlas = new TileAtlas(map, packFileDirectory); loadMapProperties();/*from w w w . j a va2 s. c o m*/ parseMapObjects(); }
From source file:com.cmein.tilemap.utils.TiledMapPacker.java
License:Apache License
/** * Packs a Tiled Map, adding some properties to improve the speed of the {@link TiledMapRenderer}. Also runs the texture packer * on the tiles for use with a {@link TileAtlas} * @param tmxFile the map's tmx file/*from w ww . j a va 2 s . co m*/ * @param imageDir the directory containing tile set images * @param outputDir the directory to output a fully processed map to * @param settings the settings used in the TexturePacker * */ public void processMap(File tmxFile, File imageDir, File outputDir, Settings settings) throws IOException { this.outputDir = outputDir; tmxFileHandle = Gdx.files.absolute(tmxFile.getAbsolutePath()); imageDirHandle = Gdx.files.absolute(imageDir.getAbsolutePath()); new File(outputDir, tmxFileHandle.name()).delete(); if (outputDir.exists()) { String prefix = tmxFileHandle.nameWithoutExtension(); for (File file : outputDir.listFiles()) if (file.getName().startsWith(prefix)) file.delete(); } map = TiledLoader.createMap(tmxFileHandle); packMap(map, settings); }
From source file:com.codefiddler.libgdx.spinit.assets.SoundEffects.java
License:Apache License
public SoundEffects() { c = Gdx.audio.newSound(Gdx.files.internal("data/sounds/c.mp3")); cS = Gdx.audio.newSound(Gdx.files.internal("data/sounds/cS.mp3")); d = Gdx.audio.newSound(Gdx.files.internal("data/sounds/d.mp3")); buzzer = Gdx.audio.newSound(Gdx.files.internal("data/sounds/buzzer.mp3")); intro = Gdx.audio.newSound(Gdx.files.internal("data/sounds/intro.mp3")); winner = Gdx.audio.newSound(Gdx.files.internal("data/sounds/winner.mp3")); endWinnerSound = Gdx.audio.newSound(Gdx.files.internal("data/sounds/endWinner.mp3")); effects = new ArrayList<Sound>(); for (int i = 1; i <= 16; i++) { effects.add(Gdx.audio.newSound(Gdx.files.internal("data/sounds/effects/" + i + ".mp3"))); }/* w w w . j ava 2 s .c om*/ }
From source file:com.cometmebro.game.PlanetMenu.java
@Override public void show() { skin.addRegions(atlas2);// w w w . j a v a2 s . c o m blank = " "; one = "o "; two = "oo "; three = "ooo"; currentDangerCount = 1; currentDurationCount = 1; currentResourcesCount = 1; currentDanger = blank; currentDuration = blank; currentResources = blank; sandPlanet = "Sand Planet"; springPlanet = "Spring Planet"; simplePlanet = "Grass Planet"; holidayPlanet = "Winter Wonderland"; waterPlanet = "Ocean Planet"; icePlanet = "Ice Planet"; lavaPlanet = "Lava Planet"; candyPlanet = "Candy Planet"; cityPlanet = "Suburban Planet"; backButtonTex = new Texture(Gdx.files.internal("backbutton.png")); Button backButton = new Button(new SpriteDrawable(new Sprite(backButtonTex))); backButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { stage.addAction( Actions.sequence(Actions.fadeOut(.25f), Actions.delay(.25f), Actions.run(new Runnable() { @Override public void run() { MainMenu menu = new MainMenu(cmb); cmb.setScreen(menu); } }))); } }); settings = new Texture(Gdx.files.internal("settingsbutton.png")); Button settingsButton = new Button(new SpriteDrawable(new Sprite(settings))); planetHudTex = new Texture(Gdx.files.internal("planethud.png")); SpriteDrawable planethud = new SpriteDrawable(new Sprite(planetHudTex)); settingsButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { stage.addAction( Actions.sequence(Actions.fadeOut(.25f), Actions.delay(.25f), Actions.run(new Runnable() { @Override public void run() { SettingsMenu menu = new SettingsMenu(cmb); cmb.setScreen(menu); } }))); } }); buttonUp = new Texture(Gdx.files.internal("roundplaybuttonalt.png")); buttonDown = new Texture(Gdx.files.internal("roundplaybuttonaltdown.png")); Button.ButtonStyle buttonStyle2 = new Button.ButtonStyle(); buttonStyle2.up = new SpriteDrawable(new Sprite(buttonUp)).tint(Color.GREEN); buttonStyle2.down = new SpriteDrawable(new Sprite(buttonDown)).tint(Color.GREEN); play_button = new Button(buttonStyle2); play_button.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { PLAY_CLICKED++; if (!prefs.getString("type", "").equals("")) { stage.addAction(Actions.sequence(Actions.fadeOut(.25f), Actions.delay(.25f), Actions.run(new Runnable() { @Override public void run() { CometMeBro menu = new CometMeBro(cmb, currentDurationCount * 20, 3 / currentDangerCount, currentResourcesCount * 10, prefs.getString("type", "sand")); cmb.setScreen(menu); } }))); } } }); Button.ButtonStyle style1 = new Button.ButtonStyle(); style1.up = skin.getDrawable("desert"); style1.down = skin.getDrawable("desert"); sand = new Button(style1); Button.ButtonStyle style2 = new Button.ButtonStyle(); style2.up = skin.getDrawable("city"); style2.down = skin.getDrawable("city"); city = new Button(style2); Button.ButtonStyle style3 = new Button.ButtonStyle(); style3.up = skin.getDrawable("ice"); style3.down = skin.getDrawable("ice"); ice = new Button(style3); Button.ButtonStyle style4 = new Button.ButtonStyle(); style4.up = skin.getDrawable("grassland"); style4.down = skin.getDrawable("grassland"); grass = new Button(style4); Button.ButtonStyle style5 = new Button.ButtonStyle(); style5.up = skin.getDrawable("ocean"); style5.down = skin.getDrawable("ocean"); ocean = new Button(style5); Button.ButtonStyle style6 = new Button.ButtonStyle(); style6.up = skin.getDrawable("lava"); style6.down = skin.getDrawable("lava"); lava = new Button(style6); Button.ButtonStyle style7 = new Button.ButtonStyle(); style7.up = skin.getDrawable("candy"); style7.down = skin.getDrawable("candy"); candy = new Button(style7); Button.ButtonStyle style8 = new Button.ButtonStyle(); style8.up = skin.getDrawable("easter"); style8.down = skin.getDrawable("easter"); spring = new Button(style8); Button.ButtonStyle style9 = new Button.ButtonStyle(); style9.up = skin.getDrawable("winter"); style9.down = skin.getDrawable("winter"); winter = new Button(style9); sand.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "sand"); prefs.putString("title", sandPlanet); prefs.flush(); currentDanger = one; currentDuration = two; currentResources = one; currentDangerCount = 1; currentDurationCount = 2; currentResourcesCount = 1; } }); ice.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "ice"); prefs.putString("title", icePlanet); prefs.flush(); currentDanger = two; currentDuration = two; currentResources = two; currentDangerCount = 2; currentDurationCount = 2; currentResourcesCount = 2; } }); candy.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "candy"); prefs.putString("title", candyPlanet); prefs.flush(); currentDanger = one; currentDuration = one; currentResources = one; currentDangerCount = 1; currentDurationCount = 1; currentResourcesCount = 1; } }); spring.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "spring"); prefs.putString("title", springPlanet); prefs.flush(); currentDanger = one; currentDuration = two; currentResources = two; currentDangerCount = 1; currentDurationCount = 2; currentResourcesCount = 2; } }); winter.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "christmas"); prefs.putString("title", holidayPlanet); prefs.flush(); currentDanger = two; currentDuration = one; currentResources = three; currentDangerCount = 2; currentDurationCount = 1; currentResourcesCount = 3; } }); lava.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "lava"); prefs.putString("title", lavaPlanet); prefs.flush(); currentDanger = three; currentDuration = two; currentResources = three; currentDangerCount = 3; currentDurationCount = 2; currentResourcesCount = 3; } }); ocean.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "water"); prefs.putString("title", waterPlanet); prefs.flush(); currentDanger = two; currentDuration = three; currentResources = two; currentDangerCount = 2; currentDurationCount = 3; currentResourcesCount = 2; } }); grass.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "simple"); prefs.putString("title", simplePlanet); prefs.flush(); currentDanger = one; currentDuration = two; currentResources = one; currentDangerCount = 1; currentDurationCount = 2; currentResourcesCount = 1; } }); city.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { prefs.putString("type", "city"); prefs.putString("title", cityPlanet); prefs.flush(); currentDanger = three; currentDuration = three; currentResources = two; currentDangerCount = 3; currentDurationCount = 3; currentResourcesCount = 2; } }); Random rand = new Random(); int planetRandom = rand.nextInt(8); switch (planetRandom) { case 0: planet1 = sand; planet2 = ice; planet3 = candy; break; case 1: planet1 = ocean; planet2 = ice; planet3 = spring; break; case 2: planet1 = lava; planet2 = city; planet3 = sand; break; case 3: planet1 = grass; planet2 = ocean; planet3 = spring; break; case 4: planet1 = ice; planet2 = lava; planet3 = candy; break; case 5: planet1 = sand; planet2 = spring; planet3 = ocean; break; case 6: planet1 = ice; planet2 = grass; planet3 = spring; break; case 7: planet1 = candy; planet2 = spring; planet3 = sand; break; } if (STYLE == 3) { table1.setTransform(true); table1.add(planet1).width(Value.percentHeight(.25f, table)).height(Value.percentHeight(.25f, table)) .center().pad(10); table1.setX((stage.getWidth() / 4) * 3 - table1.getHeight() / 2); table1.setY(stage.getHeight() / 2 - table1.getHeight() / 2); table.addActor(table1); table2 = new Table(); table2.setTransform(true); table2.add(planet2).width(Value.percentHeight(.15f, table)).height(Value.percentHeight(.15f, table)) .center().pad(10); table2.setX((stage.getWidth() / 4) * 2 - table2.getWidth() / 2); table2.setY(stage.getHeight() / 2 - table2.getHeight() / 2); table.addActor(table2); table3 = new Table(); table3.setTransform(true); table3.add(planet3).width(Value.percentHeight(.2f, table)).height(Value.percentHeight(.2f, table)) .center().pad(10); table3.setX(stage.getWidth() / 4 - table3.getWidth() / 2); table3.setY(stage.getHeight() / 2 - table3.getHeight() / 2); table.addActor(table3); } space = new Texture("space16x9fourth.png"); SpriteDrawable spaceDrawable = new SpriteDrawable(new Sprite(space)); table.setBackground(spaceDrawable); table.setFillParent(true); Label resourceslbl = new Label("Resources: ", skin.get("label", Label.LabelStyle.class)); resourcesDots = new Label(three, skin.get("label", Label.LabelStyle.class)); Label dangerlbl = new Label("Danger: ", skin.get("label", Label.LabelStyle.class)); dangerDots = new Label(two, skin.get("label", Label.LabelStyle.class)); Label durationlbl = new Label("Duration: ", skin.get("label", Label.LabelStyle.class)); durationDots = new Label(three, skin.get("label", Label.LabelStyle.class)); pickPlanetLbl = new Label("", skin.get("label", Label.LabelStyle.class)); crystalCountlbl = new Label(String.valueOf(prefs.getInteger("crystalCount", 0)), skin.get("labelblue", Label.LabelStyle.class)); resourceslbl.setFontScale(.5f); dangerlbl.setFontScale(.5f); durationlbl.setFontScale(.5f); resourcesDots.setFontScale(.5f); dangerDots.setFontScale(.5f); durationDots.setFontScale(.5f); subtable.setBackground(planethud); crystaltable.setBackground(skin.getDrawable("bluecrystalhud")); subtable.row().colspan(2); subtable.add(dangerlbl).left().colspan(1).padBottom(-15).align(Align.right); //.padRight(Value.percentWidth(3.75f)) subtable.add(dangerDots).left().colspan(1).padBottom(-15).align(Align.left) .padRight(subtable.getWidth() / 2); subtable.row(); subtable.add(durationlbl).left().colspan(1).align(Align.right); //.padRight(Value.percentWidth(2.91f)); subtable.add(durationDots).left().colspan(1).align(Align.left).padRight(subtable.getWidth() / 2); subtable.add(play_button).right().width(Value.percentHeight(.1f, table)) .height(Value.percentHeight(.1f, table)); subtable.row(); subtable.add(resourceslbl).left().colspan(1).padTop(-15).align(Align.right); //.padRight(Value.percentWidth(2.6f)); subtable.add(resourcesDots).left().colspan(1).padTop(-15).align(Align.left) .padRight(subtable.getWidth() / 2); subtable.setX(0); subtable.setY(0); subtable.setWidth(CMB.WIDTH); subtable.setHeight(CMB.HEIGHT / 4.5f); prefs.putString("type", ""); prefs.putString("title", ""); prefs.flush(); planetName = prefs.getString("title", ""); planet_name = new Label(planetName, skin.get("label", Label.LabelStyle.class)); table.row(); table.add(backButton).left().top().width(Value.percentWidth(1f)).height(Value.percentHeight(1f)) .padBottom(20).padTop(70).padRight(1050); table.add(settingsButton).right().top().width(Value.percentWidth(1f)).height(Value.percentHeight(1f)) .padTop(70); table.row(); table.add(pickPlanetLbl).center().top().padBottom(240); table.row(); table.add(crystaltable).left().bottom().width(Value.percentHeight(.24f, table)) .height(Value.percentHeight(.187f, table)).padBottom(200).padLeft(-20); table.add(planet_name).center().bottom().padLeft(Value.percentWidth(-.9f, table)).padBottom(200); table.row(); table.addActor(subtable); crystalCountlbl.setFontScale(.4f); crystaltable.row().colspan(1); crystaltable.add(crystalCountlbl).colspan(1).bottom().center().align(Align.center).padTop(70).padRight(10); stage.addActor(table); stage.addAction(Actions.sequence(Actions.fadeIn(1f))); Gdx.input.setInputProcessor(stage); }
From source file:com.cookbook.samples.client.GwtSampleWrapper.java
License:Apache License
@Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); Gdx.app.log("GdxSampleGwt", "Setting up for " + tests.length + " tests."); ui = new Stage(); skin = new Skin(Gdx.files.internal("data/uiskin.json")); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); container = new Table(); ui.addActor(container);/*from w w w . j av a2 s .c o m*/ container.debug(); Table table = new Table(); ScrollPane scroll = new ScrollPane(table); container.add(scroll).expand().fill(); table.pad(10).defaults().expandX().space(4); for (final Instancer instancer : tests) { table.row(); TextButton button = new TextButton(instancer.instance().getClass().getName(), skin); button.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui); test = instancer.instance(); Gdx.app.log("GdxSampleGwt", "Clicked on " + test.getClass().getName()); test.create(); test.setPlatformResolver(new WebResolver()); test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } }); table.add(button).expandX().fillX(); } container.row(); container.add( new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))) .pad(5, 5, 5, 5); Gdx.input = new InputWrapper(Gdx.input) { @Override public boolean keyUp(int keycode) { if (keycode == Keys.ESCAPE) { if (test != null) { Gdx.app.log("GdxSampleGwt", "Exiting current test."); dispose = true; } } return false; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) { if (test != null) { dispose = true; } } return false; } }; ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui); Gdx.app.log("GdxSampleGwt", "Test picker UI setup complete."); }
From source file:com.cyphercove.dayinspace.Story.java
License:Apache License
public Story(Assets assets) { Json json = new Json(); Board.Parameters[] params = json.fromJson(Board.Parameters[].class, Gdx.files.internal("boardParams.json")); for (int i = 0; i < params.length; i++) { Board.Parameters stageParams = params[i]; Board board = new Board(assets, stageParams); boards.add(board);/*from www .j a v a 2 s . c o m*/ } movesPerTurn = 3; livesLeft = 3; heartsLeft = 3; stagesComplete = 0; stepsTaken = 0; enemiesDestroyed = 0; }
From source file:com.cyphercove.doublehelix.BackgroundShader.java
License:Apache License
public void reloadShader() { if (program != null) program.dispose();/*from w w w . j ava 2 s . c om*/ final String prefix = "glow"; String vert = Gdx.files.internal(prefix + "_vs.glsl").readString(); String frag = Gdx.files.internal(prefix + "_fs.glsl").readString(); program = new ShaderProgram(vert, frag); if (!program.isCompiled()) Gdx.app.log("Shader error", program.getLog()); u_texture = program.getUniformLocation("u_texture"); u_color = program.getUniformLocation("u_color"); u_ambient = program.getUniformLocation("u_ambient"); u_modelViewProjTrans = program.getUniformLocation("u_modelViewProjTrans"); }
From source file:com.cyphercove.doublehelix.BlackShader.java
License:Apache License
public void reloadShader() { if (program != null) program.dispose();/*from ww w . j av a2 s. c om*/ final String prefix = "black"; String vert = Gdx.files.internal(prefix + "_vs.glsl").readString(); String frag = Gdx.files.internal(prefix + "_fs.glsl").readString(); program = new ShaderProgram(vert, frag); if (!program.isCompiled()) Gdx.app.log("Shader error", program.getLog()); u_modelViewProjTrans = program.getUniformLocation("u_modelViewProjTrans"); }
From source file:com.cyphercove.doublehelix.FilmGrain.java
License:Apache License
public FilmGrain(Texture noiseTexture, Texture borderTexture, Texture scanlineTexture, boolean forBloom) { this.forBloom = forBloom; this.noiseTexture = noiseTexture; this.borderTexture = borderTexture; this.scanlineTexture = scanlineTexture; String prefix = forBloom ? "filmgrain_bloom" : "filmgrain"; String vertexShaderSrc = Gdx.files.internal(prefix + "_vs.glsl").readString(); String fragmentShaderSrc = Gdx.files.internal(prefix + "_fs.glsl").readString(); filmGrainShaderProgram = new ShaderProgram(vertexShaderSrc, fragmentShaderSrc); if (!forBloom) { batch = new SpriteBatch(1, filmGrainShaderProgram); batch.setProjectionMatrix(new Matrix4().idt()); }/*from ww w . j a va 2 s.com*/ u_grainInverse = filmGrainShaderProgram.getUniformLocation("u_grainInverse"); u_grainOffset = filmGrainShaderProgram.getUniformLocation("u_grainOffset"); u_flicker = filmGrainShaderProgram.getUniformLocation("u_flicker"); u_noiseTexture = filmGrainShaderProgram.getUniformLocation("u_noiseTexture"); u_scanLineTexture = filmGrainShaderProgram.getUniformLocation("u_scanLineTexture"); u_scanLineInverse = filmGrainShaderProgram.getUniformLocation("u_scanLineInverse"); if (forBloom) { u_borderTexture = filmGrainShaderProgram.getUniformLocation("u_borderTexture"); u_flipped = filmGrainShaderProgram.getUniformLocation("u_flipped"); } }