Easeljs game project

假如想象 提交于 2019-12-04 06:36:14

问题


I'm working on a game project but I have a a problem i received this error:

NS_ERROR_NOT_AVAILABLE:

ctx.drawImage(this.image, 0, 0); //Bitmap.js in Easeljs lib.

I used the bitmap in the next codes. Please tell me if in this there is a problem and how to fix it. Thanks for collaboration.

Code 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);
}

Code 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);

来源:https://stackoverflow.com/questions/23032689/easeljs-game-project

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