You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
functionleft
andtop
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 comparesprite.x < 0
(leaving out gravities to make it simpler).right
andbottom
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 containercontainer.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.
The text was updated successfully, but these errors were encountered: