Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

ct.js

Create cool 2D games with a free game editor! · By Cosmo Myzrail Gorynych

score not updating (help)

A topic by qwik06 created 33 days ago Views: 24 Replies: 2
Viewing posts 1 to 2
(1 edit)

//creates the score in the object inside the current room

this.score = 0;

this.scoreLabel = new PIXI.Text('Score: ' + this.score, ct.styles.get('ScoreText'));


but 

//collision takes place 

ct.room.score ++; 

 //does not update the score (the current room score remains 0)


what am I missing??

Developer
this.scoreLabel = new PIXI.Text('Score: ' + this.score, ct.styles.get('ScoreText'));

Here, 'Score:' + this.score turns into a static string, and to update it, you need to recalculate it each frame and update the scoreLabel. Add it to your Draw event:

this.scoreLabel.text = 'Score: ' + this.score;

or a better variant which removes excess updates but does the same thing:

var scoreText = 'Score: ' + this.score;
if (this.scoreLabel.text !== scoreText) {
    this.scoreLabel.text = scoreText;
}
(+1)

thanks. I was missing the code in the draw event