vendredi 23 décembre 2016

Text not appearing in FlashDevelop project. But not throwing any errors either

This is my first time using FlashDevelop. I have buttons in a menu and a scoreboard. These all have a text field in them. In Adobe Animate, all worked fine, but in FlashDevelop, I understand I need to embed the fonts using strictly AS3 code, as there is no GUI library to drop them into.

I found this snippet but it only confirms (I think) that I've done it correctly, which obviously, I have not.

So here is my current permutation that does not throw any errors, and the game loads and runs fine (but there is no text anywhere) and the buttons work, but there is not text anywhere:

public class Main extends Sprite 

// ********** EMBEDDED ASSESTS **       
    [Embed(source = "/../lib/FATPIXEL.TTF", fontName = "fatPixel")] public static var myFatPixels:Class;

and then while creating a menu button:

// ********* BUTTONS **********
    private var button1:RoundButton= new RoundButton(60,30,gameReset,0xff386c,0x0,"1 Player");

Those are both in my main doc class. The following includes the constructor in my button class as well as the property declaration part inside the package:

    [Embed(source = "/../lib/AtariSmall.ttf", fontName = "smallAtari")] public var myAtariFont:Class;       
    public var tF:TextField = new TextField();
    private var myAtariFormat:TextFormat = new TextFormat(myFatPixels.fontName,25,0x00ffff);        

    var b:Sprite = new Sprite;
    var txt:String = new String();

    public function RoundButton(w:Number,h:Number,f:Function,colorA:uint,colorB:uint = 0x555599,text:String="button",dat2:Boolean = false):void {
        tF.text = text;
        tF.embedFonts = true;
        tF.defaultTextFormat = myAtariFormat;

Oh, and my .ttf files are here:

enter image description here

Can anyone see what is causing my problem? In Adobe Animate embedding was made simpler by having that option in a drop-down menu and having GUI access to the library. The syntax was notably different in that I was able to use the Font class whereas all sources I've found online show me to use the Class class? Here's what I mean:

Adobe Animate

var myFatPixels:Font = new FatPixels();


var myFatPixels:Class;

I think if I understood better the difference between these two lines of code I could figure out what I'm doing wrong.

So, I made a simple script to just at least try to get some text to show up. It works, but the font look like Times New Roman or some other system font, and not the font that it is supposed to look like. Here's my code that does this:

    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.text.*;

     * ...
     * @author Neal Davis

    public class Main extends Sprite 
        [Embed(source = "../lib/FATPIXEL.TTF", fontName = "fatPixel")] public static var myFatPixels:Class;
        private var tF:TextField = new TextField();
        private var myFont:Font = new myFatPixels();
        private var myAtariFormat:TextFormat = new TextFormat(myFatPixels.fontName,25,0xB6A4E3);    

        public function Main() 
            removeEventListener(Event.ADDED_TO_STAGE, init);
            trace("hello world");
            var b:Sprite = new Sprite();
            tF.defaultTextFormat = myAtariFormat;
            tF.text = "button";



The result being


but it should look more like


Aucun commentaire:

Enregistrer un commentaire