【问题标题】:Why is this label not showing in HaxePunk?为什么这个标签没有在 HaxePunk 中显示?
【发布时间】:2014-01-25 23:08:38
【问题描述】:

我开始学习 HaxePunk,我已经浏览了他们网站上的基本教程。所以现在我试图找出如何在屏幕上添加某种标签。我注意到似乎是他们唯一的开箱即用的名为“Label”的类看起来只是一个调试工具,而不是你在生产中真正想要的东西,所以我搜索并找到了这个关于在 FlashPunk 中制作标签的链接: http://flashgamedojo.com/wiki/index.php?title=Text_%28FlashPunk%29

本质上,它只是将一个非常基本的 Text 对象分配给实体的图形属性。现在这是我的代码,它是从教程代码中分离出来的:

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;
    }   
}

我没有看到任何添加到屏幕上。但是,当我尝试取消注释 GameScene.hx 中关于添加新块的行时,我能够看到添加了一个块:

块.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();
    }
}

Disclaimer.hx 有什么问题?谢谢。

【问题讨论】:

    标签: user-interface flash graphics haxe haxepunk


    【解决方案1】:

    该代码似乎对我有用

    我正在使用 openfl 版本 1.2.1 和 haxepunk 2.4.5 以及使用 haxelib run haxepunk new test 创建的新项目

    我在 html5、flash 和 neko 中尝试过,它们都适用。

    试试看问题是不是和openfl/haxepunk的版本有关,可能是已经修复的bug

    【讨论】:

      【解决方案2】:

      我假设您也已在 GameScene.hx 中导入了该类?通过添加:

      import entities.Disclaimer;
      

      在您的GameScene 定义之上?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多