I'm planning to build a basic rebound iOS game in Cocos2D. Will Box2D be best suited for the following scenario?
The layout will consist of a target at the top of the screen, with obsticles in the middle of the screen, blocking direct view of the target from the bottom. The user will shoot a ball from the bottom of the screen by rebounding it of the sides and around the obsticles, aspiring to hit the target. Similar to a breakout style of game.
As the game levels progress, the obsticles will be moving dynamically, left to right and back, up and down etc..
I understand that the collision detection can be achieved using Cocos2D alone. Can the rebounding and trajectory of the ball off obsticles and walls also be achieved without using a physics engine?
I will have no need for gravity in the game scenario. A reduction in the velocity/speed of the ball will be essential.
Please note, I am new to iOS dev, coming from a background in front-end web dev.
Advise and help much appreciated.
Thanks
You certainly can do all that without using an existing physics engine. Once you start doing collisions with moving objects and objects of different shapes, though, it starts to become advantageous to use an out of the box solution.
It's easy to setup box2d without gravity and it will give you all of the collision calculations and velocity stuff
Related
I'm currently in the process of developing a very basic 3D OpenGL game in C++ as part of a small college project. We don't get a lot of insight from the teachers however, and only very limited documentation, as well as a small timeframe, so I'm kind of a little lost here at the moment.
My game is a tank battle on an orthogonal plane that pretty much looks exactly like the image I sketched below. Each tank (A and B) can be controlled by a different player, and each one can shoot projectiles, which are supposed to influence the other tank's score upon collision.
My question is, what would be the simplest way of effectively implementing collisions for the tanks? (Tank vs tank, tank vs map boundaries and tank vs any kind of parallelepipedic object like the one in the center of the picture - and the same thing but applied to the projectiles shot from the tank turrets).
Ideally, without the need of using an external physics engine, but also accepted if the implementation can be done easily. At the moment, I'm solely using the GLUT library.
Download and integrate Box2D (http://box2d.org) into your project.
Unless your project is to implement a physics engine, then don't bother doing it yourself. Your time will be much better spent learning how to integratate libraries and how proper physics engines work.
You can then easily use a box collider for your tanks, circle for projectiles and 4 lines for your perimeter. You can create callbacks to notify you when a projectile has collided with another tank.
You will have to use forces and torques to move and rotate your tanks, rather than just updating their positions. But you would probably have to do that anyway if you were going to implement the physics yourself.
I’ve tried my best searching online and reading the documentation to find a good answer, but I have yet to find one.
I’m creating a multi-platform 2d side-scrolling retro game in Cocos2d-x v3. The engine is rather new to me, but I do have decent experience in C++, Xcode and game development.
The game which I’m trying to create is utilising super minimal pixel art and I’m at a loss as to decide which approach would be best. Currently I have two ideas:
Work with a fixed resolution (e.a. 240x120, I’m working with
really(!) small sprites) and use Design Resolution to scale the entire canvas
upwards to the screen size using kResolutionNoBorder.
Pros: I don’t have to scale my sprites and I can just use a short piece of code in the Init() function.
Cons: Not sure if you can use Design Resolution to scale pixel perfect?
Scale every sprite so that it appears to be running on a ±240x120
resolution.
Pros: ?
Cons: I have to scale every sprite which means more code and less clarity as to what is really happening on my canvas.
I read the multi-resolution-support page on the Cocos2d-x wiki, but it didn’t really give me advice on what would be the best approach for retro games.
I feel that I don’t have enough knowledge about Cocos2d-x to make the right decision yet, and a voice in my head says I’m forgetting something important.
There are more factors at play. How do want the game to look that are diffrent from 240*120.
I'll suggest scaling the screen for pixel art games. You can also control aliasing/anti aliasing param for all texture. Generally for pixel game, anti aliasing is turned off.
KResolutionNoBorder might crop your game edges to fit it in. There are other options,like kResolutuonFixedHeight, kResoltuionFitAll, depending to game requirement and HUD placement.
Well, it still can look pixel perfect in large screen, cocos2dx uses float for the size and position, so even if 1 pixel in your design view is represented as 5x5 pixels on the screen, when you move the position 0.2 point it will look like it moves 1 pixel. How precise it can be depends on the device screen resolution.
I would go for scaling the canvas
I'm using Cocos2D, or more specifically Cocos2D-x to make a platformer-shooter game. I already have the platformer part, but I want to make my character shoot. I've seen in many ios games characters are able to shoot wherever they want and I wonder, do they make tons of sprites for this, because they can also fun while aiming at other sides, or do they sort of bend their sprites. How can I achieve this effect? Thanks
This SO question deals with rotation.
I believe it's feasible to compose a shooting figure from a sprite featuring the body and another sprite, which rotates on top of a joint and is composed of arm and gun. Does it look good? There's definitely some artistic skills required to make the joint look natural. An alpha channel could be enough though -- or some people deliberately make the heroes wear futuristic armors with spherical joints.
I am currently developing a game for iPad & iPhone using Cocos2d with Box2d.
It would have been majorly cool to achieve a lighting effect like the one in this video:
http://www.youtube.com/watch?v=Elnpm-gNI04
and on this link:
http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/
I could have a go at trying to replicate the effect with Cocos2d and Box2d from the description in the link, but I am unsure if I would be able to get very far. It looks pretty advanced and heavy.
How can I achieve this in an "easy" way? Does anyone know of a Cocos2d-version of something like this, or do anyone have some pointers to point me in the right direction?
http://code.google.com/p/box2dlights/
I have succesfully made dynamic light library that use box2d geometry and rayCasting. My library work under gles1.0 and gles2.0 and use libgdx as framework. This is peformant enough for giving dynamic real time lights to 2d games for mobile devices. I can help with porting that to Cocos2D. Basics are darn simple. It was under 100 lines when I first hacked it working for my own game.
Example:
Point light shoot from center n number of rays around it and record the closest collision points. These collision points are used for mesh that is colored with gradient and drawed with additive blending.
Try to look at this link.
http://www.cocos2d-iphone.org/forum/topic/27856
He successfully added simple dynamic light using cocos2d + chipmunk following the technique that Catalin Zima used.
Please note if you download his project and try to compile iOS build, then remove "Run Script" build phase as you may experience script didn't found error. More info to remove such phase can be seen here.
I am working on a simple 2D openGL project. It contains a main actor you can control with the keyboard arrows. I got that to work okay. What I am wanting is something that can help explain how to make another actor object follow the main actor. Maybe a tutorial on openGL. The three main things I need to learn are the actor following, collision detection, and some kind of way to create gravity. Any good books or tutorials to help get me in the right direction would be great.
You could use a physics library like Chipmunk Physics, which lets you attach springs and things between the two objects and detect when they hit each other and other things.
A pre-rolled library would be good, but the concepts you describe are ones you need to know if you are going to do any sort of game programming anyways:
A simple way to make one actor follow behind another is to have the lead actor store its position every time it moves. Feed these positions to a trailing actor with a delay of a few values - the longer the delay, the further behind they travel. Simple, but doesn't handle dynamic collision (other actors moving the block collision.)
Collision detection in 2D can simply be axis aligned (AA) bounding boxes. Search for this and you'll see the 4 ifs or so that are needed.
Gravity is just adding a fixed velocity (usually down) to every object every game loop. This is constant acceleration which is exactly how gravity works.