caesar Posted June 11, 2016 Share Posted June 11, 2016 hello, 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. thanks Link to comment Share on other sites More sharing options...
Jambutters Posted June 11, 2016 Share Posted June 11, 2016 Yeah, its possible to do that. Just write a function that will pass the x and y coordinates as parameters. 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); } caesar 1 Link to comment Share on other sites More sharing options...
caesar Posted June 11, 2016 Author Share Posted June 11, 2016 thanks very helpful. another way i thought about it was splitting the map up with math formulas and passing those in. but your way looks simpler Link to comment Share on other sites More sharing options...
Recommended Posts