2015-11-07 2 views
0

J'ai un problème lors de la création d'une image-objet à partir de BitmapData. Lorsque j'ai une forme rectangulaire, l'image-objet est créée sans problème, mais lorsque bitmapData est juste une ligne, l'image-objet est juste vide.Sprite à partir de la ligne BitmapData

bmd = this.game.add.bitmapData(this.line.width, this.line.height); 
 

 
//This works fine: 
 
bmd.ctx.rect(0, 0, 32, 32); 
 
bmd.ctx.fillStyle = "#0f0"; 
 
bmd.ctx.fill(); 
 
var platform = this.game.add.sprite(this.line.midPoint().x, this.line.midPoint().y, bmd); 
 

 
//This doesn't work 
 
bmd.ctx.this.lineWidth = "8"; 
 
bmd.ctx.strokeStyle = 'white'; 
 
bmd.ctx.moveTo(this.startPoint.x, this.startPoint.y); 
 
bmd.ctx.lineTo(this.endPoint.x, this.endPoint.y); 
 
bmd.ctx.stroke(); 
 
var platform = this.game.add.sprite(this.line.midPoint().x, this.line.midPoint().y, bmd);

est-il un problème de savoir ou dois-je une erreur horrible dans mon code?

Merci pour votre temps

Répondre

0

j'ai trouvé une façon de le faire.

Game.prototype.create = function(){ 
 
    this.bmd = this.game.add.bitmapData(this.game.width-20, this.game.height); 
 
    this.bmd.ctx.beginPath(); 
 
    this.bmd.ctx.lineWidth = "4"; 
 
    this.bmd.ctx.strokeStyle = 'white'; 
 
    this.bmd.ctx.stroke(); 
 
    this.platform = this.game.add.sprite(0, 0, this.bmd); 
 
}; 
 

 
Game.prototype.draw = function(){ 
 
    this.bmd.clear(); 
 
    this.bmd.ctx.beginPath(); 
 
    this.bmd.ctx.moveTo(this.startPoint.x, this.startPoint.y); 
 
    this.bmd.ctx.lineTo(this.endPoint.x , this.endPoint.y); 
 
    this.bmd.ctx.lineWidth = 4; 
 
    this.bmd.ctx.stroke(); 
 
    this.bmd.ctx.closePath(); 
 
    this.bmd.render(); 
 
}

Il se trouve que j'aurais ajouté le sprite une fois et puis juste re-rendre.