椋鸟不显示图形

时间:2014-03-28 03:59:35

标签: actionscript-3 starling-framework

大家好我是AS3和Starling的新手我在另一个班级显示图像时遇到问题。它确实显示在我的游戏菜单上,但我希望它能在我的游戏类中显示。

所以我得到了3个类Main,它启动了运行GameMenu类的starling。

“GameMenu课程” 包{

import starling.display.BlendMode;
import starling.display.Button;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;

public class GameMenu extends Sprite {

    private var bg:Image;
    private var gameLogo:Image;
    private var playBtn:Button;
    private var rankBtn:Button;
    private var settingBtn:Button;

    private var inGame:PlayGame;


    public function GameMenu ()
    {
        super ();

        this.addEventListener (Event.ADDED_TO_STAGE, onAddedToStage);
    }

    private function onAddedToStage (event:Event):void
    {
        this.removeEventListener (Event.ADDED_TO_STAGE, onAddedToStage);

        drawScreen ();
    }

    private function drawScreen ():void
    {
        bg = new Image(Assets.getAtlas().getTexture(("Background.png")));
        bg.blendMode = BlendMode.NONE;
        this.addChild(bg);

        gameLogo = new Image(Assets.getAtlas().getTexture(("GameLogo.png")));
        gameLogo.x = stage.stageWidth/2 - gameLogo.width/2;
        gameLogo.y = 30;
        this.addChild(gameLogo);

        playBtn = new Button(Assets.getAtlas().getTexture("PlayBtn.png"));
        playBtn.x = stage.stageWidth/2 - playBtn.width/2;
        playBtn.y = 450;
        playBtn.addEventListener(Event.TRIGGERED, onPlayClick);
        this.addChild(playBtn);

        rankBtn = new Button(Assets.getAtlas().getTexture("RankBtn.png"));
        rankBtn.x = rankBtn.bounds.left + 60;
        rankBtn.y = 600;
        rankBtn.addEventListener(Event.TRIGGERED, onRankClick);
        this.addChild(rankBtn);

        settingBtn = new Button(Assets.getAtlas().getTexture("SettingBtn.png"));
        settingBtn.x = settingBtn.bounds.right + 60;
        settingBtn.y = 600;
        settingBtn.addEventListener(Event.TRIGGERED, onSettingClick);
        this.addChild(settingBtn);

    }

    private function onRankClick (event:Event):void
    {
        trace("LEADERBOARD BUTTON HIT")
    }

    private function onSettingClick (event:Event):void
    {
        trace("SETTING SCREEN BUTTON HIT")
    }

    private function onPlayClick (event:Event):void
    {
        playBtn.removeEventListener(Event.TRIGGERED, onPlayClick);
        trace("PLAY BUTTON HIT")

        gameLogo.visible = false;
        playBtn.visible = false;
        rankBtn.visible = false;
        settingBtn.visible = false;
        //bg.visible = false;
        inGame = new PlayGame();
    }


}

}

这门课现在完美无缺。

“PlayGame class”

包{

import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;

public class PlayGame extends Sprite
{
    private var bubble:Image;

    public function PlayGame ()
    {
        trace("PlayGame");
        super ();

        this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage2);
    }

    private function onAddedToStage2 (event:Event):void
    {
        trace("OnAddedToStage");
        this.removeEventListener (Event.ADDED_TO_STAGE, onAddedToStage2);

        drawScreen ();
    }

    public function drawScreen ():void
    {
         trace("Bubble");
         bubble = new Image(Assets.getAtlas().getTexture(("Bubble.png")));
         bubble.x = 100;
         bubble.y = 100;
         this.addChild(bubble);
    }


}

}

气泡图像现在显示,我不知道为什么?

1 个答案:

答案 0 :(得分:0)

它们括号太多,但这不是你的问题

bubble = new Image(Assets.getAtlas().getTexture(("Bubble.png")));
//is less clean/readable than
bubble = new Image(Assets.getAtlas().getTexture("Bubble.png"));

当遇到这类问题时,如果starling / air没有报告任何错误,您应该尝试确保当前呈现显示对象。

尝试应用颜色而不是纹理。

bubble = new Image( Texture.fromColor(64,64,0xff99ff) );

如果此代码显示64像素/边的花式矩形,则您的纹理图集或纹理会出现问题。一定要有一个有图册的地图集,验证框架和名称。

如果此代码未显示facy矩形,则问题不是来自纹理图集或纹理,而是更多可能来自starling的显示列表。

在你的情况下, 我想你应该只需要在GameMenu类中添加Ingame Ingame:

GameMenu:

private function onPlayClick (event:Event):void
{
    //... your stuff
    inGame = new PlayGame();

    this.parent.addChild(inGame);
}

它应该有效。