Using Lua and a Socket Server to test and debug iPhone Games
Damn, too many balloons. Ops, just change the Lua code real time!
I already talked about #iDevBlogADay. But let’s say it again: I just love this “group”! The first thing I do when I wake up is checking the feed for the day’s articles. And how sad I get if an author hadn’t published his take yet.
Everyday we get 2 new nice articles from fellow indie (or established or beginners – like me) game developers. One of these articles “Tweak Away” from Mystery Coconut brings Lua and socket servers into your iPhone game development.
Main points you’ll learn from the article:
- How to open a debug server for your game.
- How to integrate Lua into your game and how it can access your game elements.
- Change your game behaviors and state via command line (e.g.: no more re-compiling to change the speed of a ball).
- Scripting all of your game content and behavior.
And yes, Miguel makes everything that easy for us :)
- Path finding class for a RTS game: ASIPathFinder. “ASIPathFinder is a complete implementation of a cooperative path finding algorithm, and will probably be most useful for writing Real Time Strategy games. It is written in Objective-C, and is compatible with Mac OS and iPhone OS.”
- Cocos2D, Path finding and Tile maps – sample app: cool working code which I found on Cocos2D forums.
- RenderTexture: let’s explain via an example: for a shooter game which leaves bullet holes, we could use sprites for these holes, but a RenderTexture is memory saver.
a) Sprites: 500 holes – 500 sprites – 1000 triangles – 2000 vertexes.
b) RenderTexture: will draw only one sprite – it takes a picture and work in that picture.
- EAGLView: create the OpenGL context.
Drawing with Quartz2D
- Save current context
- Perform a single combined matrix transformation
- Draw graphics to this transformation
- Restore context
Source: Beginning iPhone Games Development
- Sum of a scalar and a vector
- The quotient of two vectors
- Imaginary number: i * i = -1
- A quaterion is a complex number extension: 3 numbers all square roots of -1: i, j, k
- j * j = -1, k * k = -1
- q = w + xi + yj + zk (w = real, x, y, z = complex).
- or q = [w, v] (w = scalar, v = (x,y,z) – vector)
Source: http://www.gamedev.net/reference/articles/article1095.asp, http://www.paradeofrain.com/2010/07/lessons-learned-in-tilt-controls/
A* Search algorithm
- Transform anchor: coordinates used by Cocos to rotate objects on screen. For sprites, the default is the middle of the image.
- ccp(x, y) is Cocos shortcut macro to CGPointMake.
- Scene: a container of all the stuff you’re going to show on screen in a specific part of your game: Main menu, level, help, highscores (each one is a different scene).
- Hierarchy: Scene : Layer : Node : Node.
Cocos2D Scene and Layers
- A node can be a sprite, label, etc. Note that a sprite may have a child sprite.
- Add nodes to a layer with addChild method.
- Scenes have depth ordering (z): lower Z objects appear behind higher Z ones (er, ok, very old thing, we learn this when we are 8? but always worth noting :) ).
- Cocos auto dealloc all children.
- Run an action:
[node (sprite, etc) runAction:[CCSequence (or CCSpawn) actions:action1, action2, CCCallFunN (callback on the object when the actions are performed)]].
- How to load a sprite:
CCSprite *sprite = [CCSprite spriteWithFile:@"image.png" rect:CGRectMake(0, 0, w, h)];
sprite.position = ccp(x, y);
- UIKit: 0,0 from top left.
- Cocos2d: 0,0 from bottom left.
- Sprites: 0,0 from bottom left.
- Definition (b2BodyDef): The body definition holds the data needed to create and initialize a body – position, velocity, type.
- Object (b2Body): “body factory”: myWorld->CreateBody(&bodyDef);
- Shape (b2PolygonShape, b2CircleShape, etc): geometry you wish to simulate.
- Fixture definition (b2FixtureDef): binds a shape to a bodys. Shapes don’t know about bodies, that’s why we need fixtures. Defines:
4.1) Density (more dense, more mass = harder to move).
4.2) Friction (0…1 – how hard for objects to slide against each other).
4.3) Restitution (how “bouncy” is an object. 0 = no bounce, 1 = perfectly elastic).
- Fixture object (b2Fixture): b2Fixture* myFixture = myBody->CreateFixture(&fixtureDef);. A body may have any number of fixtures.
Cocos2d Image credits: Official wiki