mrvinegar Posted January 7, 2014 Share Posted January 7, 2014 Hi, I'm trying to add sprites to a group, but when I do the sprite disappears off screen... I'm doing this...where am I going wrong? var firstGroup; function create () { firstGroup = game.add.group(); game1 = game.add.sprite(200, 0, 'g1'); game1.inputEnabled=true; game1.events.onInputDown.add(listener1,this); firstGroup.add(game1); Link to comment Share on other sites More sharing options...
XekeDeath Posted January 7, 2014 Share Posted January 7, 2014 Disappears off screen how..?Does it fall off like affected by gravity, or is it just never there? Link to comment Share on other sites More sharing options...
mrvinegar Posted January 7, 2014 Author Share Posted January 7, 2014 The sprite just isn't there, if I don't add it to the group it appears as normal... Link to comment Share on other sites More sharing options...
rich Posted January 7, 2014 Share Posted January 7, 2014 Do any of the Group examples work for you? (there are loads of them, just pick a couple and see). I can't see anything obviously wrong with your code at all, which makes me think it's something else going on (that perhaps isn't shown in the code above). Link to comment Share on other sites More sharing options...
vtoaster Posted January 8, 2014 Share Posted January 8, 2014 I'm having the same issue. If I remove the line to add the sprite to the group the sprite shows on screen as it should. curiously this also fails to show anything on screen: var firstGroup; function create () { firstGroup = game.add.group(); game1 = firstGroup.create(200, 0, 'g1'); game1.inputEnabled=true; game1.events.onInputDown.add(listener1,this); Link to comment Share on other sites More sharing options...
BitlasLT Posted January 8, 2014 Share Posted January 8, 2014 Please attach full create function.Is it possible that you are adding more object on stage after group?(like fullscreen background) Link to comment Share on other sites More sharing options...
mrvinegar Posted January 8, 2014 Author Share Posted January 8, 2014 Do any of the Group examples work for you? (there are loads of them, just pick a couple and see). I can't see anything obviously wrong with your code at all, which makes me think it's something else going on (that perhaps isn't shown in the code above). The group examples do work yes...curious Here is my full createfunction create () { //removing a preloader el.style.display = 'none'; // Here we'll create a new Group menuGroup = game.add.group(); var bcgmain = game.add.sprite(game.world.centerX, game.world.centerY, 'bcg'); bcgmain.anchor.setTo(0.5, 0.5); game1 = game.add.sprite(200, 0, 'g1'); game1.inputEnabled=true; game1.events.onInputDown.add(listener1,this); menuGroup.add(game1); game2 = game.add.sprite(230, 150, 'g2'); game2.inputEnabled=true; game2.events.onInputDown.add(listener2,this); //menuGroup.add(game2); game3 = game.add.sprite(260, 300, 'g3'); game3.inputEnabled=true; game3.events.onInputDown.add(listener3,this); //menuGroup.add(game3); game4 = game.add.sprite(290, 450, 'g4'); game4.inputEnabled=true; game4.events.onInputDown.add(listener4,this); audioMenu = game.add.audio('audioMenu'); audioMenu.play('',0,1,true); audioMenuId = game.add.audio('audioMenuId'); audioMenuId.play(); audioMenuSelect = game.add.audio('audioMenuSelect'); } Link to comment Share on other sites More sharing options...
mrvinegar Posted January 8, 2014 Author Share Posted January 8, 2014 Ok..I've tracked the issue down to this line, removing this makes the sprite appear bcgmain.anchor.setTo(0.5, 0.5); Link to comment Share on other sites More sharing options...
rich Posted January 8, 2014 Share Posted January 8, 2014 How large is that sprite? The anchor shouldn't have any bearing on if a Sprite appears in a Group or not (you'll find most of them in the Groups Examples have anchors) Link to comment Share on other sites More sharing options...
mrvinegar Posted January 8, 2014 Author Share Posted January 8, 2014 How large is that sprite? The anchor shouldn't have any bearing on if a Sprite appears in a Group or not (you'll find most of them in the Groups Examples have anchors) I fixed it by adding that sprite to the group, so this worksvar bcgmain = game.add.sprite(0, 0, 'bcg');menuGroup.add(bcgmain); Link to comment Share on other sites More sharing options...
vtoaster Posted January 8, 2014 Share Posted January 8, 2014 I understand the issue now! It had to do with the background image being on top of the group. I was creating the group (but not creating the sprites or populating it) until later. Creating the sprites alone was fine as they were created above the group and background, but once I added them to the group their ordering changed to that of the group which was under the background and hidden from view as the background covers the whole game screen. Creating the group above the background fixes the issue for me. Thanks for the help! lukaMis, Lyian and mjohnsonengr 3 Link to comment Share on other sites More sharing options...
clark Posted February 19, 2014 Share Posted February 19, 2014 I have this setup:State-UIGroup extends Phaser.Group--MenuGroup extends Phaser.GroupOn UIGroup I create a new MenuGroup and I need to pass a Phaser Game instance. If I say: new MenuGroup(this.game, this) I would expect UIGroup to be the parent of MenuGroup.But:var menu: MenuGroup = new MenuGroup(this.game, this);console.log(menu.group) //nullSo I am not sure what my menu is parented to. If I say this.remove(this.menu) I get an infinite loop. Any ideas? Link to comment Share on other sites More sharing options...
Danny00014 Posted June 8, 2014 Share Posted June 8, 2014 I understand the issue now! It had to do with the background image being on top of the group. I was creating the group (but not creating the sprites or populating it) until later. Creating the sprites alone was fine as they were created above the group and background, but once I added them to the group their ordering changed to that of the group which was under the background and hidden from view as the background covers the whole game screen. Creating the group above the background fixes the issue for me. Thanks for the help! Thanks for this. It makes sense that things are layered that way. I was having the same problem. Sometimes things are just "too simple." Link to comment Share on other sites More sharing options...
Recommended Posts