Starling library - Sprite dissapeared from stage and I don't know why

匆匆过客 提交于 2019-12-24 21:44:47

问题


The code for the question is here - I am using Flash Builder 4.7, I will also post all the relevant code now:

Game.as (might be something wrong here)

package
{
import Classes.AvatarEnemy;

//import starling.animation.Juggler;
//import starling.core.Starling;
import starling.display.Sprite;

import flash.geom.Point;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.ui.Mouse;
import flash.ui.MouseCursorData;

    public class Game extends Sprite
    {
        //private var juggler:Juggler = Starling.juggler;

        [Embed(source="Classes/Avatarpic.png")]
        private const Cursor:Class;

        public var enemy:AvatarEnemy;

        public function Game() 
        {   
            enemy = new AvatarEnemy();
            addChild(enemy);

            //var counter:int;

            /*juggler.delayCall(function():void {

                if(enemy.hitTest(cursor_D.hotSpot, true)) {
                    var score:int = counter;
                    trace(score);
                };

                counter++;
            }, 1.0);*/

            function createCustomCursor():void
            {
                var cursorBitmaps:Vector.<BitmapData> = new Vector.<BitmapData>();
                cursorBitmaps.push((new Cursor() as Bitmap).bitmapData);

                var mouseCursorData:MouseCursorData = new MouseCursorData();
                mouseCursorData.data        = cursorBitmaps;
                mouseCursorData.frameRate   = 30;
                mouseCursorData.hotSpot     = new Point(0, 0);

                Mouse.registerCursor("customCursor", mouseCursorData);
                Mouse.cursor = "customCursor";
            }

            createCustomCursor();
        }
    }
}

Startup.as (shouldn't be anything wrong here)

package
{
    import flash.display.Sprite;
    import starling.core.Starling;
    import Game;

    [SWF(width="400", height="300", frameRate="60", backgroundColor="#ffffff")]
    public class Startup extends Sprite
    {
        private var _starling:Starling;

        public function Startup()
        {
            _starling = new Starling(Game, stage);
            _starling.start();
        }
    }
}

AvatarEnemy.as (might be something wrong here)

package Classes
{

    import starling.display.Image;
    import starling.display.Sprite;
    import starling.textures.Texture;

    public class AvatarEnemy extends Sprite
    {
        [Embed(source='Enemypic.png')]
        private static var Enemypic:Class;

        private var texture:Texture = Texture.fromBitmap(new Enemypic());

        private var image:Image = new Image(texture);

        public function AvatarEnemy() 
        {                   
            image.x = 0;
            image.y = 200;

            addChild(image);            
        }
    }
}

All of the code at the end of Game.as is me trying to make the cursor a certain image - I also need help with that too. But right now - the enemy object isn't being added to the stage for some reason, despite the fact that I use addChild(enemy). Anyone know why? Thanks.

来源:https://stackoverflow.com/questions/23772083/starling-library-sprite-dissapeared-from-stage-and-i-dont-know-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!