我正试图在Starling中设置assetManager。但是我得到了运行时错误:
纹理不能为空 starling.display ::图片()[C:\拉斯\八哥\八哥\ SRC \八哥\显示\ Image.as:70] 在Game()[C:\ lars \ onkel_reje_air_3 \ src \ Game.as:41] at starling.core ::斯塔林/ initializeRoot()[C:\拉斯\八哥\八哥\ SRC \八哥\核心\ Starling.as:338] 在 starling.core ::斯塔林/初始化()[C:\拉斯\八哥\八哥\ SRC \八哥\核心\ Starling.as:314] 在 starling.core ::斯塔林/ onContextCreated()[C:\拉斯\八哥\八哥\ SRC \八哥\核心\ Starling.as:519]
我有以下EmbeddedAssets.as:
package
{
import starling.display.Image;
import starling.textures.Texture;
/**
* ...
* @author Lars Gregersen
*/
public class EmbeddedAssets
{
[Embed(source="assets/bord.jpg")]
public static const bord:Class;
}
}
在我的game.as中:
package
{
import starling.display.Sprite;
import starling.display.MovieClip;
import starling.display.Image;
import starling.events.Event;
import starling.text.TextField;
import starling.textures.Texture;
import starling.utils.AssetManager;
/**
* ...
* @author Lars Gregersen
*/
public class Game extends Sprite
{
public var assets:AssetManager = new AssetManager();
public function Game(){
assets.verbose = true;
assets.enqueue(EmbeddedAssets);
var backgroundImage:Image = new Image(assets.getTexture("bord"));
addChild(backgroundImage);
assets.loadQueue(function(ratio:Number):void{
trace("Loading assets, progress:", ratio);
if (ratio == 1.0)
});
}//end constructor
}//end class
}//end package
我的Main.as:
package
{
//import flash.desktop.NativeApplication;
import flash.events.Event;
import flash.display.Sprite;
import starling.core.Starling;
/**
* ...
* @author Lars Gregersen
*/
public class Main extends Sprite
{
private var _starling:Starling;
public function Main():void
{
_starling = new Starling(Game, stage);
_starling.showStats = true;
_starling.start();
}
}
}
我的资源文件夹和.as文件位于同一文件夹(src)中。使用Flashdevelop。它应该很简单但是......
答案 0 :(得分:3)
这是因为你称之为方法' getTexture'太早了。仅在加载资产时调用此方法。
public function Game(){
assets.verbose = true;
assets.enqueue(EmbeddedAssets);
assets.loadQueue(function(ratio:Number):void{
trace("Loading assets, progress:", ratio);
if (ratio == 1.0)
{
var backgroundImage:Image = new Image(assets.getTexture("bord"));
addChild(backgroundImage);
}
});
}//end constructor
答案 1 :(得分:0)
我认为你还需要一步,你的资产类应该返回纹理的bitmapdata:
var cls:Class = getDefinitionByName(' bord')作为Class; var bm:BitmapData = new cls(0,0);