Jump to content

Sprites invisible when added to shop


Magnifisite
 Share

Recommended Posts

Hello,

 

I have a found a very weird bug or at least unsuspected behaviour.

I have a class called Shop which creates a shop sprite and has functions for opening and closing the interface.

The collision check I use was/is custom but  I also wanted to let bullets collide with the shop so I figured that it would be easy to add the sprite to a group.

I created a global variable called shops and initialized it with the following code in my stage.create:

shops = game.add.group();

This is my shop class:

Shop = function(game, chunk, sprite) {    this.game = game;    this.shop = this.game.add.sprite(chunk.sX + 256, chunk.sY + 256, sprite);    this.shop.anchor.setTo(0.5, 0.5);    this.shop.body.setCircle(95.5);    this.shop.body.immovable = true;    shops.add(this.shop);    this.open = false;}Shop.prototype = {    checkForCollision: function() {        if (this.game.physics.collide(player.p, this.shop)) {            this.openShop();        } else if (this.open) {            this.closeShop();        }    },    openShop: function(p, s) {        if (!this.open) {            this.open = true;            player.current_shop = this;        }    },    closeShop: function() {        if (this.game.physics.distanceBetween(this.shop, player.p) > 256) {            this.open = false;        }    }}

As you can see I add the shop to the group on line 10.

The problem is: the sprite is invisible but the collision is still working, if I remove line 10 then the sprite is visible but the collision is obviously not working.

 

I have the same problem with my bullets (I ended up creating a custom group object for the bullets), everything I add to a group is invisible for some reason.

 

Does anyone know why my sprites get invisible the moment I add them to a group?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...