com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator. 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: SmartFontGenerator.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
/** Convenience method for generating a font, and then writing the fnt and png files.
 * Writing a generated font to files allows the possibility of only generating the fonts when they are missing, otherwise
 * loading from a previously generated file.
 * @param fontFile
 * @param fontSize
 */
private BitmapFont generateFontWriteFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight) {
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);

	PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false);
	FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(fontSize, FreeTypeFontGenerator.DEFAULT_CHARS, false, packer);
	Array<PixmapPacker.Page> pages = packer.getPages();
	TextureRegion[] texRegions = new TextureRegion[pages.size];
	for (int i=0; i<pages.size; i++) {
		PixmapPacker.Page p = pages.get(i);
		Texture tex = new Texture(new PixmapTextureData(p.getPixmap(), p.getPixmap().getFormat(), false, false, true)) {
			@Override
			public void dispose () {
				super.dispose();
				getTextureData().consumePixmap().dispose();
			}
		};
		tex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
		texRegions[i] = new TextureRegion(tex);
	}
	BitmapFont font = new BitmapFont(fontData, texRegions, false);
	saveFontToFile(font, fontSize, fontName, packer);
	generator.dispose();
	packer.dispose();
	return font;
}
 
Example #2
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve the desired font and size (may load the font
 * if not cached).
 * 
 * @param alias
 * @param size
 * @return the font
 */
private BitmapFont getFont(String alias, int size) {
    BitmapFont font = null;
    
    String mask = alias + ":" + size;
    if(this.fonts.containsKey(mask)) {
        font = this.fonts.get(mask);
    }
    else if(this.generators.containsKey(alias)) {
        FreeTypeFontParameter params = new FreeTypeFontParameter();
        params.size = size;
        params.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
        params.flip = true;
        params.magFilter = TextureFilter.Linear;
        params.minFilter = TextureFilter.Linear;
        
        font = this.generators.get(alias).generateFont(params);
        this.fonts.put(mask, font);
    }
    
    return font;
}
 
Example #3
Source File: KeyConfiguration.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
public void create() {
	loadSkin(SkinType.KEY_CONFIG);
	if(getSkin() == null) {
		this.setSkin(new KeyConfigurationSkin(Resolution.HD, main.getConfig().getResolution()));
	}

	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
			Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = (int) (20 * getSkin().getScaleY());
	titlefont = generator.generateFont(parameter);
	shape = new ShapeRenderer();

	input = main.getInputProcessor();
	keyboard = input.getKeyBoardInputProcesseor();
	controllers = input.getBMInputProcessor();
	midiinput = input.getMidiInputProcessor();
	setMode(0);
}
 
Example #4
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void resetGenerators() {
	if (fonts != null) {
		for (FreeTypeFontGenerator generator : fonts.keySet()) {
			for (BitmapFont f : fonts.get(generator).values()) {
				f.dispose();
			}
			fonts.get(generator).clear();
			generator.dispose();
		}
		fonts.clear();
		if (packer != null) {
			for (PixmapPacker.Page p : packer.getPages()) {
				p.getTexture().dispose();
			}
			packer.dispose();
		}
		fonts = null;
	}
	setupFontGenerators(pageSize, systemfont);
}
 
Example #5
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void resetGenerators() {
	if (fonts != null) {
		for (FreeTypeFontGenerator generator : fonts.keySet()) {
			for (BitmapFont f : fonts.get(generator).values()) {
				f.dispose();
			}
			fonts.get(generator).clear();
			generator.dispose();
		}
		fonts.clear();
		if (packer != null) {
			for (PixmapPacker.Page p : packer.getPages()) {
				p.getTexture().dispose();
			}
			packer.dispose();
		}
		fonts = null;
	}
	setupFontGenerators(pageSize, systemfont);
}
 
Example #6
Source File: SmartFontGenerator.java    From gdx-smart-font with MIT License 5 votes vote down vote up
/** Convenience method for generating a font, and then writing the fnt and png files.
 * Writing a generated font to files allows the possibility of only generating the fonts when they are missing, otherwise
 * loading from a previously generated file.
 * @param fontFile
 * @param fontSize
 */
