Cocos2d. Sprite and progress bar tight connection - ios

Start to learning Cocos2d and have a question. With moving of the sprite I need progress (health) bar keep moving with them (slightly above the sprite), with keeping it position relative to the sprite like if it was one sprite. Any ideas how to realise?
Thanks,
Alex.

add the health bar as a child to the sprite, at the required offset from the soldier's body. When you later move the soldier, the health bar will follow.

You can add the health bar sprite as a child of the other sprite:
[sprite addChild:healthBar];
You can position the health bar sprite as usual, but the final position will be relative to the parent's anchor point (which by default is located at the center of the sprite).

Related

iOS: move circle shape view by collision by dragging another?

I have two UIViews shaped like a circle. (see image).
I am trying to figure out how to make the two views move by collision.
So I am moving one with a touch by changing it's position as I move my finger on it. I want to see the other move as I "push" the one I am moving against the other circle shaped view.
What is the correct way to achieve this?
Using SceneKit did the trick. I created the geometries and then applied physic bodies to each. With the proper physics configuration in the scene they now collide.

Revolving animation using cocos2d ios

I need a animation like revolving electrons on three orbiter path i the middle of nucleus. I am currently using cocos2d 3.2V for developing my game. I tried to make revolving animation using bezier path but this work for quadrant of circle not make a complete circle animation. How can i achieve this kind of animation using cocos 2d?
Thanks in advance
The center is your parent node, you add the orbiting nodes to the parent with their position at an offset like 40x0, then rotate the parent and the child will rotate around it.
If you need different rotation speeds simply add multiple parent nodes to the center, one for each "planet".
If you want to make the movement an ellipsis you can cheat to some extent. You can have the parent move slightly up and down (or between any other two opposing points) synchronized with the rotation.

Scrolling combined with physics moves my sprite out of the screen

I'm implementing a side scrolling game with SpriteKit:
As long as my sprite stays in the middle of the screen, I'm moving the sprite
When the sprite reaches the left or the right part of the screen, I'm moving the level instead of my sprite:
This works quite well, unless my sprite collides with another object. In that case the level (triggered by my code) and the sprite (triggered by the physics engine) are moved and the sprite moves outside the screen:
I tried to stop the impulse which is applied from the physics engine. This hasn't worked.
Any idea how to handle this?
Thanks
Stefan
I suppose by "moving the level" you mean moving the background view.
Why don't you just have an area in which your sprite moves that is the same size as your background? You can scroll to keep the sprite visible without disturbing the logic of physics and other manipulation of the movement.

scale around certain point over time SpriteKit

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.

How to partially animate sprite in Sprite Kit?

I have a large sprite. I want to animate parts of it. Obviously I don't want 30 images of said sprite, I want only the difference, that light blinking or something.
How do I handle that? So far using many images for sprite animations has been way to go for me.
A SKSpriteNode can have children, so you can overlay as many as you like on top of a given SKSpriteNode.
For example if you had a christmas tree, you could put 20 lights on the tree by just adding a child SKSpriteNode for each light and positioning it appropriately. You could then have each of those lights animate independently and dynamically.
You can create you sprite with something like layering.
In practice it will be looking like sprites (that will be animated separated) under 'big' sprite that you do not want to animate.

Resources