Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contain uses mixed positioning #18

Open
mcbloch opened this issue Sep 16, 2018 · 0 comments
Open

contain uses mixed positioning #18

mcbloch opened this issue Sep 16, 2018 · 0 comments

Comments

@mcbloch
Copy link

mcbloch commented Sep 16, 2018

I'm trying to use the contain function to keep a ball (sprite) inside a playing field (container). Struggling to get this done I went into the code to see if I was using it correctly.

Maybe i'm just wrongly interpreting this so correct me if I'm wrong.

Normally x and y are used as anchor positions of the object, let's say for simplicity sake that they indicate the top left corner in this example. The width and height are then used for... width and height. So if you want to know what the x-coordinate is of the right side you do x + width.

In the contain function left and top collision are calculated as if the sprite and the container are on the same level (as if they have the same parent). Because both x's are compared. If the sprite would be in the container then you should just compare sprite.x < 0 (leaving out gravities to make it simpler).

right and bottom are calculated as if they are nested aka as if the sprite is in the container.
Example how it should be for right if they are not nested like in the left and top function: you take the right most pixel sprite.x + sprite.width and you compare it to the right most part of the container container.x + container.width. But in the code it is just compared to the width as if the sprite is inside the container hereby conflicting with the left and top usage.

I'm willing to look into this and fix this if I'm correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant