xronn Posted February 12, 2014 Share Posted February 12, 2014 I want to draw many trap sprites onto my level, so far I have created them like this;//Spike Traptrap = this.add.sprite(240, 208, 'spikes');trap.animations.play('spike');But if I want to add more the only way I know currently how to do it would be to create a new sprite e.g. trap1, trap2, etc.. I want to draw them all in different locations that I define (not using math.random). Link to comment Share on other sites More sharing options...
jcs Posted February 13, 2014 Share Posted February 13, 2014 not certain what you're asking, but... first, put them in an array so that you don't have to give them all their own names. e.g.var traps = [];traps.push( this.add.sprite( x, y, 'spikes' ) );doSomethingWithTrap( traps[0] );OR you can use a Phaser Group. e.g.var traps = new Phaser.Group( this ); // assuming 'this' is your 'game' objecttraps.create( x, y, 'spikes' );doSomethingWithTrap( traps.getAt( 0 ) );which you prefer really depends on how you intend to use the. Group provides more Phaser-specific functionality and is probably more useful to you. secondly... is there a secondly? if you want to create them at non-random locations then you'll need to make the call to create each one with different x and y coordinates. you can put these in code or load them from another file somewhere (a JSON file, perhaps)... Link to comment Share on other sites More sharing options...
Recommended Posts