I want to create a "solid" SCNNode, so when the camera touches the node, it will stop moving. I've tried physics but it didn't work. How can I do it?
This question does not help with the problem. I am going to assume you have a player object moving through a scene. If you want to disable the camera moving you have to set a condition for when the player collides with that solid object to stop the camera in update.
Related
In a mario-like platform game, when my Scene launches, I create a SKTileSet as well as a SKTileMapNode programmatically (using the editor is not an option).
For now, the map only contains the ground on which the player must walk.
I have successfully added the player as a SKSpriteNode, and added a physics body, so that the player falls from the sky, through the screen when the game launches.
The issue is, I can't figure out the best way to prevent the player from falling through the ground.
Should I add a physics body to each tile of the ground, or detect collisions and correct the position of the player? If I do so, why attach a physics body to the player at all, since I need to check and correct its position all the time?
I have an SKEmitterNode centered on my player to leave a trail of particles. My player has a physics body and it's moved by physics, not by manually updating it's position.
The issue I'm having is that when the speed of my player increases the particles are emitted from a point behind the player.
I discovered that this is happening because the particles are emitted in the "evaluate actions" part of the frame cycle. My player is afterwards moved by the "simulate physics" part.
The solution I found as a workaround is to move the SKEmitterNode (in the update callback) to the point where my player will be after the physics calculations. This is the code I used:
particleEmitter.position = CGPointMake(
player.position.x + player.physicsBody!.velocity.dx * dt,
player.position.y + player.physicsBody!.velocity.dy * dt
)
UPDATE
At first I had my emitter as a child node of the player, then is when I observed the problem.
I also tried to sync the emitter position exactly to the player position, without accounting for distance moved since the last update (velocity * dt), same problem.
My question is, what would be the correct way of solving this?
UPDATE 2
I've created a playground demonstrating the issue. Here I have the emitter as a child of the player. The more you increase the player's velocity the bigger the gap between the player and the emitted particles.
https://github.com/ovidiupruteanu/SKEmitterNodeTest-Playground
Here is the frame cycle from the apple docs
Your code only estimates the next position of the player. It doesn't consider other factors that may affect the player's position, such as collisions, force fields, linear damping, etc. I suggest you set the emitter's position to the player's position in the didSimulatePhysics callback or add the emitter as a child of player.
Rather than manually repositioning the emitter on every frame, let SpriteKit do that work for you: make the emitter a child node of the player sprite, and the emitter point will stay at the same location relative to the player whenever the player moves.
If you go this route, you might have a problem with the emitted particles also following the player in ways you don't want. You can resolve this by setting the emitter's targetNode to the node containing the player.
I have a sprite and a particle fire. Sprite is moving, so I want fire be at the same place as sprite all the time.
That's what I tried. _abcdis the name of sprite.
CCParticleFire *emitter;
emitter = [CCParticleSystem particleWithFile:#"suchfire.particle"];
emitter.position=ccp(_abcd.position.x,_abcd.position.y);
[self addChild: emitter z:10];
When I run the game, fire is located in the lower left corner. Any ideas?
Your sprite is moving after its position is assigned to the emitter. Remember that the position you're assigning to your emitter is not going to update with the movement of the sprite.
So the best way forward is to update the emitter's position as the position for the sprite updates. This can be done in your update method.
Or better yet apply whatever movement you're apply to your sprite, be it by the game or the user, to your emitter.
I want to be able to remove a tile from my game when my player touches it. The only way I have found is to hide the whole layer which is not what I want to do.
I have the collision detection working fine, I just need to be able to remove the tile on collision or when the player/sprite gets to that position.
Any ideas? Thanks.
You can remove tiles with:
[_layer removeTileAt:CGPointOfTile];
I have a SpriteKit Scene in which I want to have the effect as if a camera zoom and scale. Does anyone know of any libraries or some easy methods of doing this?
It was very easy to do in other 2D engines but does not seem simple.
I was thinking of doing it from the app delegate, and using the window to zoom since my character does stay around the same position.
The desired effect I would like to accomplish is like that of the start of an Angry Bird level when the camera pans into the level and then the launch doc.
http://www.youtube.com/watch?v=_iQbZ3KNGWQ This is an example of the camera zoom and pans I am talking about.
Thanks for the help.
If you add an SKNode to the SKScene, and make your scene content children of that node instead of direct children of the scene, then you can zoom and pan all of the contained content just by adjusting the xScale, yScale and position properties of the added node. (Any content you did not want scrolled e.g. scores or whatever could then be added to a different SKNode or added directly to the scene).
The adjustment could be done by overriding one of update:, didEvaluateActions, or didSimulatePhysics in your SKScene subclass. The choice would depend on if you are just moving your character around by yourself in update:, or if it also gets moved around by running SKActions or by simulated physics.