private BitmapFont generateFontWriteFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight) {
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);

	PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false);
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = fontSize;
	parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
	parameter.flip = false;
	parameter.packer = packer;
	FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(parameter);
	Array<PixmapPacker.Page> pages = packer.getPages();
	Array<TextureRegion> texRegions = new Array<>();
	for (int i = 0; i < pages.size; i++) {
		PixmapPacker.Page p = pages.get(i);
		Texture tex = new Texture(
				new PixmapTextureData(p.getPixmap(), p.getPixmap().getFormat(), false, false, true)) {
			@Override
			public void dispose() {
				super.dispose();
				getTextureData().consumePixmap().dispose();
			}
		};
		tex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
		texRegions.add(new TextureRegion(tex));
	}
	BitmapFont font = new BitmapFont((BitmapFont.BitmapFontData) fontData, texRegions, false);
	saveFontToFile(font, fontSize, fontName, packer);
	generator.dispose();
	packer.dispose();
	return font;
}
 
Example #7
Source File: LibgdxFonts.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Override
public GameFont newPlatformFont(FileHandle fileHandle) {
	if(fileHandle.path().endsWith(".ttf")) {
		final LibgdxFileHandle gdxFileHandle = (LibgdxFileHandle) fileHandle;
		FreeTypeFontGenerator.FreeTypeFontParameter fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
		fontParameter.size = 12;
		fontParameter.flip = true;
		fontParameter.kerning = true;
		FreeTypeFontGenerator freeTypeFontGenerator = new FreeTypeFontGenerator(gdxFileHandle.fileHandle);
		return new LibgdxBitmapFont(freeTypeFontGenerator.generateFont(fontParameter));
	}
	return new LibgdxBitmapFont(fileHandle);
}
 
Example #8
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
     * 
     */
    public GdxCanvas() {
        this.batch = new SpriteBatch();
        this.color = new Color();
        this.tmpColor = new Color();
        
        this.shaderStack = new Stack<>();
        this.zoomStack = new Stack<>();
        
        this.camera = new OrthographicCamera(getWidth(), getHeight());
        this.camera.setToOrtho(true, getWidth(), getHeight());
        this.camera.position.x = this.camera.viewportWidth/2;
        this.camera.position.y = this.camera.viewportHeight/2;
        this.camera.update();
        
        this.viewport = new FitViewport(getWidth(), getHeight(), camera);
        this.viewport.apply();
                
        this.generators = new HashMap<String, FreeTypeFontGenerator>();
        this.fonts = new HashMap<String, BitmapFont>();
        this.bounds = new GlyphLayout();
                
        this.transform = new Matrix4();
        //this.batch.setTransformMatrix(transform);
                
        //Matrix4 projection = new Matrix4();
        //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1);
        //this.batch.setProjectionMatrix(projection);
        
//        this.wHeight = getHeight();
        this.batch.setProjectionMatrix(this.camera.combined);
        
        this.shapes = new ShapeRenderer();
        //this.shapes.setTransformMatrix(transform);    
//        this.shapes.setProjectionMatrix(projection);
        //this.shapes.setProjectionMatrix(camera.combined);
        
        this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false);
    }
 
Example #9
Source File: CCLabelTTF.java    From cocos2d-java with MIT License 5 votes vote down vote up
public CCLabelTTF (String text, String fontName, int fontSize)      
{ 
	m_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal(fontName));
	m_pString = removeRepeatChar(text);
	m_bitmapFont = m_fontGenerator.generateFont(fontSize, m_pString, false);
	m_pFontName = fontName;
    m_fFontSize = fontSize;
    
    setContentSize(new CCSize(m_bitmapFont.getBounds(m_pString).width,m_bitmapFont.getCapHeight() -1/2f* m_bitmapFont.getDescent()));
    setAnchorPoint(new CCPoint(0.5f, 0.5f));
}
 
Example #10
Source File: EngineAssetManager.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
protected EngineAssetManager(FileHandleResolver resolver) {
	super(resolver);

	resResolver = new EngineResolutionFileResolver(resolver);
	setLoader(Texture.class, new TextureLoader(resResolver));
	setLoader(TextureAtlas.class, new TextureAtlasLoader(resResolver));
	setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
	setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));

	Texture.setAssetManager(this);
}
 
Example #11
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example #12
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private static FreeTypeFontGenerator getGeneratorForString( String input ){
	if (asianMatcher.matcher(input).find()){
		return asianFontGenerator;
	} else {
		return basicFontGenerator;
	}
}
 
Example #13
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example #14
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private static FreeTypeFontGenerator getGeneratorForString( String input ){
	if (KRMatcher.matcher(input).find()){
		return KRFontGenerator;
	} else if (SCMatcher.matcher(input).find()){
		return SCFontGenerator;
	} else if (JPMatcher.matcher(input).find()){
		return JPFontGenerator;
	} else {
		return basicFontGenerator;
	}
}
 
