Jump to content

sprite map positioning


caesar
 Share

Recommended Posts

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

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); 

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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