Jump to content

Child not visible


Elirath
 Share

Recommended Posts

Hi! Hi!
I have a little problem when using the child function

When only one child is present it works perfectly but as soon as I add a second child the first one becomes invisible...
 

Items.js/func draw()

this.spr = game.make.sprite(0,0, this.img);
this.spr.anchor.y = 0.5;
this.spr.anchor.x = 0.5;

And I add the child like this

Player.js/ func draw()

for(var i=0;i<Slot.length;i++){

   player.spr.addChild(player[Slot[i]].spr);

}

However it works perfectly with only one...

But if I try to add it manually with the console, it works.

var o = game.add.sprite(0,0,'sword_1'); player.spr.addChild(o);

 

Log Result

player.spr.children
(2) [i.Sprite, i.Sprite]
0: i.Sprite {type: 0, physicsType: 0, position: i.Point, scale: i.Point, pivot: i.Point, …}
1: i.Sprite {type: 0, physicsType: 0, position: i.Point, scale: i.Point, pivot: i.Point, …}

length: 2

__proto__: Array(0)

 

And only the last one added is visible. :(

i tried a "spr.visible = true;"

But I have a error, so there must be another reason...

error:

Uncaught TypeError: Cannot set property 'a' of null

Thanks in advance, I hope someone can help me. :)

 

EDIT:

Hello again,
I finally fix it, like that, but I can't understand where the error came from. 

 

Player.js/func draw()

        var o;
        for(var i=0;i<Slot.length;i++){
            if(player[Slot[i]] != null){
                o = player[Slot[i]].draw();
                player.spr.addChild(o);
            }
        }

 

I just added this line in items draw function

Items.js/func draw()

return this.spr;

 

Any idea where it came from?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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