bdb Posted August 1, 2021 Share Posted August 1, 2021 Hi All, I'm a new developer and have been enjoying PIXI so far! I am new to most aspects of game and web dev as well, and I was glad to see an active forum like this one. If I have a game object composed of multiple sprites which all use the same x/y position, can I link the position values of the sprites to the x/y I am tracking in my wrapper object? I'm looking for a way to have the sprite position values reference the same memory location as a global x and y value, such that updating the global value would intrinsically update the position of a number of sprites. It looks like the sprite x and y values are getter/setter functions, so at that point I got stuck determining if this would be possible. For now I wrote a setX and setY function that loop through all the associated sprites and set their position values, and I was wondering if this is an efficient way to solve the problem? I'm trying to be cautious about processing overhead and want to understand best practices for any operations that are going to take place on every update scan. Thanks! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 1, 2021 Share Posted August 1, 2021 (edited) Short: You have to read pixi code and understand how our track updateID's work. Long: ugh, cant really re-post it now, its a looooong talk nothing bad will happen if you just re-set all sprites positions. Edited August 1, 2021 by ivan.popelyshev bdb 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 1, 2021 Share Posted August 1, 2021 However the usual way to update several sprites position is to put them in same container. If you have problem with re-ordering sprites inside layers - use can pixi-layers plugin, that way you can store all necessary sprites in same container but have them in different layers bdb 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 1, 2021 Share Posted August 1, 2021 Here's my hard demo for synchronizing physics and pixi: https://codesandbox.io/s/holy-training-step-3-fe4tu?file=/src/Pack.js you can see how physics update entity coords, entity updates sprite. If you want to sync back, like from sprite to entity/body - its better to track _worldID in the loop, save the previous id, see if its changed - then someone updated sprite coord. bdb 1 Quote Link to comment Share on other sites More sharing options...
bdb Posted August 2, 2021 Author Share Posted August 2, 2021 (edited) That's awesome! I had read about containers and planned to use them, but you made me realize the 'duh' moment here: Containers are for object grouping, big and small. Thank you - I'm going to run into a bunch of conceptual knowledge gaps, and hopefully I won't bug you about all of them! Quick response was really helpful. I'll certainly check out your demo and thank you for that link as well. Edited August 2, 2021 by bdb Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 2, 2021 Share Posted August 2, 2021 (edited) > Containers are for object grouping, big and small. for grouping elements that will 1. transform together (unless you hack "element.transform.updateTransform = () => {}" 2. remove together 3. render together (unless use pixi-layers) UPD. Also containers dont exist in pure ECS architecture, but they are very handy for 2d rendering Edited August 2, 2021 by ivan.popelyshev 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.