Problem regarding CCFollow and CCParallaxNode - iphone

I have a problem regarding CCFollow. I am using CCFollow along with CCParallaxNode. I have added layers to parallax node and then apply runaction: on parallax node.
[pn runaction:[CCFollow actionWithTarget:sprite worldBoundary:CGRectMake(0, 0, 5600, 320)]];
but using this the sprite always runs at middle of screen. Is there any way to keep it at left of screen and also layers follow this sprite?
Thanx.

If you want your player to remain on the left side of the screen, then lock the players X position to a specific region that makes sense. You should also be moving the background and other elements of your game, not your player (with exceptions, to the players position visually on the screen).

Related

Problem animating the position of a GameObject in Unity while moving it

I am working on moving a Cube across the screen when I press an arrow and display two different animations depending on if it is moving or idle. I used a very basic translation to do this when I press the right arrow. I have two different animation states that work fine independently. One spins the cube when it is “idle” and the other makes to bounce up down in the “right” state. Both are 1 second animations. The idle animation spins the cube 360 degrees, and the right animation will move the cube up 1 unit then back down to its original position. Everything works well by itself. I included an image for the states for the animation.
Cube Animation States
In order to get the movement working with the animations I made an empty GameObject and made the cube a child if it. When the cube is idle it spins, and when I press right it moves and bounces up and down. The problem is when I release the right arrow the cube snaps back to its original position from the start of the last bounce animation. If I hold right for 10 seconds, and release it will only snap back to the beginning of the most recent iteration of the bouncing animation (not to when I started pressing right).
Does anyone know why this would happen? I tried changing some of the settings for the transitions, but it doesn’t seem like that is the problem.
Can you check that your idle animation modifying its position in any case.
First, you can't move the game object with animation.
you can have the rotate animation in the cube but not the translating part.
Because when the animations switch between the states the object will be moved to its original position.
solution:
-Create a script and attach the script to that game object.
-use translate functions to move the object

How do you wrap a level around based on the players position

I want to create a circular room in a 2D level. How can I handle this problem?
My thought process was to break the level into chunks and move their position depending on where the player currently is. This would allow the level to wrap around depending on where the player travels. I can do this manually with each part but i'm looking for a better solution that can handle this programatically. I'm open to better ways to solve this problem as well.
Is the space 2D? if so, you could place two invisible colliders at the extremities of the room (one at the beginning and one at the end), and change the player's position when he collides with them. To ensure that the transition is smooth, place them a little outside of the camera space: the player won't be rendered during transition, and you would obtain a teleport effect from side to side.
As another suggestion, you can lock the player to being in the center chunk with a camera just showing that chunk. Everytime he gets through a collider on the end or the start of the middle platform you delete the opposite side platform and place it in the far end of the platform the player is now seeing, effectively making the new platform as the middle one.

Make a Defender-like "world" with SKTileMapNode

Defender is an ancient game that presents a virtual world, a horizontal scroller, in a loop. The camera view only portrays a portion of the world at any given time. The player can fly in both directions around this world, continuously.
How could this be achieved with an SKTileMapNode Layout of the world?
My first thought is to have two instances of a SKTileMapNode that illustrates the whole world, and abut them in space where and when required as the player flies around the world.
Here's a map of the Defender world highlighted at the top of the screen:
The minimap in the screen shot you show indicates it is not endlessly scrolling, it’s just really long, with only a small part visible at any time.
Doing this with SKTilemapNode would involve one SKTilemapNode and adding tiles only for the ground, which you could then attach physics bodies to. The background could be a single image or multiple images to create a parallax effect or you could go with a black colour background and stars created with SpriteKit Particles.
An alternate approach would be to use two background images and position them programmatically so as one image scrolls offscreen, it is moved left or right (depending on which way the user is scrolling) to appear adjacent to the other background image, giving the appearance of an endless scrolling background.

To follow a ball character like monkey kick off game

I am working on a game which has working similar to game monkey kick off. I have one ball bouncing on a place at the left side of screen and depending upon the position of the ball I apply linearImpulse to the ball on user touch so that it appears that the ball is kicked.
But what happens is when i apply impulse the ball goes out of the screen bounds. I dont want the ball to go out of the horizontal screen bounds whereas it can go out of the screen vertically.I tried using CCFollow but it doesn't give the realistic feel to the game flow.
I tried THIS tutorial, but dint help much.I managed to scroll the background,Only this part remains.
Any Ideas on how the ball should not move out of the horizontal screen boundary..? but in case of vertical boundary on the other hand it can go out of the bounds.
If you're not using physics, it's a simple bounds check. Assuming the screen width is 320 points this will keep the ball inside the screen horizontally:
CGPoint ballPos = ball.position;
ball.position.x = fmaxf(0, fminf(320, ballPos.x));
ball.position = ballPos;
UPDATE: I noticed you mentioned linear impulse. So you're using a physics engine. In that case, create a horizontal wall on both sides. See the cocos2d Box2D or Chipmunk templates how to enclose the screen with a collision border, then use only the left and right side borders in your game.

Cocos2d - Top down camera view with rotation

I'm trying to create a top down car game where the camera follows both the player and the player's rotation. I can get CCFollow to work easily, but I have had no success with CCCamera. I assume that I need the camera in order to make rotation follow the player (i.e. have the player facing up at all times) but I have had no luck on google.
Can anyone either provide a code snippet or a tutorial on how to create a rotation-following top down camera?
Cheers!
My suggestion: don't use the CCCamera.
Your game design requires the car to move over a track. In programming terms this is often much easier accomplished by keeping the car static, and instead moving the background underneath.
Assume your car is at the center of the screen. It's supposed to move from left to right. Instead of moving the car or the camera, move the background layer - just in reverse: move the background layer from right to left to make it seem like the car is moving from left to right.
The same is true for rotation. If you want the car to turn left, rotate the background in clockwise direction.
This is a lot easier and can be accomplished simply by changing the position and direction properties of the background layer. Note that you do not need to do this for each object in the background layer, it's sufficient to add all objects to the background layer in the appropriate positions and then just change the background layer properties. The layer's children will follow accordingly.