Jump to content

Cant add Child to background


OGKaqtus
 Share

Recommended Posts

I cant figure out how i would be able to add a function as a child, the function spawns items at the top of the screen and then they fall to the bottom where they will be killed. But if i add a background the items spawn behind that background. i cant figure out how they will be able to spawn infront of the background :(

any help would be greate!

Here im trying to add the items as a child

Potato.SpawnPotato = this.mainBackground.addChild(game.potato);

And this is the code which holds game.potato

Potato.item = {
    spawnPotato: function(game){
        
        game.world.enableBody = false;
        
        game.physics.startSystem(Phaser.Physics.ARCADE)
        game.physics.arcade.gravity.y = 200;
        
        var dropPos = Math.floor(Math.random()*650);
        
        var dropOffSet = [-27, -36, -36, -38, -48];
        var potatoType = Math.floor(Math.random()*5);
        var potato = game.add.sprite(dropPos, dropOffSet[potatoType], 'FallingPotato');
        potato.animations.add('anim', [potatoType], 10, true);
        potato.animations.play('amim');
        
        game.physics.enable(potato, Phaser.Physics.ARCADE);
        potato.inputEnabled = false;
        
        potato.anchor.setTo(0.5, 0.5);
        potato.rotateMe = (Math.random()*4)-2;
        game._potatoGroup.add(potato);
        
        potato.checkWorldBounds = true;
        potato.events.onOutOfBounds.add(this.removePotato, this)  
        
    },
    
    removePotato: function(potato){
        potato.kill();
    }
    
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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