Posts Tagged ‘Xcode’

Anybody who has used the iPhone 4 is no doubt blown away by the pixel density. The resolution cannot be described in words. One bit of confusion I had was how exactly to take advantage of the new high resolution screen. I found a useful article from Apple to help clear things up.
(more…)

Sparrow 2D Game Engine for iPhone

I stumbled across this new FREE open source 2D game engine for the iPhone called Sparrow. It is still in an early stage, but definitely a promising start. One of the advantages (or disadvantages) is it is written in pure Objective-C. Look for a full review and possibly a simple game example soon.
(more…)

I have submitted SpaceBubble to Google Code. Pick up a copy of the source code here!

Here is some example code based off my tutorial on how to implement orbital / radial gravity, but in reverse. This example pushes objects away instead of pulling inward. It makes for a nice explosion effect. Much work would need to be done to make it realistic, but you get the general idea of how to blow things up. You need to have Cocos2D and Box2D installed. Box2D comes packaged with the latest version if Cocos2D.




Download Source Code for this tutorial:
Bomb Demo Box2d & Cocos2d Example Source Code – 799k

The other day I wrote a tutorial on how to implement orbital / radial gravity with the use of Box2D and Cocos2D. I have decided to post the source code for this. You need to have Cocos2D and Box2D installed. Box2D comes packaged with the latest version if Cocos2D.



Download Source Code for this tutorial:
Radial Gravity Box2d & Cocos2d Example Source Code – 692k

I am releasing the Objective-C source code to my iPhone game SpaceBubble to the public! It is released under the “Take a kid fishing or hunting license” which means in order to use this code in your project you must take a kid fishing or hunting, and give credit and a link back to the author (me) in some way or another such as on your product web page, about box, or legal agreement.

I hope this helps you take the leap into iPhone game development. Enjoy!

Download:
SpaceBubble Source Code – 938k

Radial gravity, orbital gravity, orbital mechanics, whatever you want to call it there is no denying it can be useful for many kinds of games. Unfortunately, neither Box2D nor Chipmunk Physics Engines for the iPhone had support for it. I had a hell of a time trying to figure this out but in the end it was so simple. Here is how to do it.

First, create a new Cocos2D / Box2D Hello World project from the supplied Cocos2D templates. Add the following code to HellowWorldScene.mm and HelloWorldScene.h:

HelloWorldScene.mm

-(id) init {
//... Add at end of init after body->CreateFixture(&fixtureDef);
	// Create our static "Planet"
	b2CircleShape shape;
	shape.m_radius = 1.0f;
	shape.m_p.Set(8.0f, 8.0f);
	b2FixtureDef fd;
	fd.shape = &shape;
	planet = groundBody->CreateFixture(&fd);
}
 
-(void) tick: (ccTime) dt
{
	int32 velocityIterations = 8;
	int32 positionIterations = 1;
 
	world->Step(dt, velocityIterations, positionIterations);
 
	for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
	{
		b2Body* ground = planet->GetBody();
		b2CircleShape* circle = (b2CircleShape*)planet->GetShape();
		// Get position of our "Planet"
		b2Vec2 center = ground->GetWorldPoint(circle->m_p);
		// Get position of our current body in the iteration
		b2Vec2 position = b->GetPosition();
		// Get the distance between the two objects.
		b2Vec2 d = center - position;
		// The further away the objects are, the weaker the gravitational force is
		float force = 250.0f / d.LengthSquared(); // 150 can be changed to adjust the amount of force
		d.Normalize();
		b2Vec2 F = force * d;
		// Finally apply a force on the body in the direction of the "Planet"
		b->ApplyForce(F, position);
 
		if (b->GetUserData() != NULL) {
			CCSprite *myActor = (CCSprite*)b->GetUserData();
			myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
			myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
		}	
	}
}

HelloWorldScene.h

@interface HelloWorld : CCLayer
{
	b2World* world;
	GLESDebugDraw *m_debugDraw;
	b2Fixture* planet; // This will be a static body
}

And here is the result!

Enjoy!

Download Source Code for this tutorial:
Radial Gravity Box2d & Cocos2d Example Source Code – 692k

Here is some simple code to setup an animated sprite using a UIImageView. I used this in my game SpaceBubble and although it should be pretty self explanatory, I commented the code as heavily as I possibly could. This uses a class called Sprite that inherits from UIImageView. The only thing changed from a standard UIImageView is that there are values you can store in the sprite such as point values for coins in a game. setupAnimatedSprite really simplifies the process of creating animated sprites using UIImageViews. So simple in fact you can do it with one line of code! Enjoy! Feedback much appreciated.

(more…)

Twitter Me