Caesar Krit
Caesar Krit

Reputation: 214

Phaser sprite map positioning

i have a map laid out that fills the entire screen. i understand how to add a sprite on the map and give it coordinates,

var thumb = game.add.sprite( 100, 100 , "levelthumb");

But I wanted to know if the following was possible. Can I add lets say 15 of the same sprite on the map giving each one specific coordinates.

I know this can be done easily with a for loop and passing in random x and y just like this exmaples http://phaser.io/examples/v2/groups/add-a-sprite-to-group But I want to give them specific coordinates for each one.

Upvotes: 0

Views: 257

Answers (1)

Caesar Krit
Caesar Krit

Reputation: 214

for anyone who was wonder how it was solved someone helped me with it.

function create() {

lumpofsprites = game.add.group();
lumpofenemies = game.add.group();


function spritepositioning(x, y){ 

//pass in x&y coordinates when calling this

lumpofenemies.create(x, y, 'IMAGENAMEHERE'); //enter image name here or set it as a parameter }

spritepositioning(100,400); 
spritepositioning(0,400);
spritepositioning(500,100);
spritepositioning(424,432);
spritepositioning(216,200);
spritepositioning(500,578);


var theplayer = game.add.sprite(300, 240, 'IMGNAMEHERE');

lumpofsprites.add(theplayer); 

}

Upvotes: 1

Related Questions