Jump to content

game.physics.arcade.sortDirection


Techbot
 Share

Recommended Posts

Line 23 in the Sort Direction example

 

game.physics.arcade.sortDirection = Phaser.Physics.Arcade.RIGHT_LEFT;

 

What does this do?

 

Api docs:

[static] LEFT_RIGHT : number

A constant used for the sortDirection value. Use this if your game world is wide but short and scrolls from the left to the right (i.e. Mario)

 

Ok, I can see where and when it is used, but what does it do? What is being sorted?

 

thanks

Link to comment
Share on other sites

Let's say you're using Arcade physics. Here's a link to collideSpriteVsGroup method in the Arcade physics world.

 

See how, unless the sprite's physics body skips the quad tree, it starts colliding against members of the group? It's looking not at the group.children, but at the group.hash. That's what's being sorted: how the children of the group are stored in the hash. Why do we care?

 

Let's say we're sorted LEFT_RIGHT. That means, before colliding with the child of the group, we can take some shortcuts: if the sprite we're colliding is to the left of a group sorted LEFT_RIGHT, we're done checking against its children. Since it's sorted LEFT_RIGHT, all the children are to the right of the thing we're checking... so if the sprite is to the left, we're now done checking this group.

 

Make sense?

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