iOS Sprite Kit Collision with movement through elements - ios

Is it possible to use Sprite kit's physicsBody to have element collision and still allow elements to go through each other? I'm interested in having the delegate to be called only when two borders hit each other and then allow them to go through each other afterwards :)

Yes this is possible. You can register for callbacks from collisions between objects but not have the collision affect the object itself.
The Ray Wenderlich - Sprite Kit book explains how to do this in the Zombie Conga game tutorial.
Try this one... http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
The section called "Collision Detection and Physics: Implementation" should explain what you need.
Just had a quick read and the two things you're after are...
contactTestBitMask this is which object collisions you want to receive collision callbacks for.
collisionBitMask this is which object will collide and "bounce" off each other.

Related

how to implement gear joint in sprite kit?

The gear joint in Box2d is great, but I don't know how to implement that in Sprite Kit. Is there any solutions to implement the gear joint in Sprite Kit?
Thanks.
Here are the available Sprite-Kit joints :https://developer.apple.com/reference/spritekit/skphysicsjoint
As far as I can understand, there does not appear to be a direct correlation to Box2D's gear joint, which seems to make one body rotate when another body is rotated.
In that case, you might want to investigate overriding the didSimulatePhysics or didFinishUpdate methods to manually set the rotation of one object based upon the rotation of another object:
https://developer.apple.com/reference/spritekit/skscene/1519965-didsimulatephysics
https://developer.apple.com/reference/spritekit/skscene/1520269-didfinishupdate
It might be as simple as:
wheel2.zRotation = wheel1.zRotation
but if the gears have different numbers of teeth (thus different ratios), you'll have to do some calculations.

volume-based physicsBodies being moved manually not contacting edge-based physicsBody

So in my Space Invaders game, all collisions were working perfectly until I added a physics body created from a edgeChainFromPath which is a single line to represent the ground (an SKShapeNode created from 2 points). Now my invader bombs (which move via SKAction) notify when they hit the ground but my invaders (moved in update() by manually updating their positions) do not. My ship missiles (also moved by SKAction) DO notify when contacting an invader.
Question : if a physicsBody is moved manually and comes into contact with another physicsBody, is didBeginContact not called? (All physics interactions - bitMasks, delegates etc - are set correctly). I'm thinking the answer is 'No it's not' because that's the only explanation and makes sense picturing how Sprite/Kit probably works. I.e. A contact occurs when the SK engine itself moves a node and realises that it's physicsBody is being drawn on top of another physicsBody.
Edit - just realised that I have other physicsBodies in my scene that are stationary and that the invaders DO collide with, so it's not an SKAction thing. The difference might be that the new node I've added is an edge-based body belonging to an SKShapeNode, rather than a volume-based body for a SKSPriteNode, but nothing in the documentation that I can find states that this shouldn't work.
New question : Do volume-based bodies being moved manually not collide with stationary edge-based bodies?
Ok - my bad. The invaders' physicsBodies had dynamic=false. Every other sprite was dynamic, so all other collisions were working. My new shape was an edge-based body which also are dynamic=false.
Made that one change and all is Ok. I need to update my checkPhysics() routine to test for this.
Edit: I really should have seen this earlier - checkPhysics() was not printing that invader notifies when contacting ground, which I just put down to a glitch that I'd fix later. Whereas checkPhysics() deliberately doesn't report on nodes with dynamic=false. I think that when I wrote the function, I assumed that you'd set dynamic=false deliberately to not be involved in collision/contact detection. I should change it to print a warning.

Make a certain sprite ignore SKPhysicsBody

I am having an issue making a sprite ignore the effects of a SKPhysicsBody placed as a ground platform in an iOS project. I have only one sprite that I would like to "follow the rules" of the SKPhysicsBody and for all other sprites to "pass through". I have searched for a way to do this, but to no avail. Any suggestions?
for any physics body that you want to pass through set its collisionBitMask to 0 that means that it won't collide with anything, make sure you don't set the collisionBitMask of the ground to the type of sprite you want them to pass through,

How would I build pool-cues / simplified pinball-style plungers with SpriteKit?

I'm working on a game in which the user should be able to trigger 'rods' that come out from the edge of the screen to displace elements on screen (balls). These projectiles roughly resemble pool-cues. Or perhaps pinball plungers, except that they start from the 'loaded' position (mostly offscreen), and when triggered, they eject out, then quickly retreat.
I'm unclear how I should build these with Sprite Kit.
The game uses the PhysicsEngine, and the onscreen balls should be effected both by gravity AND they should be displaced when they collide with the rods. However the rods should neither be effected by gravity, not displaced when they collide with the balls -- they should simply retreat regardless of whether they've made contact with the balls.
I realize I can set the affectedByGravity property for the rods. However because they will still displace slightly when they collide with the balls. How can I 'fix' or 'peg' them in place? Do I need to use an SKPhysicsSlidingJoint? If so, has anyone encountered any examples online? Is there a simpler way to do this?
A related physics engine, Box2D distinguishes static, kinematic, and dynamic bodies.
Kinematic bodies can move and will collide with other objects, but they are themselves not affected by dynamic bodies or forces like gravity. Thus, consider setting rod.dynamic = NO; but animate it with actions. See also here in the reference for SKPhysicsBody.

animation in corona

how can i perform animation on my moving object....
and how can i control collisions when some of objects are allowed to collide and some not...i,m beginner to corona and coding as well ...i look all the examples i know there r answers of my questions but i cant understand that properly...so any one help me??
In Corona when you create a Physics body you can specify the body type: static, kinematic, and dynamic.
Static bodies don't move, and don't interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
Dynamic bodies are affected by gravity and collisions with the other body types.
Kinematic objects are in-between Dynamic and Static bodies but doesn't response to gravity
For more information check these links: http://developer.anscamobile.com/content/game-edition-physics-bodies and http://developer.anscamobile.com/reference/index/physicsaddbody
By "animation" I'm going to assume you mean that the graphic changes. In that case you should use a Spritesheet:
http://developer.anscamobile.com/reference/sprite-sheets
As for collisions, there again I'll make an assumption because your question is a little vague. I interpret your question as wondering how to setup collisions where some objects don't collide with each other, and for that you want to set category and mask bits:
http://developer.anscamobile.com/content/game-edition-collision-detection#Collision_categories_masking_and_groups
It is very easy to make a animation by using corona sdk.If using sprite sheet animation u have use this link http://docs.coronalabs.com/api/library/display/newSprite.html.

Resources