Jump to content

Container switching in pixi


Shadowstep33
 Share

Recommended Posts

Hi guys, I was trying to find an answer to this but had some problems (maybe my Google-fu is just a little off today). Thankfully, I figured out the answer myself. 

 

Assuming you have a character walking around in a world of containers (for example, walking from one zone to the other where each zone is a container that is next to the other) the calculation is:

newX = oldX + (oldContainerX - newContainerX);

newY = oldY + (oldContainerY - newContainerY);

 

and a real code example:

if(buckets['walking'].parent){
    var newX = buckets['walking'].position.x + (buckets['walking'].parent.position.x - buckets.biomes[overlappingBiomes[0]].scen.position.x);
    var newY = buckets['walking'].position.y + (buckets['walking'].parent.position.y - buckets.biomes[overlappingBiomes[0]].scen.position.y);
                    
    // buckets['walking'].parent.removeChild(buckets['walking']);
    buckets.biomes[overlappingBiomes[0]].scen.addChild(buckets['walking']);
    buckets['walking'].position.x = newX;
    buckets['walking'].position.y = newY;
}

 

Hopefully this helps someone! 

Cheers

Link to comment
Share on other sites

And when you are comparing obj1 and obj2 from different containers:

let differenceX = (obj2.x - obj1.x) + (obj2.parent.x - obj1.parent.x);

That helps in case of very big maps, you wont lose precision that way

And I wont paste here the code for universal portal engine which i have :) Formulas are much more difficult there.

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