LoginSignup
1
0

More than 3 years have passed since last update.

[enchant.js]Scoreを表示するラベルのクラス[JavaScript]

Posted at

Labelクラスを継承したScoreLabelクラスを定義

SCORE:[スコア]
という表示をするLabelを作るScoreLabelクラスを定義

scorelabel.js
//Labelクラスを継承する
ScoreLabel = Class.create(Label, {
    initialize: function(x, y){
        enchant.Label.call(this, "SCORE:0");
        this.x = x;
        this.y = y;
        this.score = 0;
    },
    //ptsだけスコアを加算
    add: function(pts){
        this.score += pts;
        this.text = "SCORE:" + this.score;
    }
});
main.js
scoreLabel = new ScoreLabel(10, 10);
game.rootScene.addChild(scoreLabel);
//スコアに追加
scoreLabel.add(1);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0