Example #15
Source File: SuperSnake.java    From super-snake with MIT License 5 votes vote down vote up
@Override
public void create () {
	batch = new SpriteBatch();

       WIDTH = Gdx.graphics.getBackBufferWidth();
       HEIGHT = Gdx.graphics.getBackBufferHeight();

       PADDED_WIDTH = WIDTH - PADDING;
       PADDED_HEIGHT = HEIGHT - PADDING;

       Gdx.app.log("Snake", "VIEWPORT " + WIDTH + ", " + HEIGHT);

       shapeRenderer = new ShapeRenderer();

       snake = new Snake(WIDTH / 2, HEIGHT / 2, INITIAL_SNAKE_LENGTH);
       pause_snake = new Snake(WIDTH / 2, 200, 100);

       FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/PatrickHand.ttf"));
       FreeTypeFontParameter parameter = new FreeTypeFontParameter();
       parameter.size = 32;
       font = generator.generateFont(parameter);

       parameter.size = 52;
       parameter.borderColor = Colors.spray;
       parameter.borderWidth = 2;
       fontBtn = generator.generateFont(parameter);

       parameter.size = 80;
       parameter.color = Color.WHITE;
       parameter.borderWidth = 2;
       parameter.borderColor = Colors.red;
       fontBig = generator.generateFont(parameter);

       generator.dispose();
}
 
Example #16
Source File: HUDRenderer.java    From killingspree with MIT License 5 votes vote down vote up
public HUDRenderer() {
    bomb = new Sprite(AssetLoader.instance.
            getTexture("sprites/bomb.png"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 7;
    font = new FreeTypeFontGenerator
            (Gdx.files.internal("fonts/game.ttf")).generateFont(parameter);
}
 
Example #17
Source File: KillingSpree.java    From killingspree with MIT License 5 votes vote down vote up
@Override
	public void create () {
	    generator = new FreeTypeFontGenerator
	            (Gdx.files.internal("fonts/splash.ttf"));
	    parameter = new FreeTypeFontParameter();
	    
	    AssetLoader.instance.loadAll();
	    currentScreen = new SplashScreen(this);
	    Gdx.audio.getClass();
//	    GameScreen gameScreen = new GameScreen(this);
//        gameScreen.startServer();
//        gameScreen.loadLevel("maps/retro-small.tmx", "localhost");
//        currentScreen = gameScreen;
	}
 
Example #18
Source File: Splash.java    From Skyland with MIT License 5 votes vote down vote up
private void addFonts() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/forcedsquare.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = Gdx.graphics.getHeight() / 15;
    Assets.menuSkin.add("font32", generator.generateFont(parameter));
    parameter.size = Gdx.graphics.getHeight() / 10;
    Assets.menuSkin.add("font64", generator.generateFont(parameter));
    parameter.size = Gdx.graphics.getHeight() / 25;
    Assets.menuSkin.add("console", generator.generateFont(parameter));
    generator.dispose();
}
 
Example #19
Source File: ResourceManager.java    From TerraLegion with MIT License 5 votes vote down vote up
public BitmapFont getFont(String id, String file, Color color, int size) {
	FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal(file));
	BitmapFont font = gen.generateFont(size);
	font.setColor(color);
	font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
	return font;
}
 
Example #20
Source File: SkinTextFont.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public SkinTextFont(String fontpath, int cycle, int size, int shadow, StringProperty property) {
    	super(property);
    	try {
            generator = new FreeTypeFontGenerator(Gdx.files.internal(fontpath));
            parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
            parameter.characters = "";
//            this.setCycle(cycle);
            parameter.size = size;
            setShadowOffset(new Vector2(shadow, shadow));    		
    	} catch (GdxRuntimeException e) {
    		Logger.getGlobal().warning("Skin Font読み込み失敗");
    	}
    }
 
Example #21
Source File: PracticeConfiguration.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void create(BMSModel model) {
	property.judgerank = model.getJudgerank();
	property.endtime = model.getLastTime() + 1000;
	Path p = Paths.get("practice/" + model.getSHA256() + ".json");
	if (Files.exists(p)) {
		Json json = new Json();
		try {
			property = json.fromJson(PracticeProperty.class, new FileReader(p.toFile()));
		} catch (FileNotFoundException | SerializationException e) {
			e.printStackTrace();
		}
	}

	if(property.gaugecategory == null) {
		property.gaugecategory = BMSPlayerRule.getBMSPlayerRule(model.getMode()).gauge;
	}
	this.model = model;
	if(property.total == 0) {
		property.total = model.getTotal();
	}
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
			Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = 18;
	titlefont = generator.generateFont(parameter);
	
	for(int i = 0; i < graph.length; i++) {
		graph[i].setDestination(0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, new int[0]);
	}
}
 
