@Override public LaserAnimation getAnimation() { if (color == ThLaserColor.LIGHTNING) type = ThLaserType.LIGHTNING; String identifier = type.name() + " " + (color == null ? "" : color.name()); if (animations.containsKey(identifier)) { return animations.get(identifier); } FileHandle textureFolder = Gdx.files.internal("lasers/" + type.name() + "/"); Array<Texture> array = new Array<Texture>(); String[] fileNames; float frameDelay = 1f; if (type == ThLaserType.LIGHTNING) { fileNames = new String[] {"1", "2", "3", "4"}; frameDelay = 5f; } else { fileNames = new String[] {color.name()}; FileHandle file = textureFolder.child(color.name() + ".png"); Texture text = Loader.texture(file); text.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest); } for (String name : fileNames) { FileHandle frame = textureFolder.child(name + ".png"); Texture text = Loader.texture(frame); text.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest); array.add(text); } LaserAnimation la = new LaserAnimation(frameDelay, array); animations.put(identifier, la); return getAnimation(); // It's now in the hashmap, and will load from that (also needs to clone // it). }
public void loadEmitterImages(FileHandle imagesDir) { for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); String imagePath = emitter.getImagePath(); if (imagePath == null) continue; String imageName = new File(imagePath.replace('\\', '/')).getName(); emitter.setSprite(new Sprite(loadTexture(imagesDir.child(imageName)))); } }
public static FileHandle getRelativeFileHandle(FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
@Override public void init() { settings = new Settings(); settings.maxWidth = 4096; settings.maxHeight = 4096; settings.combineSubdirectories = true; settings.silent = true; settings.useIndexes = false; settings.fast = true; loadingRegion = Assets.icons.findRegion("refresh-big"); missingRegion = Assets.icons.findRegion("file-question-big"); FileHandle out = fileAccess.getModuleFolder(".textureCache"); cachePath = out.path(); cacheFile = out.child("cache.atlas"); gfxPath = fileAccess.getAssetsFolder().child("gfx").path(); atlasesFolder = fileAccess.getAssetsFolder().child("atlas"); watcher.addListener(this); try { if (cacheFile.exists()) cache = new TextureAtlas(cacheFile); } catch (Exception e) { Log.error("Error while loading texture cache, texture cache will be regenerated"); } try { if (atlasesFolder.exists()) { FileHandle[] files = atlasesFolder.list(); for (FileHandle file : files) if (file.extension().equals("atlas")) updateAtlas(file); } } catch (Exception e) { Log.error("Error encountered while loading one of atlases"); Log.exception(e); } updateCache(); }
public static String[] writePixmapsCompressed( Array<Page> pages, FileHandle outputDir, String fileName) { Pixmap[] pix = new Pixmap[pages.size]; for (int i = 0; i < pages.size; i++) { pix[i] = pages.get(i).getPixmap(); } // Pixmap[] pagesArray = writePixmaps(pix, outputDir, fileName); if (pages == null || pages.size == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write"); String[] pageRefs = new String[pages.size]; for (int i = 0; i < pages.size; i++) { String ref = pages.size == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png"); // the ref for this image pageRefs[i] = ref; // write the PNG in that directory PixmapIO.writeCIM(outputDir.child(ref), pages.get(i).getPixmap()); } return pageRefs; }
public FileHandle getFileHandleForScene(EditorScene scene) { return assetsFolder.child(scene.path); }
public Ringo(float maxHealth, float x, float y) { super(maxHealth, x, y); int chunkHeight = 160; int chunkWidth = 128; Texture sprite = Loader.texture(FOLDER.child("anm.png")); sprite.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest); Sprite fbs = new Sprite(Loader.texture(FOLDER.child("fbs.png"))); fbs.setScale(2F); TextureRegion nameTag = new TextureRegion(Loader.texture(FOLDER.child("nametag.png"))); Animation idle = ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 1, 2, 3, 4, 5); idle.setPlayMode(PlayMode.LOOP); Animation left = new MovementAnimation( ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 11, 12), ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 13, 14, 15), 8f); Animation right = new MovementAnimation( ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 6, 7), ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 8, 9, 10), 8f); Animation special = new StartupLoopAnimation( ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 16, 17), ImageSplitter.getAnimationFromSprite(sprite, chunkHeight, chunkWidth, 8F, 18, 19, 20), 8f); special.setPlayMode(PlayMode.NORMAL); Music bgm = new J2hMusic(Gdx.audio.newMusic(FOLDER.child("bgm.mp3"))); bgm.setLooping(true); setAuraColor(AllStarUtil.from255RGB(104, 19, 52).mul(6f)); setBgAuraColor(AllStarUtil.from255RGB(40, 40, 40)); set(nameTag, bgm); set(fbs, idle, left, right, special); backgroundSpawner = new Setter<BackgroundBossAura>() { @Override public void set(final BackgroundBossAura t) { final Background bg = new Background(Loader.texture(FOLDER.child("bg.png"))) { @Override public void onDraw() { setBlendFunc(GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_COLOR); super.onDraw(); }; }; bg.setFrameBuffer(t.getBackgroundBuffer()); bg.setVelV(0.05d); bg.setVelU(-0.05d); bg.getSprite().setScale(0.75f); bg.getSprite().setAlpha(1f); bg.setZIndex(bg.getZIndex() - 20); game.spawn(bg); float speed = 10; // Layer 1 final Background bge = new Background(Loader.texture(FOLDER.child("bge.png"))) { @Override public void onDraw() { setBlendFunc(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_SRC_COLOR); super.onDraw(); }; }; bge.setFrameBuffer(t.getBackgroundBuffer()); bge.getSprite().setScale(1.5f); bge.setRotationDegs(speed); bge.getSprite().setAlpha(1f); bge.setZIndex(bg.getZIndex() - 2); game.spawn(bge); // Layer 2 { Background bgeTwo = new Background(Loader.texture(FOLDER.child("bge.png"))) { @Override public void onDraw() { setBlendFunc(GL20.GL_SRC_COLOR, GL20.GL_ZERO); super.onDraw(); }; }; bgeTwo.getSprite().setScale(1.5f); bgeTwo.setFrameBuffer(t.getBackgroundBuffer()); bgeTwo.setRotationDegs(-speed); bgeTwo.getSprite().setAlpha(1f); bgeTwo.setZIndex(bg.getZIndex() - 4); game.spawn(bgeTwo); } Game.getGame() .spawn( new ClearBackground(bg.getZIndex() - 10) { { setFrameBuffer(t.getBackgroundBuffer()); } }); } }; }