Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Skwiddy

Hi again,

n00b question. I am coding a breakout clone as a programming test and I've got quite far but I am struggling with updating the players score.

I declare my score variable in main.js and then have the following:
<code>
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
this.font.draw( this.score.floor().toString(), ig.system.width -50, 50, ig.Font.ALIGN.RIGHT );
}
</code>
which seems to work fine. I increment score in my Tile entity like this:
<code>
hitTile: function() {
this.score += 1;
this.kill();
}
</code>
but the score isn't updating. Does the Tile entity know what 'score' is? Is there a better way of doing it?

1 decade ago by auz1111

I believe instead of
this.score+=1;

You want to have
ig.game.score+=1;

Classes outside the main can't access the score variable with 'this.score'.

1 decade ago by GHETTOCHiLD

if the var score is in your MAIN.JS then you will need to access like ig.game.score. to increment it you will need to ig.game.score++ whereever you want to do the increment. let me know if you need further help and i'll post an example. note that when you are in main you don't refer to the var as ig.game.score, in main it is this.score.

1 decade ago by Skwiddy

Thanks guys, I knew it would be something simple. Was just too tired to figure it out yesterday!
Page 1 of 1
« first « previous next › last »