I am trying to implement a bar that rebounds the object falling on it. however I just want the object to rebound when it falls on it from above the top edge. if the object is comming from bellow the object should pass as if the bar doesnot exsits. This is similar to what the bird does in tweetjump or doodle does in doodle jump. Any hints on how I can do this in corona ?
When the object collides with the bar from below, Try giving
bar.isSensor = true
Have a read here:
http://developer.anscamobile.com/reference/index/bodyissensor
One use case for setting this property is overriding a collision that
is about to happen, such as the "one-sided platform" case, where a
character should pass through a platform only in one direction.
Related
I implemented physics contact delegate in order to find out the contact between two nodes. Upon contact, the delegate is getting called correctly and i am changing the color of the nodes. But contact didEnd method is called again and again and hence i couldn't find out when the actual contact ended.
For example, if i move one object to overlap with the other, i am changing the color of the objects. But when i again move the second object outwards and if there is no contact, again i have to change back the color to original one. How to achieve this?
There is method to tell that there is some contact but there is no method to tell that the contact is no more.
I'm currently creating a 2D game in Swift using SpriteKit and I'm having a problem with the collision detection.
Let's say I have SKSpriteNode Foo in the game. Then let's say SKSpriteNode Bar spawns on top of Foo, but does NOT have the contactTestBitMask to trigger a contact. Then after a short moment (let's say 1 second) Bar changes its contactTestBitMask to detect contact with Foo.
Currently, Foo will have to actually move around a little bit OR move out from under Bar and return back to it to detect contact with it. I need Bar to immediately trigger contact with Foo when it changes its contactTestBitMask.
Maybe there's a different way to do this without changing the contactTestBitMask?
Thanks!
If you create a physics body object intersecting another physics body object, no collision will register. It has something to do with the way SK registers a collision through movement only.
You have the option of using intersectsNode: when creating your object to see if it intersects another object and handle any subsequent code accordingly.
I'm messing around with Swift for the first time and have a square on the screen. The square starts by moving to the right. When I tap on it I want it to go up. I don't want it to continue to the right at all, I want it to just go straight up. Unfortunately the physics and gravity make it curve to the right some more before it goes up. What can I do to completely stop the gravity pull and acceleration of my object, before setting the gravity to the new value?
This turns the object in the right direction, but I need it to come to an instant stop before doing this.
if(self.gravity.gravityDirection.dx == 1){
self.gravity.gravityDirection = CGVectorMake(-1.0, 0.0)
}
The way to stop an item being affected by a behavior is to remove the item from the behavior or remove the behavior from the animator. For example, here you might remove self from the existing gravity behavior.
Lets say i have some long object, lets say this arrow here:
Right now, if i want to drag and move the arrow, when i tap and move it - its being held from the centre.
I want the tap and hold point to be its tail. I tried to search for a fitting property (such as anchorPoint), or physicsBody properties, but i didn't find anything that seemed to work.
Does anyone know a solution to my problem? Thank you!
I am doing this spritekit game.
I have this object that I want to move up and down when the user touches it. It is an object that has to slide in a rail, up and down or in another case left and right.
So, when the user touches the object I do something like this
CGVector force = CGVectorMake(0.0f, 5000.0f);
[object.physicsBody applyForce:force];
it is a vertical force applied up.
but when the object collide with others it rotates. Is there a way to prevent the object from rotating?
Try object.physicsBody.allowsRotation = NO. This ignores all angular impulses and forces that would make the body rotate.