Akiak Posted February 17, 2020 Share Posted February 17, 2020 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 ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 17, 2020 Share Posted February 17, 2020 You can move whole container that contains eggs. You can create extra container if you want only part of eggs to be moved. Also the code your supplied has to work, I dont see whats wrong with it. Please post a demo on codepen,jsfiddle,codesandbox or pixi-playground. Akiak 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.