In the second example, the colliders are very large, so the watermelon changes long before the knife touches it. In the two examples to the right, debug has been set to true, so you can see the green outline of the colliders, and that the animation changes when they touch, even if the pictures of the knife and watermelon aren't touching each other. You can see the colliders by setting the sprite's debug property to true. The size of the colliders is determined by the size of the animation that you are using, even the parts of it that you can't see. Instead, it checks whether the colliders are touching each other. When Game Lab checks whether two things are touching, it doesn't know what parts of the image are visible. For example, the code below changes the animation of the watermelon when the knife sprite touches it. IsTouching returns a Boolean, so it can be used inside a conditional to cause something to happen only when the two sprites touch. Game Lab uses the method isTouching to check whether one sprite is touching another sprite (the target). Sometimes, you'll want to know when two sprites are touching each other.
0 Comments
Leave a Reply. |