我正在开展一个游戏项目,但我遇到了一个问题,我收到了这个错误:
NS_ERROR_NOT_AVAILABLE:
ctx.drawImage(this.image, 0, 0); //Bitmap.js in Easeljs lib.
我在下一个代码中使用了位图。请告诉我这是否存在问题以及如何解决问题。 感谢您的合作。
代码1 :
p.initialize = function(x,y ,stage, world){
var bmp = new Bitmap('../assets/blackBall.png');
//console.log(bmp)
//alert(bmp)
bmp.regX = radius;
bmp.regY = radius;
bmp.x=x;
bmp.y=y;
this.skin = bmp;
stage.addChild(bmp);
var fixDef = new b2FixtureDef();
fixDef.density = 1.0;
fixDef.friction = 0.5;
fixDef.restitution = 0.8;
fixDef.shape = new b2CircleShape(38*CONST.pixelToMeter);
var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = bmp.x*CONST.pixelToMeter;
bodyDef.position.y = bmp.y*CONST.pixelToMeter;
this.body = world.CreateBody(bodyDef);
this.body.CreateFixture(fixDef);
this.skin.body = this.body;
setUserData(this.body);
/*Event handler*/
this.skin.onMouseOver = handleMouseOver;
this.skin.onMouseOut = handleMouseOut;
this.skin.onPress = handleMouseDown;
//console.log(this.skin);
}
代码2 :
p.initialize = function(stage, world){
var shooterSkin = new Container();
var cirlceSkin = new createjs.Bitmap('../assets/shooter.png');
cirlceSkin.name = "ball";
var arrowSkin = new createjs.Bitmap('../assets/arrow.png');
arrowSkin.name = "arrow";
arrowSkin.rotation = 0;
arrowSkin.scaleX =0;
arrowSkin.regY = arrowHeight;
cirlceSkin.regX = skinRadius;
cirlceSkin.regY = skinRadius;
cirlceSkin.x =0;
cirlceSkin.y = 0;
cirlceSkin.alpha=circleAlpha;
shooterSkin.x=110
shooterSkin.y = 110;
shooterSkin.addChild(cirlceSkin);
shooterSkin.addChild(arrowSkin);
arrowIndex = 1;
this.skin = shooterSkin;
stage.addChild(shooterSkin);
var fixDef = new b2FixtureDef();
fixDef.friction = 0;
fixDef.restitution = 0;
fixDef.isSensor = true;
fixDef.shape = new b2CircleShape(radius*CONST.pixelToMeter);
var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_kineticBody;
bodyDef.position.x = shooterSkin.x*CONST.pixelToMeter;
bodyDef.position.y = shooterSkin.y*CONST.pixelToMeter;
this.body = world.CreateBody(bodyDef);
this.body.CreateFixture(fixDef);
setUserData(this.body);