类未定义?

时间:2018-04-20 19:20:51

标签: javascript ecmascript-6

对于上下文,我正在使用Phaser框架开发游戏。但是,这个问题通常适用于Javascript。

我已经通过函数构造函数在main.js文件中定义了以下类:

function AchievementsMenu() {

    this.lastY = 43 * c.length 
}

然而,在制作原型AchievementsMenu.prototype = Object.create( Phaser.Group.prototype );时,我收到错误:'未捕获的ReferenceError:未定义成就菜单'。

据我所知,我只创建了一个定义对象的函数类,而不实际创建它的实例。但是,我不需要创建原型方法,对吧?

非常感谢任何帮助!

修改

import 'pixi'
import 'p2'
import Phaser from 'phaser'

import * as AM from './managers/AchievementManager.js'
import * as HG from './managers/hgManager.js'
import * as DM from './managers/dataManager.js'

//Configs for initializing Phaser framework
var cfg = {
        width: 1334,
        height: 750,
        renderer: Phaser.WEBGL,
        parent: "gameDiv",
        enableDebug: !1,
        transparent: !1,
        antialias: !1
    },

    game = new Phaser.Game(cfg);

game.achievementManager = new AM.AchievementManager( game );
game.hgManager = new HG.HGManager();
game.dataManager = new DM.DataManager( game );

//A decent chunk of the class
function AchievementsMenu() {
    Phaser.Group.call(this, game);

    var a = game.add.image(0, 0, "MainUI", "Achievements/Achievements_TextBG_Disabled.png");
    a.anchor.setTo(.5),
    a.scale.setTo(200),
    a.alpha = .4,
    a.tint = 0,
    a.inputEnabled = !0,
    a.events.onInputUp.add(this.onPressBG, this),
    this.add(a);


    var b = game.add.image(0, 0, "MainUI", "Achievements/Achievements_BG.png");
    b.inputEnabled = !0,
    b.events.onInputDown.add(this.onStartDrag, this),
    b.events.onInputUp.add(this.onEndDrag, this),
    this.add(b),

    this.add(this.game.add.bitmapText(15, 2, "Omnes", "Achievements", 28)),
    this.scrollableContent = game.add.group(),
    this.add(this.scrollableContent);

    for (var c = this.game.constants.achievements, d = this.game.playerData.achievements, e = 0; e < c.length; e++) {
        var f = 80 * e + 35;

        if (d.indexOf(e) == -1){
            this.game.add.image(10, f, "MainUI", "Achievements/Achievements_TextBG_Disabled.png", this.scrollableContent),
            this.game.add.image(15, f + 4, "MainUI", "Achievements/Achievements_Icon_Locked.png", this.scrollableContent);
        }

        else {
            this.game.add.image(10, f, "MainUI", "Achievements/Achievements_TextBG_Enabled.png", this.scrollableContent),
            this.game.add.image(15, f + 4, "MainUI", "Achievements/Achievements_Icon_0" + e + ".png", this.scrollableContent);
            var g = this.game.add.bitmapText(450, f + 25, "Omnes", "Completed", 20, this.scrollableContent);
            g.tint = 7454787
        }

        this.game.add.bitmapText(75, f + 10, "Omnes", c[e].name, 25, this.scrollableContent),
        this.game.add.bitmapText(75, f + 35, "Omnes", c[e].description, 20, this.scrollableContent)
    }

    this.lastY = 43 * c.length; 
}

AchievementsMenu.prototype = Object.create( Phaser.Group.prototype );

AchievementsMenu.prototype.onPressBG = function() {
    this.visible = !1
};

0 个答案:

没有答案