Jump to content

align sprites to variables


dthrasher90
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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