Example #22
Source File: LaneRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public LaneRenderer(BMSPlayer main, BMSModel model) {

		this.main = main;
		Pixmap hp = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		hp.drawPixel(0, 0, Color.toIntBits(255, 255, 255, 255));
		blank = new TextureRegion(new Texture(hp));
		hp.dispose();

		FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
				Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
		FreeTypeFontParameter parameter = new FreeTypeFontParameter();
		parameter.size = 18;
		font = generator.generateFont(parameter);
		generator.dispose();

		this.skin = (PlaySkin) main.getSkin();
		this.conf = main.main.getPlayerResource().getConfig();
		this.config = main.main.getPlayerResource().getPlayerConfig();
		this.playconfig = config.getPlayConfig(model.getMode()).getPlayconfig().clone();

		init(model);

		for (CourseData.CourseDataConstraint i : main.main.getPlayerResource().getConstraint()) {
			if (i == NO_SPEED) {
				playconfig.setHispeed(1.0f);
				playconfig.setLanecover(0);
				playconfig.setLift(0);
				playconfig.setHidden(0);
			}
		}
	}
 
Example #23
Source File: MessageRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void init(FreeTypeFontGenerator generator) {
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = 24;
	parameter.characters += text;
	font = generator.generateFont(parameter);
	font.setColor(color);
}
 
Example #24
Source File: MessageRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public MessageRenderer() {
	try {
		generator = new FreeTypeFontGenerator(Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));				
	} catch (GdxRuntimeException e) {
		Logger.getGlobal().severe("Message Font読み込み失敗");
	}
}
 
Example #25
Source File: Utility.java    From Norii with Apache License 2.0 5 votes vote down vote up
public static LabelStyle createLabelStyle(final String fontPath, final int size, final int borderWidth, final Color color, final int shadowX, final int shadowY) {
	final FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(fontPath));
	final FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
	parameter.size = size;
	parameter.borderWidth = borderWidth;
	parameter.color = color;
	parameter.shadowOffsetX = shadowX;
	parameter.shadowOffsetY = shadowY;
	final BitmapFont font = generator.generateFont(parameter);
	final LabelStyle labelStyle = new LabelStyle();
	labelStyle.font = font;
	return labelStyle;
}
 
Example #26
Source File: Utility.java    From Norii with Apache License 2.0 5 votes vote down vote up
public static void loadFreeTypeFontAsset(final String fontName, final int size) {
	if (checkValidString(fontName)) {
		assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(filePathResolver));
		assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(filePathResolver));

		final FreeTypeFontLoaderParameter myFont = new FreeTypeFontLoaderParameter();
		myFont.fontFileName = fontName;
		myFont.fontParameters.size = size;
		myFont.fontParameters.borderWidth = 0.5f;
		myFont.fontParameters.color = Color.LIGHT_GRAY;
		myFont.fontParameters.shadowOffsetX = 2;
		myFont.fontParameters.shadowOffsetY = 2;
		assetManager.load(fontName, BitmapFont.class, myFont);
	}
}
 
Example #27
Source File: AssetsManager.java    From martianrun with Apache License 2.0 4 votes vote down vote up
public static void loadAssets() {

        // Background
        texturesMap.put(Constants.BACKGROUND_ASSETS_ID,
                new TextureRegion(new Texture(Gdx.files.internal(Constants.BACKGROUND_IMAGE_PATH))));

        // Ground
        texturesMap.put(Constants.GROUND_ASSETS_ID,
                new TextureRegion(new Texture(Gdx.files.internal(Constants.GROUND_IMAGE_PATH))));

        textureAtlas = new TextureAtlas(Constants.SPRITES_ATLAS_PATH);

        // Runner
        texturesMap.put(Constants.RUNNER_JUMPING_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_JUMPING_REGION_NAME));
        texturesMap.put(Constants.RUNNER_DODGING_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_DODGING_REGION_NAME));
        texturesMap.put(Constants.RUNNER_HIT_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_HIT_REGION_NAME));
        animationsMap.put(Constants.RUNNER_RUNNING_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNER_RUNNING_REGION_NAMES));

        // Enemies
        animationsMap.put(Constants.RUNNING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_SMALL_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_BIG_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_BIG_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_LONG_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_LONG_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_WIDE_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.FLYING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.FLYING_SMALL_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.FLYING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.FLYING_WIDE_ENEMY_REGION_NAMES));

        // Tutorial
        texturesMap.put(Constants.TUTORIAL_LEFT_REGION_NAME,
                textureAtlas.findRegion(Constants.TUTORIAL_LEFT_REGION_NAME));
        texturesMap.put(Constants.TUTORIAL_RIGHT_REGION_NAME,
                textureAtlas.findRegion(Constants.TUTORIAL_RIGHT_REGION_NAME));

        // Fonts
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(Constants.FONT_NAME));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 36;
        smallFont = generator.generateFont(parameter);
        smallFont.setColor(.21f, .22f, .21f, 1f);
        parameter.size = 72;
        largeFont = generator.generateFont(parameter);
        largeFont.setColor(.21f, .22f, .21f, 1f);
        parameter.size = 24;
        smallestFont = generator.generateFont(parameter);
        smallestFont.setColor(.21f, .22f, .21f, 1f);
        generator.dispose();

    }
 
