Simple 2D iPhone game with cocos2d - tips and tricks

I would like to create a simple 2d game: there is a car in the middle of the screen, and the background goes back, which creates a feeling of car speed. The road has a mountain and downhill, so the car must follow its shape. The user can accelerate and break. That's all!

I did some research and found cocos2d. I downloaded it, read the tutorials and studied the examples, but to start developing my simple game, I still have questions that I have no answer to.

How do I create a road (2d) to put a car on it? How to move the background (and the road) from right to left to feel the speed of the car? How do I create a car?

I do not want to have source code as an answer, but theoretical tips, good tutorials and examples. Thanks!!

+4
source share
2 answers

I highly recommend you buy Steffen Itterheim's book Learn Cocos2D on Amazon . It helped me get started by reading it and playing with its source code: http://www.learn-cocos2d.com/ If you don't want to spend money on the RayWenderlich Tutorial Series. There is a team that works with him, and there are many tutorials on how to create your first game (check them out, they are very good!): Http://www.raywenderlich.com/tag/cocos2d . To move a car, this is simply a CCSprite object that moves during the update method. The position refers to abstract coordinates (width 0-320 and height 0-640), and you can set it using the position property (sprite.position = CGPointMake (10.0f, 200.0f) will place your sprite in pos x: 10, y: 200). you need to add a sprite as a child of the scene and schedule Update in the init method, and there is logic to move the sprite according to the input (you can choose accellerometery input or select some cool controllers like SneakyInput . For more on this, see Steffen's book :).

You should add โ€œParallaxBackgroundโ€ as a separate layer and make it move by scheduling updates. This is the same concept as a car, but with a different input (you do not need a controller, but the input will relate to the position of the car. You can get the car as a child from the parent node using the parent .getChildByTag (CARTAG)).

This is a little strange, but I hope to give an initial idea.

+1
source

If you want a realistic result, you can use box2d or chipmunk (already built into cocos2d) to make physics make the car act like those objects in "Doodle Truck" or "Tiny Wings". There are quite a few textbooks on the Internet. Of cox, which requires another setup and settings for the game to work properly. Otherwise, you need to think about the data structure of the "road", which makes the car know that this should be the angle of rotation. I think this is the hardest part of this simple game.

To move the background, it is simple and should have many possible ways. The simplest thing I can think of is to set the position in the frame in accordance with the current speed of the car.

Creating a car: you can create a class representing it, including CCSprite in it, which handles animations, rotations, flip .... and everything related to the display of the car.

0
source

Source: https://habr.com/ru/post/1435108/


All Articles