Gem collection system

how would i do a coin collection system? i want it to be so that when the player walks over the gem, it dissapear’s and the value of it goes to a UI text on the screen. link to project:

This game does exactly that :
You might find what you need there :slight_smile:



it is not working. what script am i supposed to use?

Well this is a full game (not mine, I don’t know anything about it except that it’s nice and cool :slight_smile: )
So you won’t find something to purely copy/paste.

But a quick look in the code can give some hints, such as this in “collectible.js” :

Collectible.prototype.onContact = function () {
    this.entity.enabled = false;'pickup', this);

    //regeneration logic

Looks like a contact event is used to trigger a “pickup” and make the collectible disappear.

and then in “game.js” :

Game.prototype.onPickedCollectible = function (collectible) {
    var points = collectible.points;

    // [...]

    this.setScore(this.score + points);

Here you can see that a collectible has a “points” attribute, which is used for the score calculation.

One of the collectible’s attributes :

1 Like

i will try it out