title: Tilemap-based level editor wishlist

text:
# Question
Title: Tilemap-based level editor wishlist
I'll be likely writing one this year. It will end up having unique design so things turn out on its own anyway.

Though, what an experienced level designer would want from a level editor? Requirements? Key features? Things that could be worth the time spent into implementing them?

# Answer
Not yet mentioned:

* Autotiles (so the designer can draw freely, and have the application set the correct corner tiles).
* Plugins (so I can develop in-house format exporters/importers and tools, etc.)
* Cross-platform (so designers are not forced to use one specific OS.) This, for me, would be one of the most important requirements.
> 7 votes

# Answer
* Loading in custom tiles
* Setting map size
* Setting tile size
* Square tilemaps, hexagon tilemaps, or other shaped tiles
* Save/load map
* Layers
* Animating tiles
* Tile properties (walkable, swimable, etc.)
* Events (depends if you want to add this; i.e. player steps on tile at x,y and does an event)
> 7 votes

# Answer
**Plug-in Editor**
I would just like to reiterate the value of creating a plug-in based editor. Jeff Ward pointed me in this direction a few years ago when I started working on an editor.

Creating such an editor will allow you to remain agile in development. Inserting a new component into the system should be a painless experience. Requirements will come up where you didn't expect them and having this kind of architecture will save you time in the long run.

And, tbh, from a developer stand-point -- this was pretty fun to experiment with. :)

**Easy-to-use Event Editor**
I wouldn't want to see one window with a thousand checkboxes, comboboxes, etc. Give me one window that does one thing. Imagine right clicking on a door and selecting add event. It recognizes it's a door and opens a 'Door' dialog. Well, what do we do with doors? We go places. Have a drop down of other positions the player can go. KISS

**Dungeon Creator**
It would be handy if I could start designing a dungeon, or even island, from a random start-point.

**Improved Tile Placement**
Say I started drawing the exterior of a castle or the coastline of an island. Imagine, for the island, that I needed to go around the island with the coast tile. If I could hold shift and set the coast tile all around the island, that would be slick.

**Database**
What I use for one game, I'd like to use for another game. Create a way for me to store my characters, items, monsters, spells, etc into a database.
> 5 votes

# Answer
Often overlooked issues from the user's standpoint:

* Stable, nothing worse than an editor that crashes
* Reliable Save/Load
* Auto-backup
* Level integrity check (does the map have everything the game needs to run)
* New Level creates a loadable level from scratch (spawn points & whatever the game needs)
* Ability to create, save, and place collections of tiles (Prefabs)
* Ability to copy/paste/move/rotate arbitrary selections of tiles
* Ability to rapidly swap a placed tile with a different type of tile in that same location
* Keyboard shortcuts, preferably customizable.

On the coding side:

* Plug-in architecture for ease of expansion to future needs.
    + Allows multiple people to add features simultaneously and release them independently.
> 4 votes

# Answer
My big wish list feature is the ability to easily make a large map "stitched" together from 'rooms'. Basically a map editor designed specifically for a metroidvania style game. Editing many separate smaller maps by hand and dealing with markup or configuration files for specifying how one map links to another is tedious. I'd love to be able to simply make a huge map but section it off with markup and export it as submaps for implementation/efficiency/etc.
> 2 votes

# Answer
**Multiple Map Sets**: This could server for having the world on one map set, the dungeons on another, and the houses/caves/etc. on yet another. You could even have multiple worlds (i.e. Balanced, Ruined, etc. like the old Final Fantasies).

**Character/Boss/Enemy Positioning and Properties** We are probably going to want to set where the player and enemies are in the editor. It would be great to be able to edit their properties on the fly (i.e health, defense, current items, etc). This would also help with testing.
> 2 votes

# Answer
Something I would put as very high in a level editor "goal" would be to avoid ANY situation where starting the map from scratch is easier than correcting a mistake in the current map.

I've seen this happen with a lot of the tools i write for myself or even in other bigger tools(like tiled) where it is very hard to replace a tile set with a new version of it, or even change the size of the map.
> 2 votes

# Answer
Something that can top this? :)

http://thetoolsmiths.org/2009/02/24/sweating-the-small-stuff/
> 0 votes

---
Tags: 2d, tools, tiles
---


# Question
Title: Locate the shortest path through obstacles when all normal paths are blocked
I'm making a Tower Defense and I have basic pathfinding working, but I got a problem.

I want to make the path blockable, and when a block occurs the runners will attack the blocking towers.

So what I need is a way to find the shortest path that, more importantly, has the lowest number of towers in the way.

How do I do that?

# Answer
In your path scoring just make it so passing through a tower costs the same as going through some big number of tiles. In general it will try to get around them, but if there isn't such a path the output will still be going through the least number of obstacles. You can tune the penalty so that sometimes they will just go through instead of going all the way around the map if you want too.
> 22 votes

---
Tags: algorithm, path-finding, tower-defense
---


# Question
Title: Is it necessary to wait for rendering thread to terminate in surfaceDestroyed(...)
I just wrote a simple Android app that uses SurfaceHolder.Callback interface to communicate the state of the SurfaceView. In the Callback.surfaceDestroyed() method i just informed the rendering thread to terminate and returned, like so:

```
    public void surfaceDestroyed(SurfaceHolder holder) {
    renderingThread.requestStop();
    }

```

I did this because in the Android documentation SurfaceHolder.lockCanvas() it states that a null will be returned when the surface is not available. And also that the SurfaceHolder holds a lock internally until SufraceHolder.unloackCanvasAndPost() is called, which prevents calls to SurfaceHolder.Callback methods.

So to me it seems that it's not necessary to wait for the rendering thread to finish. However all examples I've seen wait for the thread to finish, usually something like:

```
    public void surfaceDestroyed(SurfaceHolder holder) {
       boolean retry = true;
       rederingThread.setRunning(false);
       while (retry) {
          try {
            thread.join();
            retry = false;
          } catch (InterruptedException e) {
        }
     }
  }

```

Is this really necessary? My application runs without problems.

# Answer
One reason to follow what most of the examples do is because just because the current implementations allow for this usage, it doesn't mean future implementations will. It's better to code defensively and to what the API is documented to do rather than what a particular implementation does.

In this case, you already have working code that's been implemented the correct way. Just toss it in your code and then you don't have to worry about it again.
> 2 votes

# Answer
I believe for the most part it is just good practice. Imagine if it was a thread that did a lot of heavy IO. If you simply killed the thread, you could potentially cause data corruption if it was in the middle of writing to disk. Now for a rendering thread, I'm not sure what the consequences would be. Memory leaks? It really just depends on what all is happening in your rendering thread.
> 1 votes

# Answer
I'm not sure that your code needs to wait the end of renderingThread but it is a generic approach or a Best Practise.

I use `renderingThread.requestStop()` too without problems.
> 1 votes

---
Tags: android, multithreading
---


title: Real-time Debugging Techniques

text:
# Question
Title: Real-time Debugging Techniques
There's nothing quite like the routine of tweaking a variable, compiling code that takes a few minutes, executing the code, realizing that your tweak was in the wrong direction and repeating the process all over again.

I would like to start interacting with my game logic while a session is in progress. What are some of the ways you've handled doing this?

I would be open to hear solutions for iOS, C/C++ and C#/XNA.

# Answer
Just discovered this for iOS Developers -

**AsyncSocket**
You set up a server in your application and connect to it via terminal. You can then pump over remote commands and start manipulating variables in real-time. Pretty slick.
> 12 votes

# Answer
Integrating a fully interpreted language can allow you to rewrite game elements very, very easily on the fly.

Python, Lua, etc. can all be utilized expressly for this. Angel Engine probably can serve as an example.