Example #28
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void loadFont(String filename, String alias) throws IOException {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(filename));        
    this.generators.put(alias, generator);        
}
 
Example #29
Source File: Main.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Setup & load the main menu.
 */
public void create() {
  // Debug shit
  debug = new Debug();

  // Load custom font
  assets = new AssetManager();
  FreeTypeFontGenerator generator =
      new FreeTypeFontGenerator(Gdx.files.internal("ui/Aller_Rg.ttf"));
  FreeTypeFontGenerator.FreeTypeFontParameter parameter =
      new FreeTypeFontGenerator.FreeTypeFontParameter();
  parameter.size = 12;
  BitmapFont font = generator.generateFont(parameter);
  generator.dispose();

  // Create UI skin
  skin = new Skin();
  skin.add("Aller", font, BitmapFont.class);
  skin.addRegions(new TextureAtlas(Gdx.files.internal("ui/uiskin.atlas")));
  skin.load(Gdx.files.internal("ui/uiskin.json"));
  skin.getFont("default-font").getData().markupEnabled = true;

  // Setup text colors
  Colors.put("LIGHT_GRAY", parseColor("c2c2c2"));
  Colors.put("DARK_GRAY", parseColor("666666"));
  Colors.put("CYAN", parseColor("67C8CF"));
  Colors.put("RED", parseColor("D67474"));
  Colors.put("YELLOW", parseColor("E0DFB1"));
  Colors.put("GREEN", parseColor("67CF8B"));

  // Environment colors
  Colors.put("forestFloor", parseColor("78AD8A"));
  Colors.put("forestFloorWet", parseColor("70BBAD"));
  Colors.put("forestTree-1", parseColor("67CF8B"));
  Colors.put("forestTree-2", parseColor("77E09B"));
  Colors.put("forestTree-3", parseColor("4AC775"));

  Colors.put("caveFloor-1", parseColor("7A7971"));
  Colors.put("caveFloor-2", parseColor("8C8B82"));
  Colors.put("caveFloor-3", parseColor("696862"));
  Colors.put("caveFloorWet", parseColor("71A48E"));
  Colors.put("caveWall", parseColor("66655C"));

  Colors.put("waterShallowLightBlue", parseColor("67C8CF"));
  Colors.put("waterShallowDarkBlue", parseColor("139EA8"));
  Colors.put("waterDeepLightBlue", parseColor("139EA8"));
  Colors.put("waterDeepDarkBlue", parseColor("0B7880"));

  Colors.put("waterShallowLightGreen", parseColor("67CFAB"));
  Colors.put("waterShallowDarkGreen", parseColor("13A88F"));
  Colors.put("waterDeepLightGreen", parseColor("13A88F"));
  Colors.put("waterDeepDarkGreen", parseColor("0B8074"));

  Colors.put("fire-1", parseColor("ED6161"));
  Colors.put("fire-2", parseColor("EDBE61"));
  Colors.put("fire-3", parseColor("ED9661"));

  // Decoration colors
  Colors.put("stone", Colors.get("LIGHT_GRAY"));
  Colors.put("bridge", parseColor("969482"));

  // Background colors
  Colors.put("screenBackground", parseColor("293033"));
  Colors.put("forestBackground", parseColor("29332F"));
  Colors.put("caveBackground", parseColor("293033"));

  // Tween manager
  tweenManager = new TweenManager();
  Tween.setCombinedAttributesLimit(4);
  Tween.registerAccessor(Sprite.class, new SpriteAccessor());

  // Cameras
  handheldCamera = new HandheldCamera();
  cameraShake = new CameraShake();

  // Start the main menu
  setScreen(new LoadingScreen(this));
}