Why is this label not showing in HaxePunk?

224 views Asked by At

I'm starting to learn HaxePunk, and I've gone through the basic tutorials on their website. So now I was trying to find out how to add a label of some sort onto the screen. I noticed that what appears to be their only out-of-the-box class named "Label" looks like just a debugging tool, not really something you would want in production so I searched and found this link about making a label in FlashPunk: http://flashgamedojo.com/wiki/index.php?title=Text_%28FlashPunk%29

Essentially it's just assigning a very basic Text object to the graphic property of an entity. So here's my code now, which is branced off of tutorial code:

GameScene.hx:

class GameScene extends Scene
{   
    public function new()
    {
        super();
    }

    public override function begin()
    {
        //add(new Block(30, 50));
        //add(new Player(100, 100));
        //add(new Ship(200, 200));
        //spawn();
        add(new Disclaimer(200, 200));
    }

Disclaimer.hx:

package graphics;

import com.haxepunk.Entity;
import com.haxepunk.graphics.Text;

class Disclaimer extends Entity
{
    public function new(x:Float, y:Float) 
    {
        super(x, y);
        var lbl = new Text("This is a disclaimer.");
        //lbl.color = 0xFFFFFF;
        graphic = lbl;
    }   
}

I see nothing added to the screen. When I try to uncomment the line in GameScene.hx about adding a new Block though, I'm able to see a Block get added:

Block.hx:

package entities;

import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.utils.Input;
import com.haxepunk.utils.Key;

class Block extends Entity
{
    public function new(x:Int, y:Int)
    {
        super(x, y);
        graphic = new Image("graphics/block.png");
    }

    public override function update()
    {
        if (Input.check(Key.LEFT))
        {
            moveBy(-2, 0);
        }

        if (Input.check(Key.RIGHT))
        {
            moveBy(2, 0);
        } 
        super.update();
    }
}

What's wrong with Disclaimer.hx? Thanks.

2

There are 2 answers

0
npretto On

That code seems to work for me

I'm using openfl version 1.2.1 and haxepunk 2.4.5 with a new project created with haxelib run haxepunk new test

I tried in html5, flash and neko and it worked in all of them.

Try to see if the problem is related to the versions of openfl/haxepunk it may be a bug that's already been fixed

0
fritzvd On

I assume you have imported the class in GameScene.hx as well? By adding:

import entities.Disclaimer;

above your GameScene definition?