/** Helper function to create tiles out of the given {@link Texture} starting from the top left corner going to the right and * ending at the bottom right corner. Only complete tiles will be returned so if the texture's width or height are not a * multiple of the tile width and height not all of the texture will be used. * * @param texture the Texture * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public static TextureRegion[][] split (Texture texture, int tileWidth, int tileHeight) { TextureRegion region = new TextureRegion(texture); return region.split(tileWidth, tileHeight); } }
/** Helper function to create tiles out of the given {@link Texture} starting from the top left corner going to the right and * ending at the bottom right corner. Only complete tiles will be returned so if the texture's width or height are not a * multiple of the tile width and height not all of the texture will be used. * * @param texture the Texture * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public static TextureRegion[][] split (Texture texture, int tileWidth, int tileHeight) { TextureRegion region = new TextureRegion(texture); return region.split(tileWidth, tileHeight); } }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/walkanim.png")); TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0]; Array<TextureRegion> rightWalkFrames = new Array(TextureRegion.class); for (int i = 0; i < leftWalkFrames.length; i++) { TextureRegion frame = new TextureRegion(leftWalkFrames[i]); frame.flip(true, false); rightWalkFrames.add(frame); } leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames); rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames); TextureRegion[] rightRegions = rightWalk.getKeyFrames(); // testing backing array type TextureRegion firstRightRegion = rightRegions[0]; Gdx.app.log("AnimationTest", "First right walk region is " + firstRightRegion.getRegionWidth() + "x" + firstRightRegion.getRegionHeight()); cavemen = new Caveman[100]; for (int i = 0; i < 100; i++) { cavemen[i] = new Caveman((float)Math.random() * Gdx.graphics.getWidth(), (float)Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false); } batch = new SpriteBatch(); fpsLog = new FPSLogger(); }
@Override public void create () { Gdx.input.setInputProcessor(this); texture = new Texture(Gdx.files.internal("data/animation.png")); TextureRegion[][] regions = TextureRegion.split(texture, 32, 48); TextureRegion[] downWalkReg = regions[0]; TextureRegion[] leftWalkReg = regions[1]; TextureRegion[] rightWalkReg = regions[2]; TextureRegion[] upWalkReg = regions[3]; downWalk = new Animation<TextureRegion>(ANIMATION_SPEED, downWalkReg); leftWalk = new Animation<TextureRegion>(ANIMATION_SPEED, leftWalkReg); rightWalk = new Animation<TextureRegion>(ANIMATION_SPEED, rightWalkReg); upWalk = new Animation<TextureRegion>(ANIMATION_SPEED, upWalkReg); currentWalk = leftWalk; currentFrameTime = 0.0f; spriteBatch = new SpriteBatch(); position = new Vector2(); }
TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32); map = new TiledMap(); MapLayers layers = map.getLayers();
@Override public void create () { spriteBatch = new SpriteBatch(); font = new BitmapFont(); modelBatch = new ModelBatch(); DefaultShader.defaultCullFace = GL20.GL_FRONT; camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.near = 0.5f; camera.far = 1000; controller = new FirstPersonCameraController(camera); Gdx.input.setInputProcessor(controller); lights = new Environment(); lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f)); lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0)); Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png")); TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32); MathUtils.random.setSeed(0); voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20); PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10); float camX = voxelWorld.voxelsX / 2f; float camZ = voxelWorld.voxelsZ / 2f; float camY = voxelWorld.getHighest(camX, camZ) + 1.5f; camera.position.set(camX, camY, camZ); }
@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); debugRenderer = new ShapeRenderer(); }
TextureRegion[][] hexes = TextureRegion.split(hexture, 112, 97); map = new TiledMap(); MapLayers layers = map.getLayers();
/** Helper function to create tiles out of the given {@link Texture} starting from the top left corner going to the right and * ending at the bottom right corner. Only complete tiles will be returned so if the texture's width or height are not a * multiple of the tile width and height not all of the texture will be used. * * @param texture the Texture * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public static TextureRegion[][] split (Texture texture, int tileWidth, int tileHeight) { TextureRegion region = new TextureRegion(texture); return region.split(tileWidth, tileHeight); } }
public static TextureRegion[] loadAnimation(String fileName, int width, int height, int frameCols, int frameRows) { TextureRegion img = loadSprite(fileName, width * frameCols, height * frameRows); TextureRegion[][] spritesheetTemp = img.split(width, height); TextureRegion[] spritesheet = new TextureRegion[frameRows*frameCols]; // Fix the indices frameCols--; frameRows--; for (int i = 0; i <= frameRows; i++) { for (int y = 0; y <= frameCols; y++) { spritesheet[i+y] = spritesheetTemp[i][y]; } } return spritesheet; }
private static TextureRegion[][] cut(String path, int w, int h) { Texture tex = load(path); return TextureRegion.split(tex, w, h); }
/** * * @param tr * 数字材质 * @param tileWidth * 数字宽度 * @param tileHeight * 数字高度 * @param startCharMap * 起始字符,例如:0123456789*+-x * 这里必须填写数字的全部字符,并且顺序一致.否则会显示错乱 * @param stringValue * 显示内容,例如:89/50 */ public LabelAtlas(TextureRegion tr, int tileWidth, int tileHeight, String startCharMap, String stringValue) { this.tileWidth = tileWidth; this.tileHeight = tileHeight; TextureRegion[][] arr = tr.split(tileWidth, tileHeight); trs = arr[0]; if (startCharMap == null) { startCharMap = "0";// 默认值 } this.chars = startCharMap.toCharArray(); setText(stringValue); }
/** * 获取TextureRegions */ public TextureRegion[] getTextureRegions(String path, int numx, int numy) { TextureRegion img = getTextureRegion(path); int tileWidth = (int) ((float) img.getRegionWidth() / numx); int tileHeight = (int) ((float) img.getRegionHeight() / numy); TextureRegion imgs[][] = img.split(tileWidth, tileHeight); TextureRegion walkFrames[] = new TextureRegion[numx * numy]; for (int y = 0; y < numy; y++) { for (int x = 0; x < numx; x++) { walkFrames[y * numx + x] = imgs[y][x]; } } return walkFrames; }
public ActorNumber(TextureRegion tex) { texs = tex.split((int) (tex.getRegionWidth() / 10f), tex.getRegionHeight())[0]; fontWidth = texs[0].getRegionWidth(); fontHeight = texs[0].getRegionHeight(); setSize(fontWidth, fontHeight); }
public ActorAnimation(TextureRegion img, int numx, int numy, int max) { int tileWidth = (int) ((float) img.getRegionWidth() / numx); int tileHeight = (int) ((float) img.getRegionHeight() / numy); TextureRegion imgs[][] = img.split(tileWidth, tileHeight); TextureRegion walkFrames[] = new TextureRegion[max]; for (int y = 0; y < numy; y++) { for (int x = 0; x < numx; x++) { int id = y * numx + x; if (id < max) { walkFrames[id] = imgs[y][x]; } } } setSize(walkFrames[0].getRegionWidth(), walkFrames[0].getRegionHeight()); animation = new Animation(frameTime, (Object[]) walkFrames); animation.setPlayMode(playMode); }