dthrasher90 Posted April 11, 2017 Share Posted April 11, 2017 Is there away to align sprites to a variable, like from another spite? i.e. var locationx = spite1.body.x var spirte2= this.game.add.sprite(locationx, 100); or even var spirte2= this.game.add.sprite(locationx {x: '+100'}, 100); ^^^something to this affect? Link to comment Share on other sites More sharing options...
MikeW Posted April 11, 2017 Share Posted April 11, 2017 I would use the update loop. Every update run that code. Link to comment Share on other sites More sharing options...
dthrasher90 Posted April 11, 2017 Author Share Posted April 11, 2017 How would that look? Link to comment Share on other sites More sharing options...
samid737 Posted April 11, 2017 Share Posted April 11, 2017 Hi, you can use sprite.addChild to make your second sprite a child of your first one so that it will always align (and you can make the offset even variable within the update as suggested by @MikeW): You can also do the same thing by making a group and grouping your sprites: Link to comment Share on other sites More sharing options...
dthrasher90 Posted April 11, 2017 Author Share Posted April 11, 2017 That's totally what I was looking for, thanks. samid737 1 Link to comment Share on other sites More sharing options...
dthrasher90 Posted April 11, 2017 Author Share Posted April 11, 2017 So I have one more question. Im trying to align rg spite next to ct sprite based off your idea, to make it dynamic. if I use the game.physics.arcade.enable, it works properly, however, it wont align the spites, because y is undefined, since the physics isnt enabled. If I move the method above the rg variable, it becomes hasownproperty error. Is there away around this, so i can correctly position a sprite? var ct = this.game.add.sprite(510, 225, 'ct'); ct.scale.setTo(0.03); var rg = this.game.add.sprite(500, offsetRG, 'rg'); rg.scale.setTo(0.03); // // var rt = this.game.add.sprite(570, 100, 'rt'); // rt.scale.setTo(0.3); var football = this.game.add.sprite(500, 220, 'football'); football.scale.setTo(0.08); var offsetRG = ct.body.y-25; console.log(offsetRG); game.physics.arcade.enable( [wr1, wr2, wr3, wr4, ct, rg, football] ); Link to comment Share on other sites More sharing options...
dthrasher90 Posted April 11, 2017 Author Share Posted April 11, 2017 never mind i got it working, thanks. needed ct.y-25; Link to comment Share on other sites More sharing options...
Recommended Posts