OGKaqtus Posted October 23, 2016 Share Posted October 23, 2016 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 More sharing options...
nazimboudeffa Posted October 23, 2016 Share Posted October 23, 2016 addChild is a functionality of pixi right ? Link to comment Share on other sites More sharing options...
OGKaqtus Posted October 24, 2016 Author Share Posted October 24, 2016 No. Because i found out What the problem Was. I just had to add a group i had made AS a child instead of the one item Link to comment Share on other sites More sharing options...
Recommended Posts