2017-01-11 6 views
0

を拡張キノコと呼ばれる:は、私が<a href="https://github.com/lean/phaser-es6-webpack" rel="nofollow noreferrer">this Es6 Phaser boilerplate</a>を使用していて、そこでは、Phaser.Sprite拡張子がありますPhaser.Textクラス

import Phaser from 'phaser' 

export default class extends Phaser.Sprite { 

    constructor ({ game, x, y, asset }) { 
    super(game, x, y, asset) 

    this.game = game 
    this.anchor.setTo(0.5) 
    }  
    update() { 
    this.angle += 1 
    }  
} 

だから私はこのようなPhaser.Textクラスでこれを複製しようとした:

import Phaser from 'phaser'  

export default class extends Phaser.Text { 
    constructor({game, x, y, text, style}){ 
    super(game, x, y, text, style) 

    this.game = game 
    this.anchor.setTo(0.5) 

    }  
} 

してからちょうど例のように、Game.jsファイルにそれを呼んだ:

this.texto = new Texto({ 
     game: this, 
     x: 0, 
     y:0, 
     text:"hola mundo" 
    }) 

    this.game.add.existing(this.texto) 

が、T結果は次のようになります。

Uncaught TypeError: Cannot read property 'resolution' of undefined

正しくPhaser.Textを拡張するか、再利用可能なクラスを作成するにはどうすればよいですか?

私は間違っていますか?

ありがとうございます!

+0

を変更してみたらどう

あなたがエラーがテキストオブジェクトで発生していますか?解像度はテキストのプロパティですが、問題はどこかにTextオブジェクトが存在しないようです –

答えて

1

実際のゲームオブジェクトを拡張クラスに渡していますか?あなたは

this.texto = new Texto({ 
    game: this.game, 
    x: 0, 
    y:0, 
    text:"hola mundo" 
}) 

this.game.add.existing(this.texto) 
関連する問題

 関連する問題