0

raphael.js で作成したこの単純なプロジェクトを backbone.js を使用するように変換しようとしていますが、同じエラーが発生し続け、その理由がわかりません。私のモデルの関数で、「this」を使用して変数にアクセスしようとしましたが、たとえば配列で「未定義のプロパティ「長さ」を読み取れません」というエラーが引き続き発生します。私のモデルは次のようになります。

GameModel = Backbone.Model.extend({
        defaults: {

            spawnId: '',
            gameloopId: '',
            checkId: '',
            goingUp: false,
            counter: 0,     
            recentscores: [],
            enemies: '',
            speed: -4,
            score: 0,
            health: 100,
            paper: '',
            t: '',
            h: '',
            c: '',
            circle: ''

        },
        initialize: function(){

            this.enemies = [];
            this.paper = new Raphael($('#canvas'), 0, 0);
            this.circle = this.paper.circle(100, 50, 30);
            this.t = this.paper.text(1000, 50, "Score: " + this.score);
            this.h = this.paper.text(50, 50, "Health: " + this.health);
            this.c = this.paper.image("background.png", 0, 0, 2400, 800);
            this.paper.setSize(1200,800);
            this.circle.attr({fill: '#9cf', stroke: '#ddd', 'stroke-width': 5});
            this.t.attr({ "font-size": 20, "font-family": "Arial, Helvetica, sans-serif" });
            this.h.attr({ "font-size": 20, "font-family": "Arial, Helvetica, sans-serif" });
        },
4

1 に答える 1

0

これをする:

this.enemies = [];

使ってみるといいかもしれません

this.set("enemies", [])

this.circle = this.paper.circle(100, 50, 30);

this.set("circle", this.get("paper").circle(100, 50, 30))

于 2013-05-07T02:40:05.387 に答える