Java Code Examples for com.badlogic.gdx.graphics.g2d.TextureRegion#flip()

The following examples show how to use com.badlogic.gdx.graphics.g2d.TextureRegion#flip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a tileset from an image
 * 
 * @param image
 * @param tileWidth
 * @param tileHeight
 * @param margin
 * @param spacing
 * @return
 */
public static TextureRegion[] toTileSet(TextureRegion image, int tileWidth, int tileHeight, int margin, int spacing) {
    int nextX = margin;
    int nextY = margin;
    
    List<TextureRegion> images = new ArrayList<TextureRegion>();
    while (nextY + tileHeight + margin <= image.getRegionHeight()) {
        TextureRegion tile = new TextureRegion(image, nextX, nextY, tileWidth, tileHeight);
        tile.flip(false, true);
        
        images.add(tile);
        
        nextX += tileWidth + spacing;

        if (nextX + tileWidth + margin > image.getRegionWidth()) {
            nextX = margin;
            nextY += tileHeight + spacing;
        }            
    }
    
    return images.toArray(new TextureRegion[images.size()]);
}
 
Example 2
Source File: BasicInfo.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public BasicInfo (UserProfile profile) {
	name = new HudLabel(FontFace.CurseRedYellowBig, profile.userName, true);
	flag = Art.getFlag(profile.userCountryCode);
	flagRegion = new TextureRegion(flag);
	flagRegion.flip(false, true);

	borderX = 15;
	borderY = 5;
	w = 80;
	h = 80;
	name.setPosition(w + borderX * 2 + name.getWidth() / 2, 42);
}
 
Example 3
Source File: SpriteSheet.java    From TerraLegion with MIT License 5 votes vote down vote up
public void load(Texture texture, int spriteWidth, int spriteHeight, int gapWidth, int gapHeight) {
    dispose();
    
    this.texture = texture;
    this.spriteWidth = spriteWidth;
    this.spriteHeight = spriteHeight;
    this.gapWidth = gapWidth;
    this.gapHeight = gapHeight;
    
    final int width = texture.getWidth();
    final int height = texture.getHeight();
    rowCount = ((width - spriteWidth) / (spriteWidth + gapWidth)) + 1;
    columnCount = ((height - spriteHeight) / (spriteHeight + gapHeight)) + 1;
    if ((height - spriteHeight) % (spriteHeight + gapHeight) != 0) {
        columnCount++;
    }
    
    sprites = new TextureRegion[columnCount][rowCount];
    mirrored = new TextureRegion[columnCount][rowCount];
    for (int column = 0; column < columnCount; column++) {
        for (int row = 0; row < rowCount; row++) {
            sprites[column][row] = extractSprite(row, column);
            TextureRegion mirroredSprite = new TextureRegion(sprites[column][row]);
            mirroredSprite.flip(true, false);
            mirrored[column][row] = mirroredSprite;
        }
    }
}
 
Example 4
Source File: Sprite3DRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void retrieveAssets() {
	// create STATIC BATCHS if not created yet
	if (modelBatch == null)
		createBatchs();

	createEnvirontment();

	for (String key : sourceCache.keySet()) {
		if (sourceCache.get(key).refCounter > 0)
			retrieveSource(key);
	}

	if (currentAnimation != null) { // RESTORE FA
		ModelCacheEntry entry = (ModelCacheEntry) sourceCache.get(currentAnimation.source);
		currentSource = entry;

		float speed = currentAnimation.duration;

		if (currentAnimationType == Tween.Type.REVERSE || currentAnimationType == Tween.Type.REVERSE_REPEAT)
			speed *= -1;

		((ModelCacheEntry) currentSource).controller.setAnimation(currentAnimation.id, currentCount, speed,
				animationListener);

		update(lastAnimationTime);

	} else if (initAnimation != null) {
		startAnimation(initAnimation, Tween.Type.SPRITE_DEFINED, 1, null);

		if (currentAnimation != null)
			lookat(modelRotation);
	}

	if (currentSource != null && renderShadow)
		genShadowMap();

	if (USE_FBO) {
		GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(width, height);

		frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE);
		fb = frameBufferBuilder.build();

		tex = new TextureRegion(fb.getColorBufferTexture());
		tex.flip(false, true);

		renderTex();
	}

	computeBbox();
}
 
Example 5
Source File: TiledMapLoader.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
private TilesetAtlas parseTilesets(LeoArray tilesets, boolean loadImages) throws Exception {
    if(tilesets.isEmpty()) {
        throw new IllegalArgumentException("There must be at least 1 tileset");
    }
    
    TilesetAtlas atlas = new  TilesetAtlas();
    for(LeoObject t : tilesets) {
        LeoMap tileset = t.as();
                    
        // skip the sourced tilesets
        if(t.hasObject("source")) {
            // HACK: Updated version of Tiled which no longer supports inlining
            // shared tilests (lame)
            String source = tileset.getString("source");
            if(source.endsWith("collidables.tsx")) {
                tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/collision_tileset.png"));
                tileset.putByString("name", LeoString.valueOf("collidables"));
            }
            else if(source.endsWith("city.tsx")) {
                tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/cs2dnorm.png"));
                tileset.putByString("name", LeoString.valueOf("city"));
            }
            else if(source.endsWith("surface_types.tsx")) {
                tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/surface_types.png"));
                tileset.putByString("name", LeoString.valueOf("surfaces"));
            }
            
            tileset.putByString("tilewidth", LeoObject.valueOf(32));
            tileset.putByString("tileheight", LeoObject.valueOf(32));
        }
        
        int firstgid = tileset.getInt("firstgid");            
        int margin = tileset.getInt("margin");
        int spacing = tileset.getInt("spacing");
        int tilewidth = tileset.getInt("tilewidth");
        int tileheight = tileset.getInt("tileheight");
        
        LeoMap tilesetprops = null;
        LeoObject props = tileset.getByString("tileproperties");
        if(LeoObject.isTrue(props) && props.isMap()) {
            tilesetprops = props.as();
        }

        TextureRegion image = null;
        TextureRegion[] images = null;
                                            
        if(loadImages) {
            String imagePath = tileset.getString("image");
            
            // override to local assets tile directory
            if(!new File(imagePath).exists()) {
                imagePath = "./assets/gfx/tiles" + imagePath.substring(imagePath.lastIndexOf("/"), imagePath.length());
            }
            image = TextureUtil.loadImage(imagePath);
            image.flip(false, true);
            image.getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
            image.getTexture().setWrap(TextureWrap.MirroredRepeat, TextureWrap.MirroredRepeat);
            
            images = TextureUtil.toTileSet(image, tilewidth, tileheight, margin, spacing);            
        }
        atlas.addTileset(new Tileset(firstgid, images, tilesetprops));
    }
    
    return atlas;
}
 
Example 6
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Loads an image
 *
 * @param image
 * @return
 * @throws Exception
 */
public static TextureRegion loadImage(String image) {
    Texture texture = new Texture(Gdx.files.internal(image));
    TextureRegion region = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
    region.flip(false, true);
    return region;
}
 
Example 7
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Loads an image
 *
 * @param image
 * @return
 * @throws Exception
 */
public static TextureRegion loadImage(String image, int width, int height) {
    Texture texture = new Texture(Gdx.files.internal(image));
    TextureRegion region = new TextureRegion(texture, 0, 0, width, height);
    region.flip(false, true);
    return region;
}