Jump to content

align sprites to variables


dthrasher90
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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