Hot loading is another element to check out (basically, an event is fired off telling you an asset has changed--a config file, an art element, etc.--and you run it through a series of conditioners that modify it for the final format before replacing the existing with the new.

I've worked with a rapid prototyping engine that used hot loading and it was a pleasure.
> 4 votes

# Answer
Well as far as C++, C#, and C# with XNA are concerned, Visual Studio has excellent debugging tools--pause the application in real time at any point in the code, see the values assigned to variables at any time, step through function calls, analyze the call stack, and more. In addition, tools like Pix and the CLR Profiler make development with DirectX (Pix) and CLR based languages (CLR Profiler) great.

In addition, one especially useful part of working with games is that we have this giant area to write debug text, graphics, etc to. Realtime graphs of memory usage, number of objects/vertices drawn, framerate, etc are common things to draw to the screen.
> 3 votes

# Answer
In C/C++ a simple trick is to put your tweakable into a static variable, trigger a breakpoint, change the static in the debugger and it remains persistent until exit.
> 2 votes

# Answer
**HTTP Logging** is a huge help, and not difficult to get up and running. You can even use Google App engine as a quick way of getting this running. Data is always useful.

**Scripts & XML** these can be reloaded on the fly and require no reset. Allow them to fail without bringing down the game. This gives a lot of power to artists, testers and designers.

**In-Game Debug Menu** A simple in game debug menu which you can spawn as a child and freeze the game with both engine sliders and game sliders. Allowing you to tweak key numbers at runtime and maybe perform one or two debug functions, or info dumps.

I also love ASYNC sockets as mentioned in David's answer

**Easy to USE** Your games team must be able to add to these tools and use them very easily, or they just won't get used.
> 2 votes

# Answer
I know Sean James already said it. But seriously, Visual Studio (specifically the debugging tools) is terrific for this.

I don't use C++ much these days, so I'm not sure about how well these apply there. But for C# (including in C# Express) you have:

* Edit and Continue \- where you can make wholesale changes to your game logic.
* The Watch Window \- where you can see and modify variables with ease.

And this might blow your mind (it blew mine when I found out about it):

The Immediate Window is actually kind of hard to find (it's in the Debug/Windows menu).

The only major downside to using the Visual C# debugger is that it doesn't like changing `const` values. So I usually just make my gameplay-related values `static` while I'm tweaking them.

(Also: having two monitors helps a lot.)

---

Now I must admit that the above method involves pausing your application - which can be unsatisfyingly slow for a few particularly fiddly things.

On these rare occasions, what I do (in XNA) is to simply hack in a bit of code (probably using Edit and Continue, as above) to grab `Keyboard.GetState().IsKeyDown()` (actually I have an easier-to-type wrapper for this) and adjust the value by keystrokes. Anything more complicated is not worth the effort.

---

In practice what I usually find *vastly* more important is being able to **visualise** (rather than modify) values in real-time. For this I have a nice little class that can buffer lines and text to be drawn at the end of the frame. It's also useful for quick prototyping.

(And, once again, it's nice to be able to "Edit and Continue" these visualisations in at runtime.)

<sub>(source: andrewrussell.net)</sub>
(from here)

I'm afraid I don't have "nice" source to publish at the moment (maybe later). But it's basically just a list of lines (for this round line library) and strings (for XNA's built-in SpriteBatch). Just make it `public static` somewhere, and draw everything with an appropriate transform so that everything appears in "world space" (and then clear the lists for the next frame).
> 2 votes

# Answer
Writing a simple reflection system for C/C++ is fairly trivial. This way you can browse through all your variables in game (be it with a network tool, keyboard or joypad) and change them to your heart's content. It works for me, but all the above answers are equally valid.

Edited to add: This thread is now about tweaking, not debugging as per the thread-title.
> 1 votes

# Answer
One solution I've seen in multiple studios is an external debugging app that attaches to your program using the network. This app shows specific exposed variables, and allows you to edit them in real time. Adding new variables is a matter of adding some macros to the game code.

The initial set-up of the game-side macros, server/client protocol (the solutions I've seen just serialise xml back and forth), and writing the client, is large. However it's extremely useful, especially as using the network for communication means you can work on any platform.
> 0 votes

# Answer
Bind the loading and reading of the variable into a textfile and fire it up using a specific keybinding or command from console.
> 0 votes

---
Tags: networking, debugging
---


# Question
Title: How do I set up my modifier system without casting?
I am trying to create a system that can easily modify objects on the fly. For example, lets say I have an `Entity2D` that inherits from `Entity`. `Entity2D` has a `Position` property. I also have a class called `ModifyPosition` that inherits from `Modifier`.

Here is the code:

```
public class Entity
{
    /// <summary>Applies the modifier to this entity.</summary>
    /// <param name="modifier">The modifier to apply.</param>
    public void ApplyModifier(Modifier modifier)
    {
        modifier.Apply(this);
    }
}

/// <summary>Modifies an entities position</summary>
public class ModifyPosition : Modifier
{
    /// <summary>/// Initializes a new instance of the <see cref="ChangePosition"/>
    class./// </summary>
    /// <param name="position">The position.</param>
    public ChangePosition(Vector2 position)
    {
        this.Position = position;
        this.IsModifyingChildren = false;
    }

    /// <summary>Gets the position.</summary>
    /// <value>The position.</value>
    public Vector2 Position { get; private set; }

    /// <summary>Applies this change to the specified entity.</summary>
    /// <param name="entity">The entity.</param>
    internal override void Apply(Entity entity)
    {
        ((Entity2D)entity).X += this.Position.X;
        ((Entity2D)entity).Y += this.Position.Y;
    }
}

```

---

If you are calling this multiple times per second, I would think that the casting would slow it down. Is there another way to go about this, without having to cast?

# Answer
> 6 votes
To expand on my comment from earlier and give you a full answer:

**A good way to modify values on the fly is to modify them directly using C#**

It sounds like what you're trying to implement is something like Klik & Play or Unreal Kismet (and to a lesser extent the level-entity-triggering system from Unreal and some other engines).

What you need to keep in mind is that these systems make sense for companies like Epic because they (and their licensees) are creating enormous volumes of content - and it's cheaper to enable a non-programmer to make it dynamic, than it is to require a programmer to do it. (With volumes like Epic's - even a entry-level programmer working in a managed language like C# or UnrealScript is expensive enough to justify such a system.)

For the rest of us who are *not* making AAA middleware - making a system like that is just cargo-cult engineering. (And if you *are* making that kind of middleware, this is not how I'd approach it anyway.)

Basically you're adding a layer of indirection to your programming. Every time you want some new functionality *you're going to have to program it anyway*. Except you'll also have to wrap it in a new Modifier class (including, presumably: serialization, editable properties, considerations of re-usability, etc), and then add it to your level and link it up. And you lose the magic of version control, refactoring support, debugging, etc. And heaven help you if you want to modify a Modifier - have fun checking all your levels still work!

(By the way: I learned all this the hard way - which is why I'm being so opinionated about it.)

So that's my little rant about your architecture out of the way. What should you do?

Well you *already have a fantastic editor*: it's called Visual C#. In a very basic sense you should just give each level in your game a class/.cs file - and dynamically instance that class when the level starts (or whatever makes sense for your game).

And all the time you save not making your Modifer system, you could spend adding nice features like on-the-fly recompilation. (By the way: if you're concerned about end-user modding - remember that Visual C# Express is free, and the C# compiler comes with the .NET runtime.)

As to particle systems, which you mentioned in your comment: Are you nuts? Where did you see that? Particle systems need fast throughput - and I don't see that happening with a virtual function call and a cast, and using reference types for each particle!

In the ideal CPU performance case, a particle system should have a tight loop that moves through an array of structs containing a position and a velocity vector. Actually - better yet: a single draw call that gets the GPU to handle it all in a vertex shader.

---

Just to give you an idea of what I'm talking about, here's what your ball example might look like:

```
public void LevelStart()
{
    this.Walls["magicWall"].OnTouch += (touchedBy) =>
    {
        Ball ball = touchedBy as Ball;
        if(ball != null)
            ball.Color = Color.Blue;
    };
}

```

# Answer
> 8 votes
You really shouldn't need to worry about this unless you are doing this millions and millions of times per frame. This graph shows some empirical data about the speed of casting:

Source: "Type casting impact over execution performance in C#" by Emilio Guijarro, 2004

Keep in mind that there are about 17 milliseconds per frame at 60 frames per second, and about 33 milliseconds at 30 frames per second.

# Answer
> 1 votes
While I agree with the above that I wouldn't do it this way, and that you should measure actual performance hit, it's beside the discussion.

To me the cast kinda tells me your setup is wrong. For one, what if the cast fails?

I'd definitely advise you to look into interfaces and/or 'observer/visitor pattern'.

Alternatively wonder about a class Modifiable, where then that vector2 can derive from (instead of entity), so you know you're type-safe. Have your entity have a ModifiableVector2 as a member and work on that?

# Answer
> 0 votes
Speed it up:

```
internal override void Apply(Entity entity)
{
    Entity2D entity2d = entity as Entity2D;
    if (entity2d)
    {
        entity2d.X += this.Position.X;
        entity2d.Y += this.Position.Y;
    }
}

```

The "as" cast is faster and returns null if the object can't be casted. You also avoid the second cast but don't ask me if the if statement is faster, slower or equal than the cast. Honestly, I couldn't care less unless you know this to be an issue. Which it won't. That I'm 99.9% sure of.

Anyway, the "as" cast with null-pointer check is a C# best practice. It won't crash if at one time the entity really is just an Entity, not a Entity2D.

You could also write a Modifier class which runs Apply only on Entity2D objects if you're that worried about performance. Or change all your game entities to be of Entity2D and also change the Modifier class. It's a matter of trading off memory vs. speed.

---
Tags: c#
---


title: How should I start playing with 3D?

text:
# Question
Title: How should I start playing with 3D?
One of my hobbies (aside programming, of course) is 3d modeling (completely amateur, using 3ds MAX) and I'd like to mix programming with 3d modeling (what a marriage!). So I've read a little about it and figured I'd have to have good notions on geometry, math, point spacial position (which I do, from my 3d modeling experience), but I don't know how to use API's for it, so I've 'simulated' simple 3d with some simple programs I've made (first a spinning cube, then a more complex Labyrinth (or maze, if you will)).

---

**NOTE:** I have no intentions on harming anyone's computers. If you don't trust it, use a VM or something. Once you run it, I'd appreciate if you commented here stating that the EXE's are safe. Thank you.

---

Here are some questions:
**1)** What would be a nice 3d development tool for a .NET programmer like me?
**2)** Is there a way of using 3d models made in 3DS Max ? (I intend on modeling characters)
**3)** What knowledge should I have in order to render it, and move it around ?
**4)** Which API should I use ?

The development environment would be nice if it:

* Had the possibility to import existing 3D models exported by 3DS MAX (not a must, but a plus)
* Had the ability to create 3d models programmatically (a must)
* Possibly has a tool for materials and textures (that would be a huge plus)
* Is Well known (high availability of tutorials, questions in S.O., forums..)

And it would be really nice if I could use C# all the way :)

---

**EDIT**
For the ones that asked if I want to do something more UI-guided, just to mess around with some models, and not learn about how to create a game-engine, I say no, that's not the case.

If you download my Labyrinth little game, you'll notice that I've basically MADE a simple renderer from scratch using DrawPolygon on bitmaps created via code. So that's a clue that what I want is to learn, and that I somehow like the idea of mixing images and codes together, along with some user interaction.

Imagine that I have a model, say the weighted companion cube, and I want to make a full-screen, or windowed lil' program that spins it (much like the crappy spinning cube I've made a while before the other one), setting the position, the position and angle of the camera, velocity, a simple ambient (say a simple monocolor box (which would be a room) drawn maybe through code (not an imported model)) and editing it with simple user interaction (say pressing left or right on the keyboard changes direction, or pressing '+' would make it faster), all that without using a wizard or something, but coding.

Now for those that didn't quite get my intentions in here, I hope this example makes it clearer of how powerful and customizable I hope it should be. If there are any more questions, let me know!

---

**EDIT**
I'm going to start with UNITY, and I've noticed there's a pro version, is the free version enough to do what I want ? (not counting on the 1 month free pro account)
As for XNA, does the same scenario apply as well ?
Please leave a comment!

# Answer
Unity ( http://unity3d.com/ ) is a good start. It's got C# as one of its core languages, there's a standard workflow for using 3DSMax models, it's got a certain amount of drag-and-drop for rapid prototyping, and there's a free version with somewhat-limited functionality so you can try it out. It's got a supportive community and some tutorials, and creates cross-platform apps.

While it has material and texture creation support, it doesn't have built-in modeling, programmatically or otherwise. I've used Blender in my experimentation, as it's free and I'm somewhat comfortable with it, and I'm sure you can do algorithmic modeling with it (though you'd be coding in Python). If you've got an acceptably legit copy of 3DSMax already, I'm pretty sure it plays well with Unity as well.
> 6 votes

# Answer
Not quite as simple as Unity, but XNA is Microsoft's big push for making games in C#. 3DS should be able to export FBX files and the XNA dev environment can import those. Tons of tutorials and libraries available.
> 6 votes

# Answer
Both Unity and XNA are fine choices, but if you have a passion for learning things (as you imply you do), maybe you'd enjoy using OpenTK. It's an up-to-date .NET wrapper for the OpenGL API + input + window creation functions.

Dealing with OpenGL directly is as low-level as it gets, and, in my opinion, a very rewarding learning experience. I started out learning OpenGL, then moved to higher-level tools (such as Unity). Having direct experience with a graphics API can help you understand what's happening "behind-the-scenes" and be "more at home" when using a higher level tool/framework.

Alternatively, you may wish to start learning, using SlimDX, which is a DirectX wrapper.
> 5 votes

# Answer
My vote goes to Unity as well. It's much more starter friendly than XNA and there's a lot of support out there. XNA on the other hand will (if you persist) give you a more solid game programming background as less is done for you automagically. So again it depends - do you want to play (and make games, it's more than capable) with 3D, or learn to program 3D? If play, Unity. If learn 3d, XNA.
> 2 votes

# Answer
Unity will get you displaying models out of 3dsmax in seconds, and you can focus programming efforts on interaction/gameplay. You can get into more depth on the 3D side if you decide to start custom programming shaders, but you won't need to do that. You can use the scripting to do model instancing if that's interesting to you.

With XNA you can also get a model up fairly quickly, but you'll be working at a lower level, and without a visual editor for setting up scenes, if that's important to you. You'll need to personally handle setting up a camera location and the associated transforms and draw calls if your are going to do anything besides just render a basic mesh.

Either way you can use C# and you'll get stuff up on screen quickly. There isn't a single right call here, it's just a question of what you are interested in learning. Do you want something a little more nuts & bolts to learn more about the coding of 3D engines, or do you want to put together some simple games/viewers and mainly want to focus on getting your 3D art in some distributable format.
> 1 votes

---
Tags: 3d, c#, .net
---


# Question
Title: How to allow character to keep moving after it hits a wall
I am developing an iPhone game. There is a fountain that the user should not be able to walk through. Now, this question is about checking circle-point collision or anything like that. I am checking collision with `CGRectIntersectsRect(character1.frame, fountain.frame)`.

But, here is the problem: If I prevent the person from moving; he will never be able to move. So, I tried combatting this with following:

```
    if (character.center.y > fountain.center.y && CGRectIntersectsRect(character1.frame, fountain.frame) && g == false) {
        g = true;
        character1.center = CGPointMake(character1.center.x, character1.center.y-0.1);
    }
    if (character.center.x > fountain.center.x && CGRectIntersectsRect(character1.frame, fountain.frame)) {
        character1.center = CGPointMake(character1.center.x-0.1, character1.center.y);
    }
    if (character.center.y < fountain.center.y && CGRectIntersectsRect(character1.frame, fountain.frame)) {
        character1.center = CGPointMake(character1.center.x, character1.center.y+0.1);
    }
    if (character.center.x < fountain.center.x && CGRectIntersectsRect(character1.frame, fountain.frame)) {
        character1.center = CGPointMake(character1.center.x+0.1, character1.center.y);
    }

```

This should check what side the character1 is intersecting the fountain and then make it so it is not intersecting the fountain by incrementing or decrementing the x or y coordinates of the characters it. But, this still gives weird results. It will move it diagonally across the fountain if keep holding down on the the top side of the fountain and also, it will keep moving it left other wise on the top of the fountain.

# Answer
Speaking generally, the way this is handled is by moving you backwards along the collision normal. You find the axis the collision took place on (normal is a physics term, just think of it as the vector indicating the direction you penetrated the other object. Then you figure out how far you have to move back on that vector to no longer be colliding. See gpwiki for more information.
> 6 votes

# Answer
I would check for the collision before the character is moved to the new position. So that when you update the position of the character you know that it's valid.
> 1 votes

---
Tags: iphone, algorithm, collision-detection
---


title: Tools to make icon, icon design

text:
# Question
Title: Tools to make icon, icon design
I have two related questions:

What are the tools you use to make icons? (valid for all platforms)

What are the standard sizes and file formats you use? (valid for all platforms too)

# Answer
+1 for IcoFX, makes it super easy to convert PNGs to Windows and Mac icons. It can also do editing, but there isn't much reason to use it over Photoshop or GIMP. Make your files 256x256 (512x512 wouldn't hurt though) to start with, IcoFX will resample for you and do the color space conversion. Since IcoFX only runs on Windows, you can use Icon Composer on OS X (it comes with XCode). Both tools can produce both Windows' ICO and Mac's ICNS format.
> 4 votes

# Answer
There are great free online tools to convert so you don't have to install anything.

Icons are usually square with the following sizes:

* 8x8, 16x16, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512

On the iPhone the game icon would be:

* 57x57 - iPhone icon
* 72x72 - iPad icon
* 114x114 - 2x for iPhone4
* 512x512 - app store icon

Windows Standard Icons Guide

Windows Icon Design Guide

* Use 32x32 pixel for content area icons; 16x16 pixel for footnote area icons. In-place
* Use 32x32 pixel for error pages; 16x16 pixel icons for all others.

OSX Icon Guidelines

* A 128 x 128 pixel image (for Finder icons in all versions of Mac OS X)
* A 512 x 512 pixel image (for Finder icons in Mac OS X v10.5 and later)
* A mask that defines the image’s edges so that the operating system can determine which regions are clickable

Win vs. OSX Icon Specs (slightly outdated)
> 4 votes

# Answer
I use Photoshop to make the icons, and export as PNG. Icons are typically 48x48 or 32x32 in Windows, 16x16 for the title bar/favicon, and 256x256 for Macintosh dock. I use IcoFX to convert to .ico
> 2 votes

# Answer
The Gimp is a nice, free alternative to Photoshop, and I've used it to make various icons. It should be able to natively save .ico files.
> 1 votes

# Answer
i personally use paint .net and icon plugin
> 1 votes

---
Tags: graphics, tools
---


title: Scaling HUD with variable resolution

text:
# Question
Title: Scaling HUD with variable resolution
I'm unsure as to what people prefer when it comes to HUDs, and scaling them. What would you say is the best practice when it comes to sizing the HUD? I'm thinking there's really two options: Scale up, or use the same area (in pixels) to display it on a higher resolution.

The problems I see with each are with scaling, I may have a huge blurry mess in the corner, but if I don't, it could be hard to see from a distance. Any guidance?

# Answer
If you're making a PC game you may want to consider giving the player control over UI scaling themselves. For instance most MMOs allow the user to add a UI scale to make everything bigger. This is because the dpi of a PC's display can differ heavily from person to person. Some players like everything to be tiny, but many other players will be physically unable to read the text at that scale. If your HUD can be deconstructed as multiple "windows" you can probably scale each window seperately, while attaching it to the correct point on the screen (bottom middle, upper left, etc).
> 5 votes

# Answer
It depends, if your HUD is an integral part of the design you'd obviously want to scale it up (or rather down - mipmapping and multiple versions of the same resource will somewhat alleviate the quality loss problem). If it's merely to get information to the user I'd try to steal as little screenspace as the HUD allows while at the same time ensuring maximum readability as your assets won't be blurred.

An alternative is having a fully 3D/Vectorized HUD, in that case you won't suffer quality loss as it always gets rendered to native resolution.
> 12 votes

# Answer
As Kaj mentioned a 3d modeled HUD is a good solution because it can scale. It also has the benefits of allowing you to 'shake' the player by moving the camera position around slightly (think of a car crashing and the drivers head slamming forward -- you can give the player some of this effect with just a few frames of movement).
> 1 votes

# Answer
Something that will help when designing your HUDs is to use normalized screen coordinates rather than pixel coordinates. If you use pixels, you need to account for all the possible resolutions you want to support... no fun.

Instead, choose and origin (say, the bottom left of the screen) and call it \<0, 0\>. The top left of the screen would be \<0, 1\> and the top right would be \<x, 1\>, where x is dependent on the aspect ratio. For example, at 1680x1050 the aspect ratio is 16:10 so x would be 1.6.

Now you can design your UIs in normalized screen coordinates and they won't be stretched/skewed when the aspect ratio changes, and they'll scale perfectly regardless of the resolution. The only adjustments you might have to make are for 3 or 4 aspect rations (4:3, 5:4, 16:10, and 16:9 probably). You can even alleviate that by allowing things to be anchored to the right hand side of the screen.
> 1 votes

---
Tags: resolution
---


# Question
Title: Storing game state at exit on the iPhone with Objective-C
How would you store your game state at exit for an iPhone game written in Objective-C?

# Answer
Here is the method I used in my games.

First, every object that needs to be persisted must implement the NSCoding protocol. You want to only store your model data and nothing specific to the current process. This means that you can't persist pointers or any resource ids that the OS gives you at runtime. For the pointers you can fix this easily by just making sure that you encode the objects that they point to instead of the pointers themselves. For other resources, you will need a way to hook up your object to the new resource at runtime.

Second, make sure that all of your game objects can be accessed through a single root object. This object could be a master object for the entire game state, for example. Another possibility is that you could store them in one of the Foundation collection classes (NSMutableArray, NSMutableSet, NSMutableDictionary).

When you get notified that your application is moving into the background (applicationDidEnterBackground), you will need to use NSKeyedArchiver to save the entire state to a file. That file should be in the documents directory for your application. Here is a bit of code to show how that is done:

```
NSArray *docDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [docDirectories objectAtIndex:0];
NSString *saveFile = [docsPath stringByAppendingPathComponent:SAVE_STATE_FILENAME];
[NSKeyedArchiver archiveRootObject:gameState toFile:saveFile;

```

When you detect that you have gone back to the foreground, you should remove the save file to prevent any confusion the next time your application is launched.

On application start up, you need to check for the existence of the save file. If you have one, you load it up like this:

```
NSArray *docDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [docDirectories objectAtIndex:0];
NSString *saveFile = [docsPath stringByAppendingPathComponent:SAVE_STATE_FILENAME];
[gameState release];
gameState = [[NSKeyedArchiver unarchiveObjectWithFile:saveFile] retain];

```

Depending on your design, you may need to walk through the game state and re-connect up any resources that you could not persist. This really depends on how cleanly separated your model code is from your rendering code.

At this point, you may want to put your game into a paused state, depending on what kind of game you are making.

Hopefully this helps someone else out there who is trying to implement game saving on the iPhone.
> 7 votes

# Answer
How to store game state is a complex question that's heavily dependent on how you set up your game itself.

On the iPhone specifically, you would just have to hook into `-(void)applicationWillTerminate:` in your `UIApplicationDelegate` to catch when the application will exit, from user action or otherwise. You have a short amount of time to do your work before the OS will kill your process, though.
> 2 votes

# Answer
That would largely depend on how your game was coded. Are you keeping track of a few ivars or something more substantial?

If it's just a few ivars, I'd probably write them to a plist on background and load that upon startup.

If there's more ivars, you might be better off with CoreData (and/or saving their values as they change instead of trying to fit everything into the close window).
> 1 votes

# Answer
The same way you save it when the user bumps a save-game without exiting.

Is this question about how to save game state? Or how to do something at app-exit?

For the latter, the answer is: appWillTerminate (or appWillResignActive.) In iOS4 or later, you can request extra time (Google "iOS-4 request extra time") if your save-game takes a while.

If you're asking how to save game-state at all, I'm a big fan of NSDictionary to store values easily re-read by the game-engine on continue.

```
NSMutableDictionary *saveDict = [NSMutableDictionary dictionary];
[saveDict setValue: [NSNumber numberWithInt: currentScore] forKey: @"currentScore"];
// etc...
[saveDict writeToFile: saveFilePath atomically: YES];

```

If you want, you can add a "signature" (*i.e.*, like md5 or similar) to verify on game continue to make sure that someone hasn't mucked with the file to try to cheat.
> 1 votes

# Answer
I would say don't. Save it when it makes sense for the game, not when the app is exiting. For example, if this is a turn based game, then save at the end of each turn. If it's a level based game, save at the end of each level. There a couple of reasons for this:

* Mobile usage is very unpredictable. Yes, you get notified by the iPhone SDK when the app is closing, but it could be in the middle of anything, and the transition is not just "exiting" it is also receiving a call, getting a text, etc.
* You have very limited time and resources to shut your game down on app exit. Most of that will probably be consumed just with pausing your game and cleaning up memory. No need to add to that load by saving game state.
* Most games have natural pauses that make sense for saving. You can take advantage of these pauses to seamlessly store game state, and the user will never notice that you are consuming extra resources.
* By saving incrementally during game play, the amount of data to be saved will be smaller per save.
> 1 votes

# Answer
Here's an example of how to implement the NSCoding protocol for some example "map" and "player" classes:

http://deadpanic.com/howtosave

Then you can save the objects using Dennis' NSKeyedArchiver method.
> 1 votes

---
Tags: iphone, objective-c, state
---


# Question
Title: How to know when to use UIViews and other Quartz2d features and when to use OpenGL ES?
When starting a new 2d project on the iOS framework, it seems pretty to start creating UIView subclasses and having fun with Quartz to create very quick prototypes, but I am guessing there will be times where it will be impractical(or impossible) to use such powerful(and wasteful compared to openGL ES) abstractions.

I know a couple dozen subviews work allright, but there must be a point where having more than X is just impossible to keep a good frame rate.

How do you know if it would be a good idea to drop the UIKit and start doing some more powerful stuff on openGL?

# Answer
In my own game I use a combination of UIKit and Cocos2D (which is OpenGL ES based, for those not familiar with it).

The first iteration of my game used UIKit for menus, and then a game screen that was Cocos2D based. The game screen had buttons on it, as well as dialog messages that would pop up. These were all done in Cocos2D.

Over time, I have gradually replaced much of my Cocos2D code with UIKit, so that the game play screen is about 2/3 Cocos2D and 1/3 UIKit.

I have learned to love and use both frameworks for different reasons.

This has several advantages:

1) It's easier to have a consistent UI throughout the app. I was having to write code that would make my shiny UIKit buttons look just like my shiny Cocos2D buttons. Now they're all UIKit.

2) The UIKit API is stable. The best thing and worst thing about Cocos2D is that it is changing (improving!) so fast that I found myself constantly updating my code to support new features and API changes. Now the amount of code that gets affected by those changes is a lot smaller.

