1 decade ago by zimett
There is probably a very simple answer to this, but I'm teaching myself some game programming and have hit my first real speed bump.
In my main.js file I'm creating a Stats Screen that shows how long you've been playing and how many mouse clicks you've made.
Here is my Stat Screen code in the Draw function of main.js. It works fine if I comment out the line tracking 'Clicks' - the offending piece of code is definitely 'EntityMonster.clicks'
If I leave 'EntityMoster.clicks' in the code the stat screen opens and immediately closes when called and doesn't show anything after the Time Played.
Here is my EntityMonster code:
Basically, I want to increment the clicks by 1 whenever the player clicks the monster, and be able to call that property in the stats screen. I'm guessing I've made a really rookie scope mistake somewhere, but I can't figure out what I need to do after an hours worth of forum searching.
Any help would be really appreciated!
In my main.js file I'm creating a Stats Screen that shows how long you've been playing and how many mouse clicks you've made.
Here is my Stat Screen code in the Draw function of main.js. It works fine if I comment out the line tracking 'Clicks' - the offending piece of code is definitely 'EntityMonster.clicks'
if(this.showStats){ this.statMatte.draw(0,0); var x = ig.system.width / 2; var y = ig.system.height/2 - 20; this.statText.draw('Level Complete', x,y,ig.Font.ALIGN.CENTER); this.statText.draw('Time Played: ' + Math.floor(this.stats.time), x, y+30, ig.Font.ALIGN.CENTER); this.statText.draw('Clicks: ' + EntityMonster.clicks, x, y+40, ig.Font.ALIGN.CENTER); this.statText.draw('Press TAB to continue.', x, y+50, ig.Font.ALIGN.CENTER); }
If I leave 'EntityMoster.clicks' in the code the stat screen opens and immediately closes when called and doesn't show anything after the Time Played.
Here is my EntityMonster code:
animSheet: new ig.AnimationSheet('media/monster.png', 100, 129), size: {x:100, y:129}, offset: {x:0, y:0}, clicks: 0, init: function(x, y, settings){ this.parent(x, y, settings); this.addAnim('idle', 1, [1]); this.addAnim('clicked', 1, [0]); }, update: function (){ if (ig.input.state('leftButton') && this.inFocus()) { this.currentAnim = this.anims.clicked; } else{ this.currentAnim = this.anims.idle; } if (ig.input.pressed('leftButton') && this.inFocus()) { this.clicks++; } this.parent(); }, inFocus: function() { return ( (this.pos.x <= (ig.input.mouse.x + ig.game.screen.x)) && ((ig.input.mouse.x + ig.game.screen.x) <= this.pos.x + this.size.x) && (this.pos.y <= (ig.input.mouse.y + ig.game.screen.y)) && ((ig.input.mouse.y + ig.game.screen.y) <= this.pos.y + this.size.y) ); }
Basically, I want to increment the clicks by 1 whenever the player clicks the monster, and be able to call that property in the stats screen. I'm guessing I've made a really rookie scope mistake somewhere, but I can't figure out what I need to do after an hours worth of forum searching.
Any help would be really appreciated!