I am using SpriteKit, does SKLightNode can only work with SKSpriteNode? because there is no shadowCastBitMask property on SKShapeNode, I cannot make SKLightNode work with SKShapeNode. Is there a way can make them work together? Thanks!
SKShapeNode does not have lighting properties like SKSpriteNode. If you create a SKShapeNode you can make it disappear into a shadow but you cannot make it cast a shadow or set any other lighting properties.
Related
I'm working in Swift 3.1. I want to create a shadow for a SKSpriteNode. I'm thinking of doing a SKShapeNode from my SKSpriteNode and giving it some glow and alpha.
But how can I convert SKSpriteNode into SKShapeNode?
If your plan is to make a shadow that looks like your sprite, then using another SpriteNode instead would be advisable. SKShapeNodes have poor performance and the process of converting the sprite into a vector shape will be processing heavy.
You should have read about SKEffectNode because you could use them to create a SpriteNode with your current texture and apply some effects on it to turn your texture black, blured ans maybe even use affine transformation to distort and rotate the texture so it looks like a shadow.
To make things more GPU/CPU efficient in the case where you have many shadows, you could simply put all the shadow sprites as child of a single SKEffectNode that will apply the effects on every shadow sprite all at once. I assume that positionning the shadow under the main sprite would not be a challenge for you.
Having the shadow as a child of the main sprite would force you to put an effect node for every sprite casting a shadow, and would cause the effects to be processed over and over. By putting every shadow as a child of the same node, they will get rendered all at once and the effect will be processed only once every frame.
I hope it helps!
SKShapeNode's are known to have poor performance in SpriteKit. Instead, you should add another SKSpriteNode for the shadow, and add it as a child to the main SKSpriteNode.
If you want the shadow to appear below its parent, you may have to adjust it's relative z-position as well.
I want to make a drawing app by using SKEmitterNode effect.
I know that SKShapeNode are used to stroke or fill a CGPath and I can use SKShapeNode to do it,
But what I want is using SKEmitterNode effect like following images to do the same work.
Is it possible ?
Yes, and this is a very good use of SKEmitterNodes.
First, you'll need to use Additive blend mode on your particles to get this effect.
And you should then set the pace (motion) of the particles to 0 in all directions, and not have them impacted by gravity. When they're emitted, they should be stationary.
The particle emitter should move with the touch of the artist/user, and emit at a rate slightly inverse to the rate of change in position of the emitter.
How can a particle emitter be set to produce shapes (solid shapes/Core Graphics?), instead of texture images (png)?
In the documentation Manipulating the Particle Emitter, it looks like only a texture image can be set.
Only a SKTexture can be used, but that doesn't stop you from using SKShapeNode to create shapes and then create a SKTexture of that shape via the SKView method textureFromNode:.
I'm creating a semi-circle node when i try to develop a simple sprite kit game, but i wish the physics body of the node just cover the circle object's edge, and the physics body rotates with the circle(to change the physics body programatically), what should i do?
You can do complex shapes using SKPhysicsBody -bodyWithPolygonFromPath:
There are even tools that let you draw your shape and generate the code for you. See this question for examples: SpriteKit's SKPhysicsBody with polygon helper tool
I am new to Objective-C and I am trying to make a simple spriteKit game which contains a circle and a ball inside it. I want to move the ball around in this circle as well on the iPhone movement. So far I have created the circle and am able to put the ball on the screen.
My problem is that I am not sure the ball is actually inside the circle or on top of it. When I attach a physics body on the ball, it drops out of the screen and does not stop on the circle's bottom edge. I am using SKShapeNode for both the circle and ball.
Please help me to provide the right documentation to go through or a little piece of code that can resolve this.
You need to assign appropriate physics bodies to your nodes. See Simulating Physics in the Sprite Kit Programming Guide.
From your description, it sounds like you need to create the outter circle's physics body with the bodyWithEdgeLoopFromPath: method (and provide a path representing the circle). Note that an edge loop physics body is not dynamic and can only collide with volume-based bodies.
The inner balls physics body can be created with bodyWithCircleOfRadius:.