Jump to content

Linking sprite position by reference to wrapper class for game object


bdb
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by bdb
Link to comment
Share on other sites

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 by ivan.popelyshev
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...