Jump to content

Can't create new objects in phaser group


Tesserato
 Share

Recommended Posts

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

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

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 (){
	
}

 

Link to comment
Share on other sites

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

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

 Share

  • Recently Browsing   0 members

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