3) I have seen no performance loss by doing it this way. There may even be some memory gain because UIKit is pretty efficient with its use of resources when memory gets tight.

4) Development on things like pop-up messages and dialogs is a lot faster, because I can do those in Interface Builder. I don't need to think about how to lay out the dialog screens in code.

5) I don't have to reinvent the wheel on basics like buttons and tables.

After developing this way, here's my rule of thumb:

1) Use UIKit for everything that doesn't require OpenGL. Menus, messages, buttons, tables, etc. Core Animation does a good job on 80% of what I need.

2) If I find myself writing something that I have seen in UIKit, stop and try to think how I can pull it out of the OpenGL view.

3) Certain things like complex movement, particle effects, etc. are perfect fit for OpenGL/Cocos2D, so that's where I put that effort.
> 4 votes

# Answer
Isn't Quartz2D more for User Interface / Charts / Drawing Shadowed Text?

It depends on what you're building. I've built game projects using Core Animation and I've just now started to dip into Cocos2D/OpenGL ES. The most I was doing in my projects was scrolling a background and allowing the player to manipulate views (drag and drop). The moment I thought about particles I figured I would slow the system down to a halt. Animations seemed to work well enough. But, again, I wasn't doing much.

If your game is simple enough you could very well ride with Quartz2D. But if you're thinking about 50 enemy ships and particle effects already, I'd look at OpenGL ES and save yourself the headache. Might as well learn it earlier rather than later.

I have to look at projects like Cocos2D and think that OpenGL ES would be the better route to go if you are serious about developing some graphical intense game projects.
> 2 votes

# Answer
I would say that it's time to switch when you run into something you can't do or it's too slow. Switching anytime before then is just wasted time. And if you are doing this for yourself, you don't want to waste a lot of time.

As for the speed of UIViews, I've found them to be very respectable -- you're not going to want to use them to put up 100s of sprites and particles on the screen at once, but there are certainly quite a few games you could get away with using nothing outside of Cocoa. If you find yourself on the edge, you can use CALayers directly to reduce some overhead.

Another thing to remember is that the OS caches the contents of your layers. Even if the item beneath a layer is redrawn and that layer has transparency in it, it doesn't mean that layer will be redrawn. I've watched layers in my code to see how often their drawInContext: method is called, and despite tons of things going on, most of the time it will be once. The OS does a very good job with minimizing draw calls.
> 2 votes

# Answer
I've found that trying to maintain even 20 FPS with UIKit is difficult when you have more than 10-15 moving objects. Adding and removing UIviews is also slow, and keeping the necessary uncompressed UIImages in memory is expensive.

Probably good for puzzle or board games, but go with Cocos2d for anything with more moving parts.
> 2 votes

---
Tags: iphone
---


# Question
Title: Is there any significant differences in programming via PALIB over Nintendo's official DS SDK?
My brother has taken an interest in making games on the DS (via PALIB). I'm worried that since its a homebrew game and homebrew development on the DS is not officially supported, his programming would go to waste.

Is there any significant differences in programming via PALIB over Nintendo's official DS SDK?

# Answer
> 4 votes
Unless you've been employed in a company which is into DS development, there is no way you are able to have access to the official DS SDK. Using PALib is the next best thing for hobby developers to get into DS development. His efforts won't go to waste, the programming skills and experience he will learn upon completing a game is invaluable and will be an excellent addition for his portfolio to be included in his resume.

# Answer
> 1 votes
Well, if his goal is to gain experience working with an embedded platform, I don't see any reason why working on homebrew games would be a waste of skills. Any skills he picks up there will transfer over to any other portable platform, such as working within memory constraints and on odd systems (DS's two screens and 2 processors). I recommend everyone do a bit of embedded device programming at some point, even if you don't do it professionally.

The DS's life as a commercial system is reaching near it's end so I wouldn't choose now to go into commercial DS development as it is. It's also fairly difficult to acquire an official DS SDK even if you are a semi-professional game developer with published games. As a result I do not have specific information on the DS (Nitro) SDK.

# Answer
> 0 votes
It depends on how you look at it. Being developed by different parties there's bound to be differences in library calls and some data structures. Given that they're both addressing the same hardware and thus the same problems there's a lot of overlap too. Switching between library a and b is a lot easier than switching hardware paradigm, so working with PALib is a valuable lesson if you aspire to work for a NDS developer I'd think. As for being able to use his actual code - well, higher level utility libraries would be fairly portable if set up properly (C is C regardless of platform), lower level code would definitely need a rewrite. The extent of it I can't comment on - even if I could, I couldn't. NDAs and stuff. As Ben Ziegler said, getting a NDS licence is no trivial task, although I know it's possible even for very small studios, you'd need some serious history in game development.

---
Tags: homebrew
---


# Question
Title: How do I handle Isometric collision detection?
I would like to make an isometric run-jump style platformer. The player should be able to jump on top of platforms above the floor, hit the side of objects etc.

I'll be using a 2D game engine so I wouldn't like to emulate full 3D collision for dimensions I'm not using.

I'm thinking objects in the game should be placed using: X, Y, width, height, and Z for depth.

Using those values, how should I detect collisions?

# Answer
2 options:

* You could treat it as a 3D game with a fixed orthographic camera. Then you could use any standard 3D games resources / books / tutorials / libraries. Even if it rendered in 2D with sprites, the maths for movement etc would still be 3D behind the scene. This would give you the most accurate results.
* You could treat it as a top-down 2D game, with an added height property. For example, imagine a 2D grid where each tile has a height value. When moving from one tile to another, you only let a character pass to a particular tile if the character's feet are above or equal to the height of that tile, but if they are jumping and gravity brings them down on top of a tile, you let them remain there. With a bit more work you could make it so you can walk under bridges etc.
> 19 votes

# Answer
There are a lot of ways you could simplify this. For example, if you didn't allow layers (for example, a bridge you can both walk over and under, you could do all the collision detecting in X/Y dimensions, where you filter the collision set to anything of its height+depth or higher.
> 4 votes

# Answer
If the game is based on a rectangular grid, then this grid defines your X/Y axes. And Z can be used for height.

Collisions are then as more-or-less as easy as any 2D tile-based game.

Then you just need to convert from the grid back to isometric screen coordinates for rendering. This is fairly straightforward - but you may need to think about calculating 'depth' values, for sorting purposes (rendering the isometric scene from back to front)
> 2 votes

# Answer
Googling around I find this demo: http://planetskill.com/iso/

> WASD to move. Space bar to jump

It only implements collision with the up/down axis but adding the other collision should be easy:

If the up/down position of the next step is higher than your max just don't move. This should also let you implement jumping in a easy way.

Sample code here: http://gist.github.com/478997
> 2 votes

# Answer
All of the above. Isometric is just a sheared 2d grid so treat it as a 2d tilemap and think of a way to encode depth. How would you do that in a regular 2d game (being able to go behind or in front of blocks when 'jumping'? You'd either store a depth per tile (depth buffer-\>z buffer) or you'd use multiple layers, or, if you want fancier, you'd implement a callback per tiletype (or mapposition) and would be able to do whatever you want, check depth, check equipment, warp player around, have player slowly move up, format HD.
> 2 votes

# Answer
Well you could have a separate collision layer above your level that is not visible and use that to check for collision.. You can also use this for multiple layers as long as you know on which layer the player is ;)
> 1 votes

---
Tags: collision-detection, isometric
---


# Question
Title: How can I take advantage of the iPhone 4's higher resolution screen?
I've recently tested an OpenGL ES based 2D game on the iPhone 4. I've done almost all of the development and testing so far on my 3G device. The game works fine (except for a few multitasking things) on the new device. I'd like to replace some of the artwork w/ "better" artwork that takes advantage of the iPhone 4's higher resolution. How can I do this?

Is there a flag somewhere that tells the phone to scale up some or all of the image resources?

# Answer
Apple's Documentation: Supporting High-Resolution Screens (requires iPhone developer account)

Some basics:

* Add "@2x" to your filenames for high resolution files. So you'd have myTexture.png for low-res and myTexture@2x.png for high-res.
* If you're using UIImage to load in graphics, imageNamed:, imageWithContentsOfFile:, and initWithContentsOfFile: will automatically look for @2x files on the iPhone 4. Otherwise you have to load them yourself.
* For OGL ES change the "contentScaleFactor" property of your view from 1.0 to 2.0 to increase the size of the renderbuffer.

There's more to it than that depending on what you're drawing and how you're drawing it. The docs are super handy in that regard.
> 4 votes

---
Tags: iphone, opengl-es
---


# Question
Title: How to have a successful beta test with a small team?
I've done a lot of work (pro-bono) on a patch to a commercial game from ~11 years ago that needs some beta testing. Loads of people are waiting for it.

What are some ways to get **good** (by that I mean useful) feedback during the beta test phase for a game? I've got lots of people who want to play with it, but I'm concerned about getting good feedback without getting bogged down in the development. I'm also concerned that people will be more concerned about having the tweaks they want to see added to the patch than really testing the work that has been done.

* Do you provide the ability to log bugs directly into a bug tracker, or send them all to a person on the development team?
* How do you ensure you cover all the platforms you support (in my case: Mac OSX (x86/ppc), Windows (multiple versions), Linux (multiple versions)?

Are there any good software packages (like a web portal) for running a beta test for a project like this? Any good documents out there with tips?

# Answer
I would strongly suggest having an in-game bug-filing option, preferably a big button that says "FILE BUG HERE". Players who are engaged, especially if your game is actually good, are never going to remember bugs that occurred if they have to go out of the engine to file them. You could have those go to the bug tracker, or you could just have it email a holder address. The main goal is to make it easy to file stuff, although this may not be possible for an 11 year old game. In that case I would support both direct email and a website link, and maybe force the testers to go through some trivial front end that exposes a "file a bug" button so they remember it exists.

One good way to do this could be to semi-publicly expose your bug tracking software itself. Most bug tracking software (Trac is a good free one if you don't have one set up already) already has a good web frontend, and you could open that up to everyone in the beta directly. That way your beta testers can literally do QA for you.

To get platform coverage, you could try going directly to those communities. Make sure to discuss your beta on PC, mac, and linux-focused forums. That way you'll make sure to get a few from each group. You should ask players to specify what platforms they have available in the beta application as well.

Lastly, you may consider sending out some sort of "status of the test" email periodically. Something like "Hey, we just changed the weapon balance, can you guys focus on levels 4-7 for today? levels 8-10 are still being worked out and will be a bit better next week." Anything you can do to focus the testing process will work out to your advantage.
> 8 votes

# Answer
As far as getting good quantitative info, if you have the development time, add as much logging as can be analyzed.

* What % of your beta testers ever came back?
* How long was their (longest, average) play session?
* Where did they stop playing (what was the last action logged)
* What % of people encountered the new content?

etc

As far as data collection, (http://docs.google.com) has a pretty easy-to-use survey tool - just use the Form-\>Create a Form menu item.
> 1 votes

# Answer
If you're using Flash or Silverlight then I would recommend integrating Google Analytics or something similar. Using Analytics it's easy to instrument your game and measure things such as play time, where players are quitting, etc.

Additionally, I would recommend using a service such as Flash Game License's "First Impressions" or just going to Amazon's Mechanical Turk directly. I've found for $1 you can have a player try your game for a few minutes and provide feedback across a number of categories. If you use Mechanical Turk you can design your own form and ask the questions you're interested in.

If you combine both methods you can get a great deal of information for relatively cheap. Of course make sure you know what you want to measure before you start spending money. Finally, I have heard that some people will release their games to a portal such as Newgrounds using an alias and then use Analytics as well as a built in form to collect feedback from players.
> 0 votes

---
Tags: testing, project-management, beta
---


# Question
Title: Should beginning/indie game developers target multiple platforms initially?
Partially as a response to How do game developers target multiple platforms (Xbox 360, PS3, PC and Linux)? but mainly because there are people on here with published games, should cross platform be the first requirement/feature for a developer trying to break into the business? I have always been a believer (in a totally procrastinating sort of way) in picking either a 'niche' or 'mass market' platform and porting later if demand justified it. Cross platform always felt like an artifical barrier to entry. Why shouldn't we all write iPhone, Windows, or Browser games?

# Answer
> 9 votes
Especially if it's your first serious project, getting something (anything) actually completed is going to be your biggest challenge. The more barriers you can remove from that goal, the better.

If you're really serious, to give some thought to making your game port-able. If it's a stand-alone Windows application and you're doing your own rendering, don't write everything straight to DirectX. If you ever want to do something that's not Windowx/XBox, you'll need to rip all that out. And that's an unpleasant process once you've stopped looking at the code for more than a week or two. Put in some amount of abstraction if you think seriously think you'll ever want to port it.

That's assuming you've written your own engine, of course. All things being equal, I'd start with Unity or something similar. It removes a lot of those initial barriers for you.

# Answer
> 3 votes
I would agree with you on this one. If you spend all of your time building a cross platform game, it will never get out the door. I think it's best to try to predict which market it would succeed best in, and built your game to target that marker. If the game does really well, then you should consider porting it to other markets that make sense. If the game doesn't do well, and you think it could do well on another market, you might consider porting it anyway.

# Answer
> 3 votes
No. The whole idea about being an indie is that you can do what works for you, or what you believe is best (for your game, for you, or for your audience). The whole idea about being indie is that there is no 'must', 'should', or 'have to'. Make a game - your game. If it's a hit, or if you, after doing it, feel the need to port it, by all means. If it's not extremely targetted to specific hardware, or in some esoteric language, the main idea should be portable enough regardless. You're an indie, do your thing. YOUR thing.

# Answer
> 2 votes
Ruling out consoles briefly, I believe there's no reason the majority of PC games could not be developed for Windows, Mac and Linux simultaneously. Provided you put the work in at the beginning to get a system agnostic platform to work with, there's not going to be any huge blockers, and there will be advantages.

* Compiling your code for different systems will show you issues that may have otherwise gone undetected. This can be simply from different compilers warning about different things, but also via the use of other tools not available for other platforms, like valgrind.
* Larger audience, while Windows might have a huge platform share, the small communities of Linux and Windows are starving for games. And there's much less competition
* Working with an existing rendering library is going to make things easier anyway, why not choose one which lets you easily target more platforms, Ogre3D for example.

Of course there is work involved, but I believe there's also a vast, largely untapped potential.

I'll also note that I agree with previous answers, targeting many platforms with your first application might be a stretch, but I'd suggest keeping it in mind anyway.

# Answer
> 1 votes
> Should beginning/indi game developers target multiple platforms initially?

For a beginner, I would suggest no. A beginner wouldn't have any idea what is and is not cross-platform.

Worst case scenario is you implement something that *you* thought was cross-platform. Weeks later when you compile on other platforms, you find out that it was broken. You'll either ignore it (gonna get the game working) or go back and revisit that code.

> Why shouldn't we all write iPhone, Windows, or Browser games?

Complexity increases fast. For every platform you wish to support, you'll have to create one additional code path.

---
Tags: architecture, cross-platform
---


# Question
Title: How do game developers target multiple platforms (Xbox 360, PS3, PC and Linux)?
How do game developers target multiple platforms at once? For example, Xbox 360, PS3, PC and Linux. For 2D games, is it possible to also target the iPhone? I'm be interested in engines used (2D/3D, etc), how the build pipeline is setup and generally how much of the "core code" can be centralized without having to write platform specific code branches.

Or, if completely separate code trunks are usually maintained for each platform, how are libraries / code reused (in terms of linking and modularization)?

# Answer
> 11 votes
For commercial console game development, setting up a build system to target 360, PC, and PS3 simultaneously is irritating but is not particularly difficult. The 360 dev kit is simply a new a new target for Visual Studio + some tools and uses a very similar compiler to the standard windows MSVC++ compiler. The PS3 uses a GCC compiler back end but plugs easily in to the visual studio front end. For gameplay and general utility code, it should generally be possible to have code that is 99% the same between the 3 platforms. There ARE some incompatibilities between GCC and MSVC++, but luckily if you work those out linux (assuming you use a gcc version close to the PS3 one) will not be too much more trouble on top of that. The last 1% of code that differs you can normally fix with kludgy #defines. You can actually have the same visual studio solution build PS3, 360, and windows builds, so you can have them entirely integrated at that level if you wish.

Past the basic build steps, the big hurdle is going to be the graphics systems as well as any high performance elements of your game. For these elements you're realistically going to end up writing platform custom code, or using an existing engine. Memory will be a huge issue but that's for another question. A commercial project I worked on was able to get console versions of an originally PC source base up fairly easily, but making them actually perform well was a completely different problem.

If you wish to integrate iPhone as well you may want to go with some sort of existing engine/middleware solution. The iPhone setup of openGL + objective C doesn't really fit very well with any other platform. That's very much a choice on Apple's part, as they are heavily discouraging the use of interpreted middleware in any iPhone applications.

# Answer
> 3 votes
For most platforms, you can write subsystems which abstract away from the specific APIs used to call out and get information back from the platform you're running on. IO APIs are usually the easiest to abstract - all file systems work on some pretty basic assumptions about opening, closing and reading from files, even when you factor in asynchronous calling. Then you have your core systems like reading controller input, querying the time, accessing memory and thread primitives, most of which work the same way.

Even graphics can be abstracted to a large extent, and indeed in most good engines they are. But you have to package up the 'renderable' things into black boxes where you aren't allowed to know what's going on inside them. You know that you have a 'thing' which you render in a particular position in the world. You don't know how it's rendered, just that it is. And the graphics abstraction layer takes care of all of the details of getting it on-screen. The platform specific build pipelines package up the graphical data in such a way that it can be referenced from the engine without really knowing how it's represented internally.

All that said though, when it comes down to actually shipping a game, there are certain parts that you just can't abstract away. It would be ridiculous to think you could ship the same code on iPhone as you would on 360 or PS3, as the input mechanisms, fundamental way of operating, and platform capabilities are just too different. You could make an iPhone sized title on 360, but it would have to limit its input mechanisms to only those that the 360 can support. So, a virtual cursor on screen simulating a finger, and possibly using the joystick where the 3D accelerometer input is used.

More sensibly, parts of the game can be written in a re-usable way, and individual code modules can be ported between platforms, even though the majority of the title is different. For example if you have an AI state machine, that doesn't really care whether it's running on 360, PC, or iPhone. Your game will use many such components, and as long as they've been designed well so that they take well defined inputs and outputs, then the rest of a game can be wrapped around them, regardless of platform, and avoid having to rewrite those components.

That re-usability is the key to a cross platform development, not looking for a one-size-fits-all engine which works on all platforms. Even if such a thing did exist, it would be so crippled by having to work on the lowest common denominator, it wouldn't be of much use to make games with.

# Answer
> 0 votes
A way is using a multiplatafom engine such as Torque or Unity3D. But I don't think they work on all those plataforms. There's also another way: developing one engine...

---
Tags: cross-platform, xbox360, pc, linux, playstation3
---


title: Why use asset manifest files?

text:
# Question
Title: Why use asset manifest files?
Sometimes you'll see people recommend that rather than using graphics/sound files/etc. like this...

```
// Game code
Image myImage = new Image("path/to/image.png");

```

... you should use a *manifest* file as a level of indirection instead:

```
// Manifest file
MY_IMAGE: path/to/image.png

// Game code
Manifest myManifest = new Manifest("path/to/manifest");
Image myImage = myManifest.getImage("MY_IMAGE");

```

What reasons would I have of taking this sort of approach? If I'm not using a compiled language, would there still be reasons to do this?

# Answer
> 8 votes
Most of the time manifest files are associated with some sort of archive file format. For instance, a JAR file in java is simply a zip file with a manifest file that lists the assets within the zip file, and where to find them. In that case the "path/to/image.png" is not a real filesystem path but is instead information on how to find the object inside a compressed archive. In addition to the disk space advantage of compression, using a file archive can improve performance because windows has a very difficult time dealing with tens of thousands of individual files in a small number of directories.

By using a manifest file of this sort you can completely abstract where a given chunk of data is coming from. Maybe your file is on a DVD, or streamed off the internet, or inside a zip file. You'll have to write some additional code to deal with these cases, but by using a manifest file your game logic doesn't have to care at all where something is loaded from.

Now, if you're using a non-compiled language this manifest file could certainly be a C# source file, but it's nice if you can easily modify what manifest file you are using at client execution time based on a registry setting or something similar. For instance, you could check during execution to see if a on-hard-drive cache exists, or if only the DVD is available. You could then switch which manifest to use depending on the available setup.

# Answer
> 4 votes
One reason: data driven programming.

Your code may only want to know it needs a "LightWood" texture and let the resource manager use this key to find the right path to the file. Even further, in scripts, people don't want to remember file paths. They're messy, they can be incorrect. Let the manifest work out where the file is, and let the human work out what material they need by it's name, not the file name.

```
<material name="wood">
  <diffuse color="1,1,1,1">environment.zip/wood_diffuse.jpg</diffuse>
  <normals>environment.zip/wood_normals.jpg</normals>
  <shader>environment.zip/wood.fx</shader>
  <specular color="1,1,1,1" power="0.5" flat="yes" />
</material>

```

# Answer
> 2 votes
As a general design pattern, manifests are useful when you want to collect all the information about a disparate set of objects into a single place. It doesn't have to be about archive/packed files, or about indirection to allow things to be moved without recompiling/updating original references. Indeed the latter can introduce more problems than it solves, so you would only do that if it solved a particular need you had.

The big advantage of manifests is that they act as an index to a large amount of data in a single compact place. As such they improve performance (because you can simply load the entire manifest from disc and keep it in memory), especially in the case where you need to iterate over multiple objects, **but you don't know in advance what those objects will be**. If the objects are on disc, especially if they are in multiple places, you have to touch the filesystem every time you want to iterate over files. For disc-based file systems, the time needed to touch the filesystem is prohibitive, so iterating over files in a directory is a massive cost. By pre-building a manifest of files at build time (NB: not compile time), you trade that cost for memory usage.

Archive files require the use of manifests, simply because the table-of-contents for the archive is essentially a manifest itself, so you get the behaviour for free. And if you are required to use manifests for assets in one location, it can be cleaner to insist that all assets be referenced through manifests; allowing you to abstract the actual storage location/mechanism of the assets from the references to those assets in code. That way you can have a single asset reference type in your code, and not have to make the distinction between file paths, archive file path + offset, or sub-assets.

# Answer
> 1 votes
In addition to the other answers, it also makes your code a little more separated from your assets. You could, for example, allow an artist to work directly with the manifest files without having to have a programmer make the change and make a new build. All it would take is changing the manifest file to point to a new image and simply running the game again.

# Answer
> 0 votes
Manifest files provide a layer of indirection between the resource name and its location. Ofter extra layers of indirection is just a sign of over design. However, sometimes that extra layer is just whats needed to build an elegant and efficient solution.

Here is a simple concrete example where resource name / location separation helped me. While in development my art assets are in revision control with source code. It's very convenient and allows me to iterate quickly. Usually the resource name reflects it's location. The development manifest is very straight forward.

I don't want to distribute a game with the assets scattered around. So when I'm ready to distribute it I can easily zip up my assets into a resource file and build a new manifest.

Also texture atlases are a great way to wring a bit more performance out of the graphics system. Atlases are fast but they're a pain to work with while the art is still under development. My solution is to only build the atlas at the end when I'm optimizing the game. Since I'm using manifests all I need to do is update the manifest to point to an atlas location and voilà the game is now using atlases instead of straight files.

---
Tags: architecture, assets
---


# Question
Title: What are some low-level performance tweaks for iPhone games written in c?
I'm interested in some performance tweaks for a relatively simple OpenGL ES based 2D iPhone game. What performance tweaks have you found? The performance of the game is pretty good on most devices (3G, 2nd gen touch, and iPhone 4)... But I still want to give the user the best experience possible.

p.s. I'm still using OpenGL ES 1.1

# Answer
> 4 votes
Some low-level things that might help:

* Turn "thumb mode" off. This is especially important if you have lots of floating-point operations, like most games do.
* Use CADisplayLink to drive your loop
* If you're using a lot of floating point math, consider using the vector floating point processor or the new intrinsics library.

And of course, profile your game with Instruments and Shark to narrow down where the performance bottlenecks are.

Check out my presentation from last year's GDC Austin for more details on iPhone performance optimizations.

# Answer
> 3 votes
I'll add another few nuggets that I noticed gave me a speed increase on the 2G (I tested a lot of permutations on 2G to know what was feasible).

* use shorts for indices if you can, or in general, experiment with vertex formats.
* experiment with tile sizes. 16x16 tiles may or may not be faster. CPU overhead differs little, data uploaded is more, but cache might be better utilized. As below, I wish I had my tests handy (and organized)
* use as short a format as you can for texture coordinates. I found it was faster to have shorter format and do the multiplication of the texture coords by the texture matrix.
* Test different screen formats. I don't have my tests at hand anymore (I gave up on iPhone aeons ago), but texture depths and display depths/orientation made for all kinds of different performance stats (logical but still, try it).

The biggest thing however, make sure your game is framerate independent. I never tested on my 3GS, but on the 2G you *will* get spikes. Even in a very tight, always the same testcase (just scrolling 4 layers), there was a 8ms spike every second or so.

As for plain C optimizations, the same goes as pretty much anywhere else. Memory layout, avoiding dynamic allocations, avoiding unnecessary branches.

# Answer
> 2 votes
When it comes to textures it's also important to note that you should stay away from large transparent areas in images. If you e.g. have a mask that you put in front of the whole game scene, it's faster to assemble it out of 4 images (just the borders) than to use 1 large image that covers the entire screen.

# Answer
> 1 votes
What I found very interesting, and never mentioned to anyone, was that I noticed a speed difference (on the rendering side of things) when rendering my sprites and tiles 90 degrees rotated. I can't remember whether it was faster portrait or landscape. You'd have to rotate all your graphics for correct usage of course, but the phenomenon itself was interesting. Must be a memory organization/cache access issue. This was doing 4 layers of parallax on a 2G. I found this the biggest win, as there was ample time to run a game in the background (on a 2G you're locked to 30fps pretty much anyhow imo).

# Answer
> 1 votes
In the course of the famous Stanford lectures on iPhone development, Tim Omernick from ngmoco presented many ways to optimize opengl for iPhone (Youtube link). The keynote lasts ~30min and I found it very informative.

---
Tags: iphone, opengl, performance
---


# Question
Title: What resources are available for using Qt as a toolkit for games
Qt is an excellent application toolkit and overall the best for C++. While some large projects use Qt (KDE for example), I haven't seen many games using it. So I decided to make my own. But what does Qt provide that may be useful when writing a game (in my case a 2D game)?

# Answer
> 2 votes
You should definitely take a look at the Qt Graphics View Framework, it does provide a nice hardware accelerated 2D scene graph (QtGraphicsScene).

# Answer
> 2 votes
There are games made with Qt, KDE has a lot of them, see http://games.kde.org/

Most of them are made using the graphics view framework, and the svg renderer.

---
Tags: c++, qt
---


title: Game treatment collaboration tools

text:
# Question
Title: Game treatment collaboration tools
Other than using a wiki, what good (or purpose-built) tools allow for collaborative work on a game treatment?

I have a couple ideas I'd like to get fleshed-out and built, and have a small team who will work me on the project(s). How can we best iterate-over and define the game-play, graphical styles, etc?

# Answer
Personally I think your best bet is to use a funnel-like process.

1. Team generates ideas. No criticism at this point just write stuff down. Wikis, Skype, group chat are all good tools here. Each person should generate ~20 ideas at this stage.
2. Filter through ideas. You can do this alone or with the team. Most likely start by picking a few key qualities to optimize for. (e.g. novelty, depth, time to create.) Put ideas into buckets, start eliminating ones that don't meet the cut. You should end up with ~1 idea per a person at this stage. Consider using Excel or Google Spreadsheet to help you slice & dice and visualize your data.
3. Prototype ideas, still no coding or very limited coding. Best bet would be to use pen & paper to draw out some of the interactions. You could also use something like XNA, Game Maker, or Flash to prototype ideas quickly and cheaply. Identify the best one at this point.
4. Implement more features in waves, no more than 1 day per a feature. At the end of each day test what you have and measure it against the qualities you were optimizing for in step 2. Cut the features that don't seem to be helping and do more of the stuff which is. Most likely use version control to distribute source code for prototypes, e-mail, a wiki, etc for feedback.

Tools to use:

* Git, SVN for version control
* DropBox, Git, SVN for distributing builds
* E-mail, Wiki, Google Docs, Google Wave, Chatterous, Skype for feedback, discussion
* GitHub, Mantis, Jira for issue tracking
* SCRUM, Kanban for development process
* Excel, Google Spreadsheets to work with feedback / break features down and visualize results

*Edited to add mention to spreadsheets, we often forget it but Excel is easy to use, powerful, and creates visuals which communicate a lot quickly*
> 6 votes

# Answer
Git \+ Sphinx is the best solution I've found lately. Substitute git for hg if you prefer, but the general principle is the same. Wikis are generally not so good for such a highly structured document will multiple concurrent editors.
> 1 votes

---
Tags: tools
---


# Question
Title: How do you activate multisampling in OpenGL ES on the iPhone?
I'm experimenting w/ improving the "resolution" of an OpenGL ES based app. Apple mentions here (developer.apple.com) that OpenGL ES in iOS 4 supports multisampling... and this can improve the graphics somewhat. **How do you enable multisampling?**

# Answer
> 4 votes
Does this help?

http://www.cocos2d-iphone.org/forum/topic/7552

---
Tags: iphone, graphics, opengl-es
---


title: How to start development for PSN?

text:
# Question
Title: How to start development for PSN?
I'm interested in making a game that can be distributed on PSN. Any suggestions?

# Answer
> 4 votes
You have to put money down. Call Sony and ask them about it. They'll tell you how to hook yourself up with the official developer's kit. It will cost money. But of course, you'll make that money in the back end. So the question really is, how confident are you that you can make something that will end up on PSN for sale?

# Answer
> 3 votes
Here is an interesting article on becoming a developer of the "mini" titles that have recently come onto PSN. http://www.pspminis.com/2068/interview-futurlab-on-how-to-become-a-licensed-psp-mini-developer/

In terms of initial cost, you no longer need to purchase a full reference kit (~$10k) and can get away with a reference tool costing $2000 with much of the functionality.

# Answer
> 0 votes
As mentioned above, getting a real devkit and being setup as a licensed studio can take quite a bit of cash. A better bet might be to learn Unity since Unity3 (which is supposed to be out Real Soon Now) will support PS3. That said, Unity Pro is still not cheap, though they haven't said if the free version will support targeting the PS3 last I looked.

---
Tags: homebrew
---


title: How can I promote my game?

text:
# Question
Title: How can I promote my game?
I am a beginning indie developer, and I want to get the word out about my game. What sites can I go to to ask about reviews of my game, and where might I be able to talk about and get feedback on my game from players?

# Answer
The answer will really depend on what kind of game you've made. Here are some of my thoughts:

1. For Flash: Flash Game License is a good place to get feedback from other developers, you could also try Mochi's forums. The FGL people also run Flash Game Distribution which can help get your game out to different portals (if you decide not to get an exclusive sponsor). This answer has a good list of portals you could submit your game to.
2. Generally: Sites such as the Indie Game Blog and TIGSource might review your game if you send them some info. The TIG Source also runs forums where people can play your game and leave feedback. The Indie Gamer forums is another community which can help.
> 12 votes

# Answer
I would send (and have) an e-mail to every single website out there that reviews games of any kind. **But not before I have an almost completed game.** Be real. Be humble. Show off something innovative.

A lot of places won't really take their time looking at you until you have something put together. Don't try to approach reviewers to review a pre-alpha-alpha prototype. It might sound like common sense but I have read reviewers make that kind of remark (which is enough of an indicator).

As for feedback. Grab a few play testers, preferably locally, that you can watch play your game. That will be some of the best feedback you can get. Alternatively, follow the other's advice. tigsource.net, gamedev.net and devmaster.net forums.
> 8 votes

# Answer
Both Bytejacker and Rock, Paper, Shotgun have a sizable readership and will review indie games sent to them if they find them interesting enough. I also second Alex's idea of the TIGSource forums; just make sure you follow their guidelines for new users and post in the appropriate category.
> 6 votes

# Answer
My advice is to know your market. A mud for example, usually buy ads on topmudsite or mudconnect. An MMO might want to buy an ad at massively.

Indie game developer probly could get some good publicity by being upfront and simply posting at an related forum saying that they have a new game and want people to check it out. If you do this however, dont be pretentious and say you found a cool game and want people to try it. Just say that you are the developer and hope people give feedback on it. Try to find a genre specific forum for this. For example the wargamer forum is a nice place to do this if you have a grognard-ish game. Gamedev forum is also nice for this, but targeted audience is always better.
> 3 votes

# Answer
Find blogs that post about games/apps of what you are developing for. For instance, if you are creating an Android game, then first I would get some sort of PR statement about the game together for blogs to post (with some screenshots of the game or video! A must!). This is even better if you have a website you can put this out on. Then hit up every Android related blog and see if they'll write a review for your game. Most of these blog sites also have forums that you can post to about your game's release.

You can easily replace "Android" for "iPhone" or "xBox" etc.
> 3 votes

# Answer
I posted this answer in a similar question

---

I don't know how effective this idea is (I haven't tried it yet) but for my current project I am going to advertise on Facebook. Let me explain.

Essentially I am going to create a fan page, and run an ad campaign on Facebook. What I figure is I can spend like $30/mo (or what ever you want) for advertising. As people become a "fan" of the page, a lot of other people will see that. So basically, if that $30/mo generates 5 fans directly, it could generate 50 fans indirectly. I figure I could also do some fun stuff with the fan page such as give away copies, solicit ideas, etc...

Like I said above, I haven't tried this so I don't know if it will work. However, I will let you know in the near future. :)
> 3 votes

---
Tags: marketing
---


# Question
Title: What is the correct object-orientated approach to class design in game development?
I'm in the midst of developing a 2D sprite-based game for Windows 7 Phone, using XNA. The training and tutorials available for it are pretty helpful, but the problem I face is that each of them approaches their class design differently, and the code is not particularly well-factored. As a result, it has been difficult for me to gain a good understanding of which responsibilities I should give to a particular class.

For example, I could have a base sprite class `BaseSprite` that knows how to draw itself, check for collisions, etc. I could then have an `AnimatedSprite` class that would know how to navigate its sprite sheet, an `ExplodingSprite` class, and so on. This technique is demonstrated in the Space Invaders example in the Windows 7 Phone Jumpstart Session 2 materials.

Alternatively, I could instead place the bulk of rendering and running the game responsibility in a `GameScreen` class; that class and its derived classes behave more like forms or web pages in terms of their responsibilities. Sprite classes are more simple containers with much less logic.

This is the technique used in the Windows 7 Phone Training Kit's Alien Sprite game and other game state manager examples.

What is the correct object-orientated approach to class design in game development?

# Answer
I do use a more component-oriented approach, where you would have a Sprite class which has components like Visual, Collision, Animation, Input, etc. With this approach I don't end up having a deep class hierarchy (which is good).

For some info on Component Oriented Design see here.
> 26 votes

# Answer
In games, the Component pattern is a common solution.
> 11 votes

# Answer
The SOLID Principles apply as much to game code design as to any other profession - at least until you come to optimise, so I'd use your first example as a starting point.

I'd go further though, because BaseSprite sounds like it has the tendency to become a megaclass. The Single Responsibility Principle dictates that collision, rendering and navigation should all be handled by components, rather than individual entries in a class hierarchy. The holding class of all these components should only handle pushing world positions between them.
> 6 votes

# Answer
For the last few projects I have leaned more towards an MVC style approach.

At first we weren't sure if this would work, but it worked perfectly.

### Model

The data objects. Just the pure data. No behaviour, no rendering.

Data manager. Just handling "lists" of data objects. (Can also be enhanced to support pooling.)

### View

We call them renderers. For every data object type there is a renderer. When called with a manager it will render all objects in that list.

### Controller

Same as the renderers, but controls the behaviour.

## Example

The ShipManager has a list of Ships. The ShipController will move the Ships according to their state. The ShipRenderer will render the Ships according to their state.

## Why

This way the view and the logic are strictly seperated. It makes porting to a new platform pretty easy. Optimizing the data layout inside the XxxManager is also very easy.
> 5 votes

---
Tags: xna
---


title: Dynamic Dijkstra

text:
# Question
Title: Dynamic Dijkstra
I need dynamic dijkstra algorithm that can update itself when edge's cost is changed without a full recalculation. Full recalculation is not an option.
I've tryed to "brew" my own implemantion with no success. I've also tryed to find on the Internet but found nothing.
A link to an article explaining the algorithm or even it's name will be good.

**Edit:**
Thanks everyone for answering. I managed to make algorithm of my own that runs in O(V+E) time, if anyone wishes to know the algorithm just say so and I will post it.

# Answer
> 1 votes
Not an answer but might this help? http://www.lix.polytechnique.fr/~liberti/sppsurvey.pdf

Also, a general tip - maybe you already know.

If you know of a paper related to the problem, checking CiteCeer to see if there are papers referencing it, you might find your way to an answer (or not, but always interesting papers on your travels). http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.56.7969

And lastly, again not an answer - if you get really stuck here's some pointers to possible alternatives: http://www.aiwisdom.com/ai\_pathfinding.html

# Answer
> 1 votes
I don't believe that's possible in the general case. You can easily imagine a graph where your source node has only a single connection to the rest of the graph. If that edge changes, the weight of *every* path from the source will change (although not the paths themselves).

There are other pathological cases you can imagine where even a single edge change would dramatically affect pathing. Imagine a graph with two almost equally weighted chokepoints that almost all paths going to. A slight change in either chokepoint's weight could cause a majority of the paths in the graph to reroute.

If you're willing to settle for an imperfect solution, one option is to have your game constantly recalculating Dijkstra's algorithm incrementally on the graph. So, in addition to your other game processes, you have another loop that works its way through Dijkstra a few nodes every frame, restarting as soon as its done. You can then tune that to spend as much CPU on it per frame as you can afford. You'll get the benefit of running a full recalculation without having the stop the world, the only problem is that you'll have stale paths for a while.

# Answer
> 0 votes
It strikes me that maybe what you want is actually a hidden markov machine so you can treat the true path costs as an unknown and just model them probabilistically? That might be crazy though.

# Answer
> 0 votes
As far as a direct answer, all I have off the top of my head is: A\* might help if you can make a good heuristic.

Other ideas: You might be able to do full recalculation over multiple frames (or in a thread). Or maybe try representing your search space in a way that you can use progressive refinement; for example, a quadtree where you can perform a search at coarse granularity (by sum/avg of node costs in that region), then slowly search each subtree.

Of course, if you're working on a very limited platform or very large dataset, that's not going to help. But if that's the case, you probably want a different search algorithm.

---
Tags: algorithm, graph
---


# Question
Title: Finding unoccluded tiles in tile-based game
I am working on a 2D tile-based game, and right now I'm trying to get a 2d equivalent of shadow volumes to work. I'm having trouble finding the surfaces that should cast shadows. From any point in the game, I need to find either the unoccluded faces, or the whole tile.

My question is, is how can I find these tiles/edges as fast as possible given a point?

# Answer
> 12 votes
There's a lot of work done towards that problem in the roguelike community.

Here's a page that lists some algorithms and libraries that might help you. http://roguebasin.roguelikedevelopment.org/index.php?title=Field\_of\_Vision

# Answer
> 2 votes
This is not a complete answer, but hopefully it will help.

Is your map/tile set static or dynamic? If it's static, I would *strongly* encourage you to do offline processing and precompute as much as you can that way. You can do it in any way you want (raycasting or something smarter), but you don't really care about making very fast because it will all happen offline while you "bake" your levels. You can either precompute exactly which tiles are visible from each spot, or create some kind of larger regions and all the tiles potentially visible from each region.

Then, at runtime, the query for the visible tiles should be very straightforward and very fast.

Of course, if you're having dynamically created levels, then this doesn't apply at all :-)

# Answer
> 1 votes
You can see how I implemented this for a C# roguelike here. The code isn't highly optimized, but it seems to be fast enough for me and (more importantly) should be fairly easy to read. It's basically doing a simple shadow casting algorithm that works one octant at a time.

# Answer
> 0 votes
I'm not sure what platform you're on, but I can't really think of any platform that wouldn't be fast enough to just grow a circle around your lightcasting entities (unless there's a lot of em) and detect whether the tile about to be 'plotted' in your circle algorithm is a solid tile and thus lightblocking. From there on it would be slightly trickier as you'd have to keep track of circle segments that are occluded or not, but it would be what I would do. Another option would be to cast rays in a circle (again pretty fast) in tile resolution space and stop each ray as it hits a solid tile.

---
Tags: 2d, tiles, line-of-sight
---


title: Developing Flash games on the Wii

text:
# Question
Title: Developing Flash games on the Wii
Has anyone used WiiFlash for developing Flash games? Any pointers on how to begin developing games for the Opera channel for the Wii?

# Answer
The WiiFlash project was for using the wiimote on PC/Mac games. I think you want to look at the MarioToo project for creating wii browser games. To be honest though, why bother? You've got a much bigger audience to target with Flash by going for the general PC/Mac/Linux audience.
> 2 votes

# Answer
Keep in mind that the Internet Channel (Opera browser) uses Adobe Flash Lite 3.1; Basically Flash 8 with some Flash 9 features.

I would perhaps target the Wii but make the game accessible to any browser. Best of both worlds. Think of it more like a regular browser on an ancient machine using the Flash 8 plugin and you shouldn't have too much trouble.

I've never used WiiFlash but it might be interesting for testing locally; If you have a Wii already you'd be better off setting up a local webserver and pointing the Wii browser to that local address for testing.

If you were ever going to do a 3D game you'd have to drop Flash entirely and go with Unity3D or some similar engine.
> 3 votes

# Answer
As @Iain mentioned, that is not why the WiiFlash was made.

You will be using actionscript 2.0 to make Flash Games for the WII. There is a title out there on this subject:Nintendo Wii Flash Game Creator's Guide

HTH
> 2 votes

# Answer
For Wii games, you might want to check out **Unity**. It's pretty easy to work with and has portability to the Wii that you can buy.
> 1 votes

# Answer
Just like any other Flash game, just play test it a lot on the Opera channel to make sure that it fits that rather than your browser. Please note that a Flash game can not detect all buttons and swings...
> 0 votes

---
Tags: actionscript, flash, wii
---


# Question
Title: OpenAL - alGetSourcei and AL_BUFFERS_PROCESSED gives junk
Posted this question on SO but got no answers. Maybe somebody can help me here.

I recently had a well-working program which streamed WAV and Ogg sounds with OpenAL. I then decided to abstract the source and buffer objects into C++ classes. I got as far as the source class. My function which returns the number of processed buffers is not altering the integer passed to `alGetSourcei`.

```
int ALSource::GetBuffersProcessed() const {
    ALint processed;
    alGetSourcei(this->source, AL_BUFFERS_PROCESSED, &processed);
    int error = alGetError();
    if(error != AL_NO_ERROR)
            return -1;
    return processed;
}

```

I checked that `error` is never anything but `AL_NO_ERROR`. I generate the source in the constructor:

```
alGenSources(1, &source);

```

This also never gives any error.

The actual symptom of this is that `processed` is declared but not initialised. It's final value is the initial junk value that it starts out with. (Usually something like -8834824334).

Would this be expected behaviour? The OpenAL specification states that the value should be from `0 - any` but is not really any more specific than that. The programmers' guide is the same.

# Answer
> 3 votes
OK, here goes the solution. The root cause was an implicit destructor call which destroyed my AL context. What's interesting is that a bug in the Windows implementation causes OpenAL to fail silently when there is no current context. So all my calls to `alGetError` returned `AL_NO_ERROR` because there was no context. It's a nasty little bug, in my opinion.

---
Tags: c++, software-engineering, openal
---