我非常假想在as3中使用starling库进行游戏,其示例代码创建的游戏工作正常,但无法添加简单的png图像作为英雄/敌人:(我的代码如下...
public class radixState extends StarlingState
{
[Embed(source = "giants.png")]
private var giantsPic:Class;
[Embed(source = "ring.png")]
private var ringPic:Class;
[Embed(source = "tigers.png")]
private var tigersPic:Class;
public function radixState()
{
super();
}
override public function initialize():void {
super.initialize();
/*var imgBitmap:BitmapAsset = new giantsPic();
var bitmapData:BitmapData = imgBitmap.bitmapData;*/
var mygiants:Image = new Image(Texture.fromBitmapData(new giantsPic().bitmapData));
mygiants.height=70;
mygiants.width=70;
var physics:Box2D = new Box2D("box2D");
physics.visible = true;
add(physics);
var floor:Platform=new Platform("floor",{x:512, y:748, width:1024, height:40});
floor.view=new Quad(1024,40,0x333333);
add(floor);
var p1:Platform=new Platform("p1",{x:871, y:151, width:300, height:40});
p1.view=new Quad(300,40,0x333333);
add(p1);
var mp:MovingPlatform=new MovingPlatform("moving",{x:220, y:700, width:200, height:40, startX:220, startY:700, endX:500, endY:151});
mp.view=new Quad(200,40,0x333333);
add(mp);
var hero:Hero=new Hero("hero",{x:50, y:50, width:70, height:70});
hero.view=mygiants;
add(hero);
var enemy:Enemy=new Enemy("enemy",{x:900, y:700, width:70, height:70, leftBound:10, rightBound:1000});
enemy.view=new tigersPic();
add(enemy);
var goal:Coin=new Coin("ring",{x:957, y:90, width:79, height:79});
goal.onBeginContact.add(function(c:b2Contact):void{
trace("Goal Raeched");
});
goal.view=new ringPic();
add(goal)
}
}
任何人都可以帮助我只想添加图像作为英雄/敌人
答案 0 :(得分:0)
您正在向StarlingState添加CitrusObjects,同时显示您必须添加(addChild)DisplayObject到starling sprite的内容