Masking and Physics in SpriteKit - swift

When using SKCropNode in SpriteKit, does the masking affect the physics of the node? (e.g. I crop half of the sprite, will a ball fall through the masked part of the image?) If this is the case, how would I go about creating the SKCropNode so it would crop where ever I touch?
Cheers

SKCropNode only pertains to how a node appears on the screen, it does not deal with physics bodies. You can however use SKPhysicsBody(polygonFrom:CGPath) to create a path that is identical to the body you are trying to mimic, with the gap and everything. I recommend using the program PhysicsEditor to achieve such effect. https://www.codeandweb.com/physicseditor

Related

Can you paint a tile on sprite overlap? Unity

Hi all I'm trying to make a game where I can drive around and as I pass over certain tiles in my tile-map they change colour, dead simple problem in my head. However not sure how to change the painted tile on overlap, my thinking was I could use sprite collision detection but when I put my sprites on the same z-axis height they overlay and are no longer visible. Is there something I have missed or a more efficient way of going about this?
Thanks :)

How do I create an outline for my SKSpriteNode around the png texture in swift?

I am making a game in Swift(SpriteKit) and when the character in the game picks up a power-up, I want him to get an outline in purple so the player can see that his power-up is ready to use. I want the outline to hug all the curves of the player exactly. Is there any way to draw an outline around a sprite node that isn't a basic shape(like circle or square) but to outline a complex shape?
Here is an example of a shape similar to my sprite node:
And here is another example of the player with the visual outline that I want to add in SpriteKit(I just sketched it but I want it to be exact obviously):
They player also has his legs animating by flipping through an atlas of the animation, and preferably the outline would stay around the legs when the walking animation is happening. Is this possible?
To be clear, I just want an outline for visual purposes, so the player knows their "power up" shield is active so if they get hit it won't damage them.
I haven't dabbled with SpriteKit for a few years, and if memory serves me correctly perfect collision detection while animating is not available out of the box.
After checking the documentation I see that SKPhysicsBody has a init(texture:size:) initializer. This should at least get you a bit closer.
This guide from Apple is probably worth a read. (Pixel perfect collision detection is expensive).

SpriteKit + iOS8. Does SpriteKit support "baking" rendered results?

I am implementing a paint program in SpriteKit and I am super impressed by the simplicity of implementation SprikeKit enables. Very cool indeed!
Each brush stroke is implemented as a SKSpriteNode with attached SKShader. Everything works as I expect.
Issue: Currently I am steadily growing the SKScene graph as brush strokes are appended. This is not a scalable solution as resource consumption mushrooms and framerate slows to a crawl. So, what I want to do "bake" the SKScene graph after brush stroke is painted.
I tried setting myScene.shouldRasterize = YES on my SKScene instance but it appeared to have no effect. How do I "bake" rendering results in SpriteKit? Do I have to roll my own?
Thanks,
Doug
The only was I can think of to do this is to call textureFromNode on your SKView passing in the SKNode that you want to "bake". Then take that texture, apply it to a SKSpriteNode, and remove the SKNode(s) that you just "baked" in to the texture.
Wanted to add a comment but reputation won't allow me. Just would like to add that you can rasterize group of sprites by using SKEffectNode. Just add any sprite to this node then use the same shouldRasterize property. You can even apply CoreImage filters to it such as Gaussian Blurs.
The downside is obviously performance when created the rasterized node.

Creating a Body - Cocos2d/Box2d

I have a ball and another sprite. When the ball collides with the sprite it simulates falling.
My only problem is the other sprite is just on big image and the ball is on top of it, but there are spaces on the sprite and a lot of corners. I need to determine if the sprite has touch one of the corners. I know this is hard to understand.
So, my question is, is it possible to make a body without
b2PolygonShape blockShape;
and
blockShapeDef.shape = &blockShape;
OR
is there an alternative I can use? I cannot set the image as a box and it would take way to long to set edges because there are so many corners.
I have already set up the collision detection.
I really need help with this.
Thanks!
If you want it to react properly, you have to make a polygon using every single corner coordinate.
But don't be lazy about it. You can use SpriteHelper for creating *b2PolygonShape*s out of your sprites.
Or another alternative: VertexHelper

Cocos2d - Creating collidable Sprites?

Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?