我试图在游戏中创建某种类型的“项目显示器”,以展示项目或在库存中充当图标(它将包括项目层、项目名称、exc等信息)。
为了实现这一点,我想要创建一个扩展ItemDisplay的FlxSpriteGroup类,并将项目的框架、背景和信息作为Sprites放入其中,这样我就可以像处理单个Sprite那样处理所有这些项目。
所以我就这样做了,但是当ItemDisplay对象被创建并被认为是add编辑到FlxState时,这个组并没有出现。
经过一些故障排除后,我发现对象exists,但是isOnScreen()返回false,我不知道为什么。
下面是我用来创建ItemDisplay对象的代码:
var itd:ItemDisplay = new ItemDisplay(FlxG.width / 2, FlxG.height / 2, test_sword);
add(itd);...and,这是ItemDisplay类的所有荣耀:
class ItemDisplay extends FlxSpriteGroup
{
override public function new(posX:Float, posY:Float, itemToShow:Item)
{
super();
x = posX;
y = posY;
// create sprites
var bckgr:FlxSprite = new FlxSprite(x, y);
var itPng:FlxSprite = new FlxSprite(x, y);
var itFrm:FlxSprite = new FlxSprite(x, y);
// load sprites graphics (problem's not here, i checked)
bckgr.loadGraphic("assets/images/ui/item_framing/ifbg_" + itemToShow.tier + "Tier.png");
itPng.loadGraphic(itemToShow.pngPath);
itFrm.loadGraphic("assets/images/ui/item_framing/item_frame.png");
// add all sprites to group
this.add(bckgr);
this.add(itPng);
this.add(itFrm);
}
}(我在macos上运行代码,而不是HTML5)
如果你知道为什么ItemDisplay没有出现,请向我解释,因为我不是一个好的程序员,我可能错过了什么。谢谢^-^
发布于 2022-03-11 15:47:45
正如我所想的,Nvm是我愚蠢的错误:在创建第10-12行中的精灵时,我将它们的位置设置为X和Y,以使它们与组位置相同。
我刚刚发现,精灵把群的x和y当作(0,0),然后从那里开始计算它们的位置。
因此,通过将sprites的x/y设置为组的x/y,我实际上是将值加倍,并将sprites放到屏幕外
伊莫为糟糕的英语道歉
https://stackoverflow.com/questions/71440096
复制相似问题