Tesserato Posted August 13, 2017 Share Posted August 13, 2017 Hello comrades, I'm new to phaser and I can't seem to create new objects to the group "capetinhas", even though I can load the sprite through game.add.sprite. Here's the code: var game = new Phaser.Game(448, 448, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload () { game.load.image('tabuleiro','assets/tabuleiro.png') game.load.spritesheet('devil','assets/devil.png',32,32); var capetinhas; } function create (){ capetinhas = game.add.group(); game.add.sprite(window.width,0,'tabuleiro');//loading the background game.add.sprite(128,128,'devil'); // this works capetinhas.create(32,32,'devil'); // this doesnt } function update (){ } Any helpe would be really apreciated. Thanks in advance. Link to comment Share on other sites More sharing options...
samme Posted August 14, 2017 Share Posted August 14, 2017 What happens? Do you get an error, or do you not see a sprite at (32, 32)? Link to comment Share on other sites More sharing options...
Tesserato Posted August 14, 2017 Author Share Posted August 14, 2017 18 minutes ago, samme said: What happens? Do you get an error, or do you not see a sprite at (32, 32)? The sprite doesn't appears. After a while I used "capetinhas.countLiving" on the console and it returned me 1. Therefore, the object is created but the sprite doesn't load. P.S. I don't get any error. Link to comment Share on other sites More sharing options...
espace Posted August 15, 2017 Share Posted August 15, 2017 try this : var game = new Phaser.Game(448, 448, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload () { game.load.image('tabuleiro','assets/tabuleiro.png') game.load.spritesheet('devil','assets/devil.png',32,32); } function create (){ var capetinhas = game.add.group(); game.add.sprite(window.width,0,'tabuleiro');//loading the background game.add.sprite(128,128,'devil'); // this works capetinhas.create(32,32,'devil'); // this doesnt } function update (){ } Titus 1 Link to comment Share on other sites More sharing options...
Titus Posted August 15, 2017 Share Posted August 15, 2017 I'm also new to Phaser but when I tested your code I was able to add both 'devil' sprites to the game world so maybe something else is affecting it, but you could try putting the sprite into a variable and then add it to the group function create (){ capetinhas = game.add.group(); game.add.sprite(window.width,0,'tabuleiro');//loading the background var devil = game.add.sprite(128,128,'devil'); capetinhas.add(devil); } Link to comment Share on other sites More sharing options...
Tesserato Posted August 15, 2017 Author Share Posted August 15, 2017 4 hours ago, Titus said: I'm also new to Phaser but when I tested your code I was able to add both 'devil' sprites to the game world so maybe something else is affecting it, but you could try putting the sprite into a variable and then add it to the group What version of Phaser are you using? Link to comment Share on other sites More sharing options...
Tesserato Posted August 15, 2017 Author Share Posted August 15, 2017 Just found that that the board sprite (tabuleiro.png) was being rendered AFTER the creation of the group. Therefore, every instance of capetinha was beign overlayed by it. Thank you everyone. Link to comment Share on other sites More sharing options...
Recommended Posts