Jump to content

accessing variables of all children


Akiak
 Share

Recommended Posts

Hi, i'm a beginner at pixi.js so please bear with me!

I'm trying to add a sprite of a certain type whenever the user presses a button.

However I need all the sprites to be moving towards the right every frame.

So for now I have the following code triggered when the user presses a button:

egg = new PIXI.Sprite(PIXI.loader.resources["images/newegg-02.png"].texture);
pubviewport.addChild(egg);

Which works fine, however I'm not sure how to access the X and Y values of all the eggs that currently exist in order to move them.

In the gameLoop function, just adding an egg.x += 4 doesn't work, so what do I do? Have also tried a for loop like so:

for (var i = 0; i < pubviewport.children.length; i++){
           pubviewport.getChildAt(i).x += 4;
       }

Thanks

A

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...