# Question
Title: Do you know any 3D engines written in Objective-C for iOS?
In the next few weeks I will start a game for iOS, most of the action will happen in 2D but a 2D engine is not enough for our idea, therefore I'm doing a small research on available 3D engines for iOS written in Objective-C (we already looked on some engines written in C++).
Do you know 3D engines written in Objective-C?

I found this one http://nineveh.gl/ but is not yet ready :(.

**later edit (1)**.......
I did a research on the engines written in C++, they are nice and probably I will go with one of them, but if there is any good engine written in Objective-C, than I will go with it, because its a matter of taste and I like very much the obj-c language.
**later edit (2)**.......
nice presentation/teaser about what I'm looking for http://www.slideshare.net/rsebbe/designing-an-objectivec-framework-about-3d

# Answer
You might also want to check out iSGL3D (http://isgl3d.com) which is an open source Objective-C iOS scene graph library.

It works with both OpenGL ES 1.1 and ES 2.0 with a number of features such as simple scene and object manipulation, lighting and shading, cameras, multiple views, meshes and particles, tweening, mesh skinning, vertex animation, shadows, object interactivity, etc.

It uses a few C++ hooks for external libraries such as Bullet physics and PowerVR POD importing but these are wrapped in Objective-C classes.
> 0 votes

# Answer
Cocos3d is an extension for Cocos2d and supports many features. Check out their website - http://brenwill.com/cocos3d/
> 4 votes

# Answer
Check out both the Unreal Development Kit (http://www.udk.com/) and Unity (http://www.unity3d.com) engines. Both have Objective-C hooks.

I am assuming that it's not important that the engine itself be written in Objective-C, only that you can program in Objective-C and use the engine.
> 0 votes

# Answer
Galaxy Engine looks pretty solid. It's not just a 3D engine written in Objective-C, but the package also contains scene manager, mesh converter and dozen of other content-creation related tools.

Also check out the Oolong engine, it's mostly written in C++ and maintained by Wolfgang Engel of Rockstar Games fame.
> 0 votes

---
Tags: objective-c
---


title: Rotate object to face player

text:
# Question
Title: Rotate object to face player
This is probably a simple vector question, but I'm not sure how to do it.

I have an object at vector position `(ox,oy)`. Potentially every update, the user walks around the screen, and will be at position `(px,py)` at any given moment. How do I make it so that the object is always facing the player? I need to get the angle in degrees.

This is what I've been messing around with, but the direction doesn't immediately point to where the user is located. Instead, it slowly increments in the direction the user is walking in.

```
 objVec.Normalize();
 playerVec.Normalize();

 obj.Rotation = MathHelper.ToDegrees((float)Math.Acos(Vector2.Dot(objVec, playerVec)));

```

I might be going about it completely wrong, so any help is appreciated!

# Answer
> 14 votes
Think about the problem differently. You want to object always to "face" the player, which means you want its "forward" vector rotated around to be parallel to the vector from itself to the player. Assuming its "forward" vector is normally at `obj.Rotation = 0`, the proper rotation is basically the arctangent of `Vector2.Subtract(playerPos, objectPos)`. Most math libraries will have something like `atan2` that takes two arguments or a `Vector2` that will automatically figure out the right quadrant for you.

EDIT: I realized that you're in C# and these are actually built-in classes. So you don't have to go hunting for math library documentation, I can do so for you. The right code should be:

```
Vector2 facingVec = playerVec - objVec;
obj.Rotation = MathHelper.ToDegrees((float)Math.Atan2(facingVec.Y, facingVec.X));

```

Note the X/Y reversal; for hysterical raisins, Atan2 always has the arguments reversed.

---
Tags: 2d, c#, mathematics, vector, orientation
---


# Question
Title: What are the specifications for 3D animated game assets on the Android platform?
(apologies if this is phrased vaguely due to my lack of knowledge; I'm happy to change the question entirely if someone can suggest a more realistic query)

I'm getting a grip on creating 3D characters in Lightwave, Maya, Blender, etc. My goal is to focus on creating creature & character animations specifically for games. I thought it would be a good exercise to make a few critters with a specific scope. As a non-programmer (I've written a few scripts, but I really don't have a passion to code) - can you point me in the right direction to find some guidelines? (I have a programmer handy who will write the code, but I want to be able to give him assets that are as usable as possible)

I assume that Android games are intended to run on limited hardware - maybe there's a polycount I should shoot for, or a particular memory limit? The resources I've found so far all seem to be helpful to developers \- haven't found much oriented in my direction

# Answer
> 1 votes
This question really depends on what game you are targeting. It's very specific to the engine and platform. So, that would be more of a question for your programmer buddy than anyone. Is it his own game engine or 3rd party? Either way, he should know A) the formats used or preferred and B) the "requirements" of the system and C) any special cases such as max polygon count, textures sizes/foramts, animations, etc.

Generally speaking, you will want to work with whatever format that works best for you (as the artist). Once you have a finished model, you'll want to give that to your development team. They will compile that offline into an optimized format/textures that works best with their engine.

---
Tags: android, efficiency
---


title: Working towards going 3D

text:
# Question
Title: Working towards going 3D
I am a beginner-intermediate C++/Java programmer and my long term goal is to be a game programmer.

I have decided to start off with 2D and work my way towards 3D.

I would like to use SDL to start off with, but I am wondering if it is maybe not such a great idea.

Given the fact that I am working towards 3D, would it be advisable to use SDL or jump into OpenGL without the Z axis?

# Answer
Just use SDL. You can use OpenGL with the SDL when you want to transition over.

http://www.libsdl.org/docs/html/guidevideoopengl.html
> 2 votes

# Answer
OpenGL is used quite a lot for 2D games. We used it in Teeworlds for example. Using it as a pure 2D language is ok, it might give you some quirks when setting up camera and especially if you want stuff pixel perfect. But you will learn a lot by doing it.

You can use OpenGL with SDL, it's very common. Most people doing it that way only uses GL though, and skips most (all?) of SDL:s drawing functions.
> 2 votes

---
Tags: opengl, c++, sdl
---


# Question
Title: Mouse joint isn't restricting the ball from going to the other part of the screen
I'm developing a application in cocos2d using the Box2D framework, but unfortunately I am having issues. I'm not able to restrict the orange ball in the half screen area, taking the image below as reference, I don't want to allow the ball to go to the opposite part of the screen.

I'm using the b2MouseJoint to move the ball around the screen. b2PrismaticJointDef seems to restrict on any particular axis, but I need to restrict on a particular rectangular area of the screen.

# Answer
> 1 votes
I Did This By following simple if Condition It was looking hard to Me As I am new to the Box2D FrameWork

```
if (location.y<240.00)
{
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    _mouseJoint->SetTarget(locationWorld);
}

```

---
Tags: iphone, physics, box2d, cocos2d-iphone
---


# Question
Title: Need a better function for transportation efficiency
I'm making an economic kind of game, and one of the things I'm simulating is the transportation of resources to a central depository, e.g. moving metal from a mine to the city (so it can be turned into swords). I want it to behave so that a producer farther away from the city is considerably less efficient, but the player can bring the efficiency back up by assigning additional carters.

The function I have right now is:

```
efficiencyPercent = 100 - pow(9 * travelTime, 4/3)*pow(2/3, carters)

```

However, this doesn't have the behavior I want; carters are too powerful, either because `pow(2/3, carters)` converges to 0 much too fast, or because `pow(9 * travelTime, 4/3)` grows too slowly, or both, I'm not sure. No matter how big `travelTime` is, the player can overcome it by assigning a reasonable number of carters. I want it to work so that modest `travelTime` is defeatable by a reasonable number of carters, but once it gets too high it takes an absolutely incredible number of carters to defeat it.

What's a better sort of function that will have this behavior? I think I need the inefficiency to be exponential in `travelTime` but I don't know what to do about `carters`. Please help!

EDIT: DeadMG suggests that I have combined two effects (effect of travel time & effect of carters) that would be better off separated. I'm not sure I agree, but I'm not sure I disagree either, so I'm restating the question in support of this theory.

What I'm looking for is some kind of mechanic, involving carters and travel time, with the following behavior:

* An iron mine can generate iron at a rate dependent on the number of laborers assigned to the mine; for example, 40 miners produce a maximum of 10 iron per month. This is strictly linear and I'm not changing it at this point. No matter how many carters you assign, there should never be a way to convince the mine to provide more than this amount.
* In order to be used, the iron has to be transported to a city. The miners are willing to do this to some extent, but they become less willing the farther they have to carry it. If the mine is right in the middle of town, no carrying is necessary and the miners work at full power; farther away and they are forced to take time off to haul wagons. In the interest of concreteness, the miners shouldn't be willing to carry a significant amount of stuff farther than 5 days away. (I can fiddle with the exact balance later).
* You can assign additional laborers (from the city's pool) as carters, allowing the miners to get on with their proper jobs. Dedicated carters are far better at moving things than miners moonlighting as teamsters. Assigning more carters should have diminishing returns. For concreteness in fiddling with constants, a mine 5-7 days away should be restored to 95% efficiency by roughly 10 carters.
* The farther away the mine is, the more carters it should take to achieve a given efficiency improvement. Mines that are too far away (for concreteness, 14 days or so) should require a completely impractical amount of carters to increase the efficiency to usable levels. Ideally, in this situation the player would rather build a new city, closer to the mine, than assign such an incredible amount of workforce simply to cart things around.

The formula I have satisfies all of these except the last, which is the one I'm having trouble with. I'm particularly looking for a mechanic that provides all of these features in a "smooth" way, without arbitrary breakpoints or funny corner cases, because I want to be able to change the constants depending on the empire's technology levels. Whether this is two separate formulae as DeadMG suggests, or a single combined one like I have now, or any other kind of mechanic, I don't care. Any suggestion, up to and including the simulation of little carter automata moving around the map, is what I'm looking for.

# Answer
> 2 votes
I tend to say 'if you can't find an explicit solution, seek an implicit one' (compare my anwer to this question).

Have you thought about simulating miners, carters and stockpiles as agents?

Taking your example numbers, you could go like this: A miner mines .25 units of iron in 30 days (i assume uniform month-length for the sake of brevity). If this miner has to push a cart across the country, he can not mine, so for a five-day-trip, he is out of the mine for 10 days (five days to there, five days back again), so there is your inefficency. So, let the miners mine to a stockpile at the mine.

Let a cart have a limited maximum load, eg 2 units. A carter needs the same 10 days for a round trip, picking up up to 2 units of iron at the main after five days. A single carter would thus be able to pick up 6 units of iron from the mine per month (3 trips of 10 days with a load of 2 units each). A second carter could then be assigend to pick up the rest of the iron mined, but he might have to go back (half)empty or wait for the miners if there isn't enough iron in the stockpile to fill his cart.

Essentially, this would be like the gathering logic in RTS-games, without the fancy graphics.

The implementation depends on the granularity of your game. As you didn't mention it in your question i assume a turn based approach, with one turn being one month - so you would have to simulate 30 days of mining and carting for each turn.

# Answer
> 4 votes
I had started an economic model for one of my games, and wanted distances between factories and towns to matter. I tried to model the person's commuting and working hours. Suppose they're willing to work+commute 12 hours in a day and have 4 hours leisure/eating and 8 hours sleep. Some of that 12 hours goes into the commute to work and some of it goes into actual work. The farther you are from town, the more goes into the commute. There's a hard cutoff at 12 hours of commute time — you just don't get any work done anymore.

```
time_worked = 12 - time_commuting

```

and then

```
time_to_complete_job = constant / (12 - time_commuting)

```

If you plot this on a graph you'll see it's reasonable for the first 6 hours commute time (any factory within 3 hours of the town is the same efficiency) but then it starts going up after that, and it's twice as expensive around 9 hours commute time, and starts going up very quickly. At 12 hours it goes to infinity. That corresponds to your 14 days = impractical.

I don't know if this behaves the way you want but given that you have some distance you want to be impractical, I think this type of function probably gives you better results than pow().

# Answer
> 0 votes
Ultimately, I think that you're dramatically over-complicating the situation at hand. You want to achieve a simple effect- resources further away are more expensive. You should aim to reflect this in the simplest way possible- an increase in the cost, either recurring or initial, of obtaining the resource production. Once this is done, then it doesn't matter what you decide to do about stacking carters, because all mines produce the same amount once they're paid for, and you can balance the distance of resources and the power of carters independently.

---
Tags: mathematics, game-mechanics
---


# Question
Title: Writing Game Engine from scratch with OpenGL
I want to start writing my game engine from scratch for learning purpose, what is the prerequisites and how to do that, what programming languages and things you recommend me? Also if you have good articles and books on that it will be great. Thanks in advance!

My Programming languages and tools are:

* C/C++ is it good to use only C?
* Python
* OpenGL
* Git
* GDB

What I want to learn from it:

* Core Game Engine
* Rendering / Graphics
* Game Play/Rules
* Input (keyboard/mouse/controllers, etc)

In Rendering/Graphics:

* 3D
* Shading
* Lighting
* Texturing

# Answer
You can write a game engine in practically any language using practically any methods of rendering. You could write a game engine in bash using console output for example.

So, I think it would be best to define what exactly you want to learn in writing your own engine. There are a lot of "fields" in game development.

* Core Game Engine
* Rendering / Graphics
* AI
* Networking
* Game Play/Rules
* Sound
* Input (keyboard/mouse/controllers, etc)

etc.. From there you can even have sub topics. In Rendering/Graphics

* 2d or 3d ?
* Modeling
* Shading
* Lighting
* Texturing
* GUIs/Huds/Interfaces.
* etc, etc

Just one of those sub-sub-topics could eat up many hours (or years!) of study!

So, first define what you want to learn. Start simple.

Use whatever language you are comfortable with - though some are better suited for certain tasks. For example, the core engine and rendering is probably best done with a "lower" level language like C/C++ (if you need performance that is); but something like AI or Game Rules might be better done in a higher level language. Nothing says you can't mix and match. You could write your engine in C++, your rendering in C (since it works well with OpenGL) and then use LUA for scripting your Game Rules, etc.

As far as example, there is a game engine called Slick2D. It's written in Java and is open source. It's an example of a simple 2d engine written and designed really well. You can learn basic concepts from that, like game loops, managing game states, etc.

If your comfortable with C/C++; I would suggest taking a look at SDL/OpenGL. It handles some of the housekeeping like input, sound, creating windows, etc and can focus on other stuff.
> 10 votes

# Answer
SDL + OpenGL is an excellent choice to start up a custom game engine.

I personally use a C-ish version of C++ because I found out that works the best for me. By that I mean I don't use any exceptions. There are two reasons for that: first and foremost exceptions require exception safe code all the way down which with OpenGL and SDL is not exactly easy to achieve. More importantly however this way it's very easy to expose C++ objects over the C ABI which is incredible helpful if you try to bring a scripting language into the mix.

I'm in a similar boat than you are and I wrote down some of my adventures with SDL and OpenGL in a blog (immersedcode.org) in case someone else is interested.

For the general architecture I have two suggestions: if you want a 3D engine check out the book "Game Engine Architecture" by Jason Lander. If all you want is 2D, keep the design as simple as possible and let yourself inspire by XNA or other projects.

Lastly: do not call OpenGL all over the place. Do yourself a favor and isolate it into a couple of places so that you have the ability to switch between desktop OpenGL/OpenGL ES or even DirectX at a later point if you want to.
> 4 votes

# Answer
Don't use C unless an implementation detail holds you to it at gunpoint. Otherwise, use C++, because it's flat out a vastly more capable language, and you can always choose not to use those capabilities later. I personally have nothing for/against Python, I've never used it.

I wouldn't recommend OpenGL against DirectX because DX has a modern object-orientated approach, which is far cleaner and more understandable/less error prone. The interface offered by OpenGL is extremely poor in comparison.

The last thing I've got is that I've heard from many people I trust that GDB utterly, utterly sucks and the Visual Studio debugger is by far and away the best. This is not my personal experience so take it with a little salt.
> 0 votes

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


title: Splitting an object into two

text:
# Question
Title: Splitting an object into two
I'm using Farseer physics engine.

I have a simple rectangle body and would like it to split into two pieces given a starting coordinate (where the bullet enters the object) and ending coordinate (where it exits).

# Answer
A common technique for creating cutaways or cross-sections is to use an arbitrary clipping plane to exclude a part of the body. By cloning the body and clipping an opposite part of the body you end up with two pieces of something that appears to have been sliced in two.

You would then have to use the stencil buffer to 'fill in' the clip edges, and create new physics bodies for the two new bodies.

http://glbook.gamedev.net/moglgp/advclip.asp
> 2 votes

---
Tags: physics, procedural-destruction
---


title: Should our group try to make a game?

text:
# Question
Title: Should our group try to make a game?
I am a second year, learning C/C++ and Java.

In our first year of university we did basic C++, no classes. This year we have been introduced to classes and inheritance. We have not yet done pointers, virtual functions, abstract classes, operator overloading, exception handling, linked lists, stacks, queues, binary trees, graphs, etc.

I am very curious, so I like to teach myself some things that we haven't yet done. I enjoy the technical side of things a lot, my friends think I am weird to want to learn more than I have to..

**But heres my problem:**

Our C++ lecturer has decided to take a different approach this term to learning. He said, form a group, think of a project you would like to do and implement it over the year.

**Let me give you a break down of our group:**

Theres five of us in the group. Myself and another member are much more experienced than the other three and we like the technical side of things, and are quite motivated to do something with an **interesting** challenge. Then we have a group member who has been extremely hard to motivate, and he was very unsure why he wanted to be a programmer. He did some thinking and decided he wanted to work towards becoming a game programmer. The next member of ours is not the most reliable and has let us down a few times. Finally we have a new member that is keen to learn, but his programming needs work, as do the previous two members.

We are all friends, of course -- which probably isn't the ideal solution to a good group.

**The project idea:**

Our lecturer gave us an initial idea for a project: a timetable scheduler. Of course this is no trivial task, but most of our members were not really interested in the project at all. So, then I thought -- one member wants to be a game programmer (the hardest member to motivate), most of us would probably enjoy the experience of doing a game, as it would be a big challenge, so why not give it a go?

**So what is my question?** Do you think that we should take on the task of making a game, or aim for something else?

Initially we thought of a 2D, top-down, ARPG. Then it became a 3D ARPG.

Obviously 3D would be harder, but as we have time to learn, it wouldn't be such a bad idea would it?

Personally I think that the learning will be the most fun part of this project, even if we don't end up with a great game, we should have learned a lot (including being forced to learn and implement new C++ topics).

# Answer
Honestly, in the space of time you've got where you have to factor in learning time as well, design a 2D game rather than 3D. As quoted a few times on this site, 3D is orders of magnitude harder than 2D.

It's definitely possible to make a game but you must make sure that you clamp your gameplay features right at the beginning. You don't want to situation of "Well wouldn't it be cool if we did X as well as Y?" 7-8 months down the line.

Just remember that it doesn't have to have fancy graphics or the polish of a AAA game.

Depending on your game idea and how complete you want it (and try to keep it as simple as possible, especially as some members are less experienced than others) you will need something for:

* Graphics
* Input
* Audio - potentially optional
* Collision Detection
* Physics - depending on the idea, you can easily get away with your own physics for a Tetris clone, for example.
* AI - completely optional

There are plenty of sites available that you can get free assets and content from.

I have heard good things regarding SDL and SFML so have a look at them to make your 2D implementation a lot easier.

If you really want physics, you could use Box2D but you should take note that it's a fine balance you're after. The more libraries you use the longer it will take to learn them and integrate them to a satisfactory degree. On the other hand, depending on the complexities of your game, you should make use of more libraries rather than reinvent the wheel.

You can simplify this headache just by keeping your game simple. There's nothing wrong with a Tetris, Mario or Asteroids clone.

Personally, I wouldn't bother with AI. You can have some enemies that move about randomly and that would be sufficient to make it a challenging game.

Just as a final note, I'd get used to using pointers and references at the very least, so I'd recommend learning a bit more about C++ too in your own time.

Good luck!
> 10 votes

# Answer
I am guessing that none of you have done a project like this. You should definitely use a game engine or some kind of third party library. Do not try to roll your own.

Use something like C4, Irrlicht, Horde3D, NeoAxis, or anything that looks like it will fit your needs (decent list here: Easy to use cross-platform 3D engines for C++ game development?). You should probably stick with C++ since this is a C++ class your talking about.

Also, consider content. Programming isn't the only thing that will go into this project. Some games need a lot of assets: sounds, music, models, meshes, textures, etc. Another important asset is game content like maps, items, etc (depending on the game). My foremost recommendation is to make a game that doesn't require too many assets so you guys can focus on the programming aspect. That's why I recommend you stay away from certain genres like RPGs (usually require vast amounts of game content like maps, items, monsters, art, sound, etc).

This isn't to say you can't make a game where art or sound is required, just be ready to use things that are already out there. This will save you vast amounts of time.

If you make a game, it should be a game that is focused on something programming wise. For instance: a game where you have to catch shapes as music plays. The varying pitches and other aspects of the music would change the flow of shapes. This game would be neat because it doesn't require a lot of assets (no maps and very minimal amount of art and sounds). You would also have to focus on programming tasks like manipulating and responding to the music your game is playing. Try to do a game that is neat, but also doesn't require a lot of content.

My core suggestion: Aim for a game that you think you can finish. Low amounts of content (or content from free/usable sources) is essential in my opinion for a first project like this. You should also develop other games before your "end game" project (clones like tic-tac-toe, break out, and tetris are good examples). Also, don't reinvent the wheel. Use other people's code! It'll save you time and it'll probably be better than your code if your doing this for the first time. Don't code an engine, code a game.

3D verse 2D isn't a huge deal in my opinion. The math is a bit more imposing, but it isn't like 3D is far harder than 2D. Yeah, your not going to make WoW, but you can make a decent-looking 3D game. It's all about where you set your sights.

Notes on your team: Your team is only as strong as it's weakest link. If you feel that certain team members will have troubles, than you should anticipate picking up the slack or making changes. Your team members should fully realize how hard making game can be. It's not an easy project by far.

Honestly, I think you guys can do it in a year. Five people can definitely learn and implement a game. It all depends on the game your making, set your sights just right and you'll hit your mark. Sorry for the horribly long answer, just my opinions from what I've learned in the past year.
> 5 votes

# Answer
I wrote a game for my final year project alone so it is possible with five of you.

I would advise you think about these things:

1. check how lenient your professor is going to be. I nearly failed my first review because I used to much 3rd party code and they felt that I wasn't doing any real work.
2. resources. I wasn't allowed to use any graphics or sounds that were copyrighted so its more difficult than just googleing it.
3. plan to fail. the amount of times I thought I knew what I was doing and it turned out it wasn't as simple as that such as adding text to a graphic window.

and I cannot stress enough plan before you code, or two months in you will realise that should be a class. a good plan will save you time especially if there are 5 of you.

also dont feel bad if you dont create a big hit. a game is an incredibly big project. Though your classmates projects may look a lot better two thirds of a game will get you a better mark that all of a easier project.

I never made it past a demo world and still got the top grade in my class (first with honours)
> 1 votes

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


title: split pngs for sidescroller

text:
# Question
Title: split pngs for sidescroller
I want to split a long png from my artist into vertical chunks that I can load into my code for a side scroller.

Is there a tool that will help do that or do I have to do it manually?

# Answer
Use a texture atlas, or a tilesheet of some kind. One texture in video memory is much less work than 100 textures in video memory.
> 5 votes

# Answer
Try http://www.imagemagick.org/ which you can control from the command line to process images.
> 2 votes

---
Tags: image
---


# Question
Title: Drawing a texture of arbitrary size in XNA
I wish to know if there is a way to load a texture which is not in powers of 2, for example 100 X 56 in dimension, in XNA 4.0 and draw it using VertexPositionColorTexture.

# Answer
It's very simple using SpriteBatch. Initialize it :

```
spriteBatch = new SpriteBatch(yourGraphicsDevice);

```

When you load content just call

```
image = Content.Load<Texture2D>(@"yourImage");

```

then you can draw it easily

```
spriteBatch.Begin();
spriteBatch.Draw(image, dstRect, srcRect, Color.White);
spriteBatch.End();

```

That's all !

srcRect is juste a rectangle that indicates where your image is in the texture. That way you can have multiple images in one texture.

For the VertexPositionColorTexture, you'll probably want to create your own spriteBatch. See here.
> 6 votes

---
Tags: xna, xna-4.0
---


# Question
Title: Should I distribute different versions of the same game for different mobile platforms?
I'm currently making a game on the Android platform. I don't know whether to do a "smartphone edition" and a "tablet edition" or simply to do one edition.

If I put high definition textures, the users of smartphones will have to download a heavy package, and thus will have very less space available as if it was "normal definition" textures. On the other hand, it's very hard to maintain two versions at the same time...

So how do you handle this? Even if you develop only for smartphones, do you send multiple versions of your game/app to the Android Market or not?

# Answer
> 5 votes
Usually, when you're making something that will be ported to different systems (whether a game for multiple consoles, or an app for various mobile devices), it's common to wrap your code so that anything that is specific to one system (rendering, event handling, etc) can be completely replaced without touching the code for the logic. SDL (and SFML) are examples of this sort of code, and there's other examples out there for various things.

Now, if the only difference between the mobile and tablet version is texture sizes, then you could probably set up your code to use either a configurable texture size, or different build options. If there's multiple differences between the two, then it gets more complex.

Of course, there's nothing wrong with focusing on one platform to start, and if your game does well/there's enough demand for it/you have free time, porting your game to a new platform once you make the gameplay solid for the initial version.

---
Tags: android, distribution, resolution
---


title: Efficient Way of Creating Menus in XNA

text:
# Question
Title: Efficient Way of Creating Menus in XNA
I'm a hobbyist and I've just finished implementing the "game" part of a game I'm developing, and I feel as if it finally matured enough to be worth adding a menu to start a new game, exit, edit options, etc., and so I tried to find sources online with tips for creating menus in XNA (first time creating a game in XNA).

So far, I haven't really found any good solutions. I guess I'm looking for a solution that isn't ad hoc so that I could easily reuse it for future games I decide to make. Is there any such built in XNA functionality I'm unaware of? Any XNA libraries out there that would prove useful? Or do you guys have any tips in general for easy/robust/reusable implementation of menus in XNA?

Thanks in advance!

# Answer
> 9 votes
You can try Game State Management code sample. I was using it in my first XNA game :)

---
Tags: xna
---


title: Get shape of my bodies using Box2D

text:
# Question
Title: Get shape of my bodies using Box2D
I would like to get the shapes of my bodies, but I can't get anything, only null. Why?
Here is the relevant code section:

```
Body b;
while((b = box2d.physics.PhysicsWorld.world.getBodyList().getNext()) !=null) {
  Shape shape;
  while((shape = b.getShapeList().getNext()) != null) {

    Log.e("name",""+b.getUserData().toString()+" "+shape+" ");

    opengl.saveMatrix();
    Meshes.select(b.getUserData().toString())
              .translate((b.getPosition().x)*RATIO, (b.getPosition().y)*RATIO)
              .rotate((int) ((int) b.getAngle() * (180 / Math.PI)), 0, 0, 1)
              .draw(shape, 1, 1, 1);

    opengl.loadMatrix();

  }
}

```

`shape = b.getShapeList().getNext()` always returns null, and the log entry never ran.

# Answer
> 5 votes
I'm guessing by the presence of `Log.e` and `toString()` that this is Java on Android. I don't know much about JBox2D in Java, but...

```
while((b = box2d.physics.PhysicsWorld.world.getBodyList().getNext()) !=null)

```

You're only ever going to get the second body here. I can't imagine this loop would ever terminate if it was entered. Your other loop has a similar problem:

```
while((shape = b.getShapeList().getNext()) != null)

```

In Box2D, shapes and bodies form a linked list. getBodyList and getShapeList return the head of that linked list, which is itself a body/shape, not an iterator. (Your loop is wrong even if it was an iterator, though! If something returns an iterator, you need to keep using the one it returned, not ask for it again.)

The loop you want is of the form:

```
for (Body b = box2d.physics.PhysicsWorld.world.getBodyList();
     b != null;
     b = b.getNext())

```

---
Tags: java, box2d
---


# Question
Title: rotating an object from sourceAngle to destAngle, both 0-359, clockwise or counter clockwise?
I've got a game object i need to rotate. It's current angle is player.rotation, the destination is targetAngle, both in degress, 0 to 359. I've got a function named rotateDirection(float sourceAngle, float destAngle) that needs to return -1 or 1 depending on whether the shortest way to reach the destination angle would be clockwise or counterclockwise.

For example - for sourceAngle 300 and destAngle 0 the function would return 1 for clockwise.

The solution is most probably going to leave me looking silly, and i usually don't like just asking for code, but my brain is completely broken so please help me with this one :)

# Answer
This should do:

```
(((source-dest+360) mod 360)>180)?1:-1

```

The +360 is only necessary for languages with a fuzzy `mod` function. Note that most languages implement fuzzy `mod`.
> 5 votes

---
Tags: mathematics, geometry, logic
---


# Question
Title: How to create mipmap for Unity3d textures loaded with www?
When I load a texture using the code below:

```
WWW www = new WWW(textureName);

yield return www;

renderer.material = new Material(Shader.Find("Diffuse"));

Texture tex = www.texture;
tex.filterMode = FilterMode.Trilinear;

renderer.material.mainTexture =tex;

```

The texture does not come with mipmaps, how can I tell unity to generate the mipmaps?

# Answer
You could simply create a new texture using the width/height information from the WWW's texture, and pass `true` to the `mipmap` parameter of the constructor. Then you can use the GetPixels and SetPixels methods to copy the data over (the texture returned from the WWW object is read-only so you probably can't modify it directly).

See also: http://answers.unity3d.com/questions/2814/how-do-i-generate-mipmaps-at-runtime
> 6 votes

---
Tags: textures, unity
---


# Question
Title: Are RTMFP Flash games the new big thing?
After watching (and playing) HaxBall, I can imagine that RTMFP (or any other real time multiplayer flash based technology) games will be the new big thing, replacing social games (cafeworld, etc).

What do you think about it? Is now the right moment to dedicate some time to learn how this technology works and how can it be used at its full potential?

Just your two cents.

# Answer
> 2 votes
Many browser games are single player. Of the multiplayer ones, there are lots of "social" ones (e.g. on Facebook), letting you play with your friends. Since your friends aren't online at the same time as you, these games are typically asynchronous — you play a bit, then they play a bit, then you play a bit. There are also some synchronous games — you and they play at the same time. These are common on XBox and PC not as common in the browser. You typically play these games with strangers.

I can't say it's the next big thing but the synchronous realtime games seem to be uncommon when it comes to browser games. Maybe people don't like playing with strangers. There are a few out there though. For example, there's Realm of the Mad God, which has hundreds of players online at once. (Disclaimer: the authors are friends of mine.)

# Answer
> 1 votes
I don't see anything about the game you linked, or the concept of "real time Flash-based multiplayer" games in general, that would distinguish them in any kind of revolutionary fashion from the glut of Flash-based games out there already, multiplayer or not. Nor do I see them as being all that distinct from most casual or social games that exist as well.

That said, just because there is nothing mind-blowingly revolutionary about them doesn't mean they are a dead end. If you are interested in the platform, understand the advantages and disadvantages of that platform (from both a technical and marketing perspective) and can make you game idea work within that context then by all means, invest some time in learning the technology.

---
Tags: flash, multiplayer, peer-to-peer
---


title: Get Vertices of a Shape/Body in Box2D

text:
# Question
Title: Get Vertices of a Shape/Body in Box2D
Is there a way to do it? I can get only polygon\_shape's vertices, but i want circle, box, etc too.

How to do it?

# Answer
> 6 votes
There's no such thing as a *box* in in Box2D (ironically). The `SetAsBox` method is a convenience function that creates a 4-ary polygon.

A circle does not have vertices, so you cannot get a list of them. A circle is defined by its radius and its position, and those are both accessible.

Edge and loop shapes use the same vertex storage as a polygon.

---
Tags: box2d
---


title: Interactive music games

text:
# Question
Title: Interactive music games
I've been seeing lots of simple interactive programs popping up all over the internet that generate basic music, usually quite nice sounding, from simple interactions from the user. Otomata is one recent popular example; on the iDevices there are a variety of programs, like Bloom.

I'm just wondering how these programs work. How do they generate the music live? Are there established APIs for doing this? I'm interested in the technical aspects of how this is implemented. My knowledge is so lacking here I'm honestly not sure how to better phrase the question. Ask if anything isn't clear!

# Answer
> 5 votes
Your question can be broken down into 2 components:

## 1. How do I generate musical sounds and timbres, and then play that through the speaker?

This is even a 2-parter:

### 1.1. How do I generate any kind of sound and play it back through the speaker?

Audio data is frequently represented and processed in 32 bit floating point numbers ranging from -1.0 to 1.0, representing. Open up an audio file in Audacity and zoom in to the sample level to see individual pieces of data. When you write data either to a sound file or to an audio buffer that goes out to the sound card, you typically map these -1.0 to 1.0 values to a fixed scale (no fractional values) of 0 to 65536 (for 16 bit depth) or 0 to 16777216 (for 24 bit depth).

Once you have your buffer constructed, you feed it to your sound device. This is library and platform-specific.

* Flash 10 added support for dynamically generating sound via the SampleDataEvent of the Sound class. You create a Sound object, but don't load any data into it. When you call Sound.play(), it will fire the SampleDataEvent, and the data member of SampleDataEvent will be a bytearray you can feed samples into. Read the docs for details.
* XNA recently gave you the option of using DynamicSoundEffectInstance, which is similar to Flash's sampleDataEvent.
* iOS seems to support AudioUnits, which are a standard way of generating sound in Cocoa (disclaimer: haven't used them myself). You could use this in a Mac application as well. (example: http://cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html)

---

### 1.2 How do I make my generated sound musical?

For a sound wave to have a sense of pitch, it must be generally periodic (obviously sound waves from instruments are not perfectly periodic, but we're talking broad strokes here). Any periodic wave can be constructed by adding together multiple waves of different frequencies and phases.

An spectrum analysis will show that the frequency with the greatest amplitude will generally be the pitch that the sound is perceived as. See this figure. To add depth, you also add waves with frequencies that are integer multiples of the base frequency (see the overtone or harmonic series).

---

## 2. How do I use my new robot zombie sounds to generate music on the fly?

This is a really open ended question, and is half of the fun of computer music. You can start somewhere as basic as selecting notes at random from a predefined scale, and then from there implement random rhythm variation as another step.

People do everything from selecting portions of music from a database of pre-written compositions (there's a really really thick book on a project to get a program to write 2-part Inventions in the style of Bach), to applying genetic algorithms to an initial interval vector and apply the results to different starting pitches.

Eventually you'll want to think about how to create larger movements of smaller, randomly generated musical components. As you start building up, this is where you can begin to insert game hooks. Maybe the angle of the mobile device can alter the range of notes, and when bad guys arrive you change the set of pitches in the scale to closer resemble a minor rather than a major scale, or adjust other properties such as attack envelopes and frequency of note events.

Timing can be tricky, because you don't want to be polling the elapsed time of your audio source, but you also want to be accurate. Relying on "sound complete" type of events will generally be much too slow. In Flash you can get away with musical timing for long sound cues if a 50ms delay is acceptable and it wouldn't be too obvious if you faded out one sound then started it again on another channel in sync with everything else. The catch is you need to check Channel.position on every frame update, unless you're manipulating your own sample data, in which case you're crunching a lot of data anyway just copying stuff to the SampleDataEvent buffer. Performance aside, just use basic ratios to figure out beat and tempo to millisecond interval conversions.

---

## *There's a whole wide world of audio programming fun out there*

A book that I haven't managed to read much of yet (damn school) is The Audio Programming Book by Richard Boulanger and Victor Lazzarini. The first 60-70 pages are a basic C primer wrapped up in music-specfic examples and may get a little boring, but they get to the good stuff later on like oscillators and filters.

There's a lot of popular visual tools, libraries, and mini programming languages for creating or prototyping computer music:

The newfangled "creative computing" frameworks like Processing, OpenFrameworks, and Cinder all have some basic audio capability as well, but nowhere near what you get with these dedicated tools. A classmate of mine models HRTFs in SuperCollider to simulate environments in a basic 3d environment. Another fun thing is to pipe OSC out of Unity and let it control a MaxMSP patch.

---
Tags: sound, music
---


# Question
Title: How to create a vertex array from any shape in JBox2D?
I have a code, that add a vertex array to a shape, my code is:

```
PolygonDef shape = new PolygonDef();
for (int i=0; i<vertices.size(); i++) {
    Vec2 v = vertices.get(i);
    shape.addVertex(new Vec2(v.x/RATIO,v.y/RATIO));
}

```

But its very strange because not working good on any of my polygon creator tool.

So with a triangle, it work good:

```
    ArrayList<Vec2> vertices = new ArrayList<Vec2>();

    vertices.add(new Vec2(0,-size.height/2));
    vertices.add(new Vec2(size.width/2,size.height/2));
    vertices.add(new Vec2(-size.width/2,size.height/2));

```

but with a bigger polygon of 50 to 60 vertices it's not working.

How I can create a usable vertex array from a shape? I have a greyscaled image with black and white colors... How can use this shape (image) to define my vertex array good?

And in box2D with the addVertex how I can add this points to make a normal usable polygon? (counter clockwise?)

# Answer
> 1 votes
(J)Box2D polygons are limited to 8 vertices. When you say it's "not working" I assume you mean you're getting the assert that fires when you pass in arrays that are too large, which should've led you to this yourself.

You will need to triangulate your polygons.

---
Tags: java, box2d
---


title: Gravity strength in first person games

text:
# Question
Title: Gravity strength in first person games
In our game, we set the acceleration due to gravity to the appropriate value of 9.8 m/s^2. Although physically correct, it feels more like moving around on the moon.. It feels about right at a value of 16 m/s^2. Has anyone else experienced this? Is it only because we don't have motion blur, or sound to give the apparent feeling of speed? Is it OK to just to set it to 16 m/s^2 if it feels right?

# Answer
> 12 votes
It could be that your scale is off. If you are looking at a brick and it seems to fall slower than it should, you may just have it scaled larger than a brick should be. I had this problem when I was working the physX engine. My entire scene was about 3x too big so I scaled it down and it worked.

If 16 seems better than 9.8 but you want to use 9.8. Just multiply the size of the object falling by 0.61. Which should scale it down to where 9.8 gives you the desired effect.

Edit: To fix this. I made an object that should be 1 meter tall. I scale it until it seems to fall at the right speed. Whatever the world units are compared to the new scale gives me my new unit scale. Example. If the object was scaled to 0.14 then that represents 1 meter in the game world. Make a ruler object that is .14 tall and when you design the level you will be able to use that ruler to scale everything correctly. That will cause everything to look like it's falling correctly at 9.8 m/ss.

# Answer
> 2 votes
I'd say go with whatever feels and plays right. However, it would be better if you were using the correct value - if only so you or other developers don't have a WTF moment when you revisit the code 6 months down the line.

Don't forget that your physics implementation is only ever going to be an approximation of the real world and that sometimes getting things "too close" to reality makes the game unplayable. Also there may be something else in your simulation that's "off". Double check that as well.

More than a few years ago I was involved with a helicopter simulator and the client wanted the controls to be "realistic". It failed because it was unplayable. Making the controls simpler made the game playable.

# Answer
> 1 votes
Modelling everything in the metric system I also observed that gravity feels much too weak with regards to the player jumping (in a platformer). Much like "on the moon", "jelly", "too much phyics", not "arcade" enough. On the other hand players in games are regularly able to jump to great unrealistic height too.

TLDR: high gravity feels very fast paced and arcade, realistic gravity sometimes might not give the desired game experience.

---
Tags: 3d, physics, first-person-shooter
---


title: How to make one solid object in Maya?

text:
# Question
Title: How to make one solid object in Maya?
How can I "glue" more objects to each other so I get one object? (It is for resizing models), couldn't find anything about it on the internet, but I'm dutch, so maybe that's why. Thank you very much!

# Answer
> 2 votes
If you want them to be resized, moved, and rotated together, use Grouping. Just select all of the models and click Edit-\>Group. This will allow them to be edited together.

---
Tags: objects
---


# Question
Title: WP7 emulator + Microsoft.Advertising.Mobile.Xna.dll = 'System.IO.FileLoadException' occurred in mscorlib.dll
I've downloaded Microsoft Advertising SDK for WP7, added reference to Windows Phone Game project, and now when I'm trying to run the game I get this in Output:

```
'taskhost.exe' (Managed): Loaded 'mscorlib.dll'
'taskhost.exe' (Managed): Loaded 'System.Windows.RuntimeHost.dll'
'taskhost.exe' (Managed): Loaded 'System.dll'
'taskhost.exe' (Managed): Loaded 'System.Windows.dll'
'taskhost.exe' (Managed): Loaded 'System.Xml.dll'
'taskhost.exe' (Managed): Loaded '\Applications\Install\B2719AD1-5A3C-40BE-A114-7E56C19E22D6\Install\TheGame.dll', Symbols loaded.
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
The thread '<No Name>' (0xd4b004e) has exited with code 0 (0x0).
The program '[229048418] taskhost.exe: Managed' has exited with code 0 (0x0).

```

If the reference is removed, game launches normally again.

What might be the possible solution to fix this?

# Answer
> 1 votes
Does your application actually fail to run, or does it just print that message to the output window and continue (there's no timestamps in the output window, alas, so I can't tell how much time elapsed between the first-chance message and the program-is-exiting message)?

First-chance exception messages like that aren't always indicative of a problem that needs to be solved, especially if they occur in code that isn't yours (unfortunately).

If you *are* crashing, I've seen this issue (and a fix for it) regarding WP7 development tools and another external assembly (not the Advertising SDK directly, but perhaps it's a related problem that could be solved with the same steps).

Other things you might try include turning on "break on throw" for all managed exceptions and disabling "Just my code" in the Options section of Visual Studio to see if you can break into the debugger when the exception is thrown -- this will let you examine the exception's FileName property and determine exactly which assembly isn't loaded -- this exception is thrown generally when the CLR finds an assembly but can't get it to load for whatever reason.

It's possible you won't be able to trap the exception if if occurs too deeply in code that belongs to the CLR loader, in which case you may need to use WinDbg or load the SOS.dll directly into VS to trap and print the exception (look into `sxe clr` in WinDbg and `!pe` from SOS).

---
Tags: xna
---


# Question
Title: Can one build a game based on something that already exists and make money off of it?
> **Possible Duplicate:**
> Is it legally possible to make a clone of the game?

I was planning on producing a game but then I had to stall. I have an idea to make a game, but its very similar to a game already out there. If I made my own graphics, audio and use my own code, would I be allowed to sell it?

# Answer
IANAL.

Gameplay ideas themselves cannot be copyrighted. If you need any evidence of this, just look at the wrath of clones of any specific popular game, such as Call of Duty or World of Warcraft, available on the market. You cannot use any of the original content, however, unless it's independent- for example, just because CoD uses an AK-47 doesn't stop you from using it, but because WoW has a race called the Night Elves pretty much does preclude you from doing something identical.

The general rule is that if the gameplay happens to be similar to an existing game at the end, then that's one thing, but if it's a straight rip of another game from the start, then you're not going to win many fans and may end up in court.
> 1 votes

---
Tags: game-design, productivity
---


title: Portal Projection

text:
# Question
Title: Portal Projection
Ok ok I admit, I'm bored and toying with a portal script like the one on steam.

I've figured out the following:

* relative positioning of the mirrored cameras
* render to texture for the portal (the texture is the view from the opposite camera)
* poly culling (since the camera is behind the other portal, I cull all polys behind the front face of the portal

I can't figure out how to scale the projection so I ignore everything outside of the back of the portal. Here's a picture to explain.

The back of portal 2, which is viewed from camera 2, is being displayed on the front of portal 1. My problem is the scale. I want to ignore everything around the dotted line and scale up the view from cam 2 so it fits the front of portal 1 perfectly. One big problem with that scaling is the perspective changes as you move around. I'm not good at matrix math to figure this out. Anyone have an idea?

I'm looking for some matrix I can set as the projection matrix for cam2 to make this work.

# Answer
Consider this as a pure 2D problem, you have the two renderings as 2D images and all you got to do is overlay one on the other, no scaling, moving around or funny angles of projection. If you just do the simplest copy pasting job you can imagine, it's going to fit perfectly.

I guess you might want to do this in a more seamless manner, using the cam 2 rendering as a texture for the cam 1 rendering. For that to work properly the cam 2 rendering must be the texture of a plane that is perpendicular to the camera angle in rendering 1.

I hope this answers your question, it sure will take a bit of trickery to get everything ordered just right.
> 2 votes

# Answer
This system is unnecessary. Just hardware instance the room (and it's contents), then translate it and rotate it if necessary to match up and let the GPU do the culling. This has the large advantage of making the world seamless- that is, you don't have to specially make the AI work with it or anything, as you're extending the world, effectively, rather than just rendering it twice.
> 0 votes

---
Tags: rendering, camera, matrix, projection
---


title: Fullscreen + Vsync = Stuttering

text:
# Question
Title: Fullscreen + Vsync = Stuttering
In my research for a stuttering problem in my game engine, I think, I have found the problem, but don't have any idea why this is happening, that's why I ask you if you have an idea !

The situation : DirectX10 under win7 simple engine. If running fullscreen (and only in fullscreen), with Vsync On and the rendering loop going much more faster than the vsync ==\> Stutter (Frame dropped by the driver).

My base solution at this moment : Make the call to device.present() not faster than the Vsync !

My questions : \- What is happening here ? It seems that the called to .present() "is caching" frames, and if the cache is full, it can go to throw away a frame ==\> It makes the stutter ! \- Why is it not happening in windowed mode under the exact same situation (back buffer resolution, scene, ...) ???

Edit : Here is a Pix debugging screen (big picture), showing the stuttering : http://www.s33m3.be/PIX/PIX3.png You can see that frame 912, that did exactly the same amount of work as other frames, wasn't processed by the GPU. (No GPU start/Duration). And after debugging, it just that for this frame the call to .Present() was really low (more then 10 times faster than the average .Present() of the other frames !

So how can I disable in DirectX10 this "feature" to throw aways frames ? I would prefer the Present method to hold instead of dropping a frame !

# Answer
That's not vsync. The call to Present() will block until the appropriate time if you have vsync enabled. This means that unless you're trying multi-threaded rendering, which DX10 does not support, this shouldn't happen- that is, it should be impossible to Present() multiple times a frame.
> 2 votes

---
Tags: directx, performance, vsync
---


title: Output from vertex shader in D3D9

text:
# Question
Title: Output from vertex shader in D3D9
I've been looking at creating some 2D rendering systems in D3D9, basically because I don't like ID3DXSprite. For the output of the vertex shader, what co-ordinate system does the run-time expect vertex co-ordinates in, like homogenous device co-ordinates? And secondly, does the depth of the resulting vertices have any effect except on the culling/depth buffering? I wanted to "reserve" a section of depth for use in 2D drawing, and then have a section for 3D geometry, to ensure that 3D geometry is always behind 2D.

# Answer
> 2 votes
> For the output of the vertex shader, what co-ordinate system does the run-time expect vertex co-ordinates in?

You should output vertices in clip space from the vertex shader (this is generally where things end up after the projection matrix is applied). The hardware will take the output of the vertex shader, perform clipping, and then perform the perspective division by `w` and continue along the pipeline.

> Does the depth of the resulting vertices have any effect except on the culling/depth buffering?

It could also be used in early-Z optimizations, potentially, and possibly a few other things like that. And maybe fixed-function fog, but I don't think anybody uses that any longer anyhow.

So in general, no. You're probably fine trying to reserve a range in the depth buffer for 2D versus 3D from that standpoint, although I suspect it may be a touch cumbersome to give the 3D elements proper depth from the eye to ensure they land in the desired range (it may be easier just to disable the depth test for the 2D elements or clear the depth buffer to the desired "2D far" value after all the 3D elements are rendered, or something, depending on exactly what you need).

The only other thing to be aware of it is the non-linearity of the depth buffer, so you should probably use a much smaller range for the 2D stuff since it will presumably be closer and thus in the more granular region of the buffer.

---
Tags: c++, directx, vertex, shaders
---


title: Initializing Direct X

text:
# Question
Title: Initializing Direct X
I've recently starting with Direct X; I've been using Rasertek's tutorials, and Frank Luna's book. One thing thats just out of this world to me is how much effort it is to initialize DX11: the swap chain and everything.

So...maybe to give myself a little bit of peace, is it mostly always going to be the same? I mean in Rasertek's tutorials it's like 8 different files, while nicely laid out seems to be a bit much; but I guess is it just required? It just seems a little long and hard to understand (the swap chain and everything).....but I guess my questions are:

1. Why is it so long, unlike OpenGL's initialization to start drawing which is 1/100th the size (it seems like)?
2. Is it basically going to be the same (Swap Chain, Message Handlers, etc) for all DX APIs (I'm working with DX11)?

# Answer
D3D10+ expose a much lower-level view of the driver/card than D3D9 did -- there are a number of nice advantages to this (control, consistency) but they come with costs, and one of those costs is that the API is *much* more verbose. Fortunately it's not hard to encapsulate all that verbosity away so you only need to deal with it once or twice.

For D3D10 and up, the general process will be quite similar. 9 is, as I noted, much different and a lot simpler. If you're using D3D11, you should be good to go for quite some time now.
> 1 votes

# Answer
DX10/11 requires more than DX9, because they have DXGI. However, there *is* a shortcut function. More importantly, the initialization to start drawing is pretty trivial, compared to what you're going to have to go through to load assets, etc.

http://msdn.microsoft.com/en-us/library/ff476083(v=VS.85).aspx
> 2 votes

---
Tags: directx
---


# Question
Title: Is a voxel engine appropriate for a Minecraft-like game?
Why does Minecraft use polygons to draw the world terrain instead of voxels? Would a voxel based rendering engine be appropriate for a fully destructible game world built out of cubes like Minecraft? Would it be more efficient than using polygons?

# Answer
> 31 votes
> Why does Minecraft use polygons to draw the world terrain instead of voxels?

Graphics hardware works with and renders triangles, so you have to use triangles if you want hardware acceleration. Most voxel renderers employ something like Marching Cubes to extract a polygonal mesh from a voxel representation and present that; direct volume rendering is typically computational expensive.

> Would a voxel based rendering engine be appropriate for a fully destructible game world built out of cubes like Minecraft?

Yes.

> Would it be more efficient than using polygons?

Probably, but not because voxels are faster or cheaper to render (in fact, they're more expensive to render since you must convert the data set). Voxel representation lends itself to *manipulation* easier than polygons -- so it's much easier to add and remove chunks, bits and pieces of the world represented by the data set.

---
Tags: voxels, minecraft-modding
---


# Question
Title: animation and game development tutorial for iphone
Can anybody suggest a good game development and animation tutorial for iphone

# Answer
> 2 votes
You might check out O'Reilly's iPhone Game Development book if you're talking about more 2D sprite oriented animation (think "Angry Birds").

But if you're talking 3D style animation, you'll need to decide whether you're going to write it yourself (a lot of work) or use a commercial game engine like Unity 3D or Unreal.

# Answer
> 0 votes
Without any information on your requirements, i can only link to the most popular iOS game development environments around, which are cocos2d and unity

---
Tags: iphone, animation, ipad
---


title: Key combinations on poll-based input

text:
# Question
Title: Key combinations on poll-based input
So assume you have an input system that is based on polling

```
void update()
{
    if( Keyboard[ 'A' ] )
        // A is down
}

```

Say you want to be able to recognize 3 to 8 length key combinations (like down, down-forward, forward, A for hado-ken)

How would you best create a generic (easily modifiable/programmable) key combination input system on *polled* input?

# Answer
> 7 votes
Fundamentally, *you can't*. Key combinations require an ordering, and an ordering requires events.

What you can do is turn polling into events by comparing the key states each frame and generating post-hoc keyup/keydown events from the differences. It's not as reliable because you lose the timestamping and other intra-frame ordering that "native" event systems provide, but it will allow you to detect and order at least one key per frame.

Once you have those ordered events, you can use a finite state machine or other tool to match them against your move lists and execute the correct one.

# Answer
> 3 votes
One way is to store the current and previous input states, and compare them every time that you poll the input.

For each key that can be pressed, store an object that has a timestamp of the last time that the key switched from a down state to an up state.

Update these objects by doing this at every poll:

```
void update(){
    some_key_has_been_pressed = false;
    foreach(key in keys){
        if(previous_input[key].Down && current_input[key].Up){
            keys[key].up_timestamp = current_time();
        }

        if(current_input[key].Down){
            keys[key].down_timestamp = current_time();
            some_key_has_been_pressed = true;
        }
    }
}

```

Now you can pattern match your combos against the contents of `keys`.

Have a combo object for each combo, and call update() on each combo object at each poll.

A combo object's update() method will pattern match the combo, checking if all necessary conditions for the combo are satisfied at this poll. I.e. all keys timestamps for the combo so far are in order, and no other key that would break the combo has been pressed this frame. For each condition met, increment a counter in the combo object to the next condition to check. When all conditions are met in a combo, call the method that the combo should perform. If `some_key_has_been_pressed == true` but the key that is the next condition for the combo has not been pressed, then reset the combo's satisfied condition counter to 0.

The above is my preferred method, as it is simple to implement, easy to maintain, efficient, and highly modular.

However for another good method, check out the XNA input sequence sample, which is written in C#, and the logic is likely transferrable to the language you're using.

# Answer
> 1 votes
Make a stack of the last X key events, for each key event add an object with the key and time of the press/release, then check if the last members of the stack match a special pattern and if those keys were pressed fast enough to count as a combination. Finally remove the oldest object from the stack.

---
Tags: input, keyboard, polling
---


title: Rcon Api not working

text:
# Question
Title: Rcon Api not working
I am developing a gaming control panel and that uses `Rcon.jar` to fetch data from gaming server.

the code to use it written as below

```
public static String rconExecute(String rcon, String command, int port, String ip) throws SocketTimeoutException{
        String response = "";
        try {

            response = Rcon.send(27778, ip, port, rcon, command);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return response;
    }

```

this throws an error when run using site but when done using local application like

```
public class RconTest {

    public static void main(String args[]) throws SocketTimeoutException, BadRcon, ResponseEmpty{
        String response = Rcon.send(27778, "59.177.45.13", 27015, "123", "status");
        System.out.println(response);
    }
}

```

it works fine any reason why?

the error is :`java.net.SocketTimeoutException: Receive timed out`

# Answer
You need to narrow down what might have caused the error. Timeout might mean either it can't reach the server at all, or it can, but the server isn't accepting the connection.

Check everything you're assuming - like the port number, the server IP address, etc. When you find yourself with a, "But it HAS to work!" bug, that usually means you're assuming something that isn't true.

In that vein, note that the call to Rcon.send in the two code examples aren't identical - one has parameters passed in and the other has hardwired parameters. You're assuming the parameters passed (like ip address) are correct. If you replace the Rcon.send line in example 1 with the hardwired one in example 2 does it work?
> 1 votes

# Answer
I'm not too familiar with rcon, is it the remote administration protocol from Valve?

If so, is the web server on your machine? What is this IP address, yours? Is it properly routed with the right ports (if you're behind a rounter)? Is your firewall accepting incoming connections on this port from your web server?

If you install a web server on your PC, does the code work? This would mean that your server is most likely only accepting connection from your localhost or that the firewall / router config is preventing external connections.
> 0 votes

---
Tags: java, steam
---


# Question
Title: How would I setup fog to follow a players coordinates?
I'm wondering if its possible to setup a fog to a player's coordinates (where there is fog around the player to make it more third-person) the main reason I ask this is because I have my player more towards the top right corner of the screen

Here's some code that can give you a guide on what im doing:

```
glEnable(GL_FOG) GLfloat FogColor[] = {0.8,0.8,0.8,1.0};
glFogfv(GL_FOG_COLOR,FogColor);
glFogi(GL_FOG_MODE,GL_LINEAR);
glFogf(GL_FOG_START,30);
glFogf(GL_FOG_END,);
glHint(GL_FOG_HINT,GL_NICEST);

```

and I want the fog to follow a player with a position as said in

`posX,posY,posZ`

If anyone can turn this into some example code that would be very helpful, thanks

If this is not possible then how would I setup the fog to be around a certain position of the camera, like show on the top right corner of the camera instead of the center?

Here's a picture of the game screen so you can see what im talking about:

# Answer
I think this would be most easily accomplished using shaders. If you don't have the ability to use shaders yet I'd recommend figuring them out regardless because they're super useful for lots of things like this. Operating under the assumption you can use them, here is a vertex and fragment shader that will create a grey radius fog around your character's location (with simple texturing).

Vertex Shader (fog.vert):

```
uniform vec3 playerPos;
uniform sampler2D colorMap;

varying vec3 vertexToPlayer;

void main(void)
{
    vec3 vertexPos = vec3(gl_Vertex[0], gl_Vertex[1], gl_Vertex[2]);

    vertexToPlayer = playerPos - vertexPos;

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

```

Fragment Shader (fog.frag):

```
uniform vec3 playerPos;
uniform sampler2D colorMap;

varying vec3 vertexToPlayer;

void main(void)
{
    const float radius = 1024.0;

    float dist = length(vertexToPlayer);
    float attenuation = clamp((radius - dist) / radius, 0.0, 1.0);

    vec4 diffuseTexel = texture2D(colorMap, gl_TexCoord[0].st);
    vec4 diffuseTerm  = diffuseTexel * attenuation + (.8 * (1.0-attenuation));
    diffuseTerm.a = diffuseTexel.a; /* preserve alpha */

    gl_FragColor = diffuseTerm;
}

```

Then, somewhere in your code, pass in your values for the player position with:

```
GLint playerPos = glGetUniformLocation(prog, "playerPos");
glUniform3f(playerPos, xPos, yPos, zPos);

```

Hope this is helpful!
> 1 votes

# Answer
Use fog coordinates. http://www.opengl.org/registry/doc/fog\_coord.txt

Normally, the fog value is computed using a distance factor from eye to the pixel 'c'. In effect, the fog density is a function of distance.

f = exp(-d\*c) -- GL\_EXP2
f = exp(-(d\*c)^2) -- GL\_EXP
f = (e-c)/(e-s) -- GL\_LINEAR

Fog coordinates allow you to set the 'c' value of the equation and specify values directly for this. If you want to set up fogging so that 0 -\> no fog, 1.0 -\> most fog, then do:

```
glFogi(GL_FOG_MODE,GL_LINEAR);
glFogf(GL_FOG_START, 0.0f);
glFogf(GL_FOG_END, 1.0f);

//This actually enables the "fog coordinate" mode
glFogi(FOG_COORDINATE_SOURCE_EXT, FOG_COORDINATE_EXT);

```

Then, when you render your person, use glFogCoordfEXT()

```
//Show fog (some value between 0.0 - 1.0f)
glFogCoordfEXT(1.0f);

renderPerson();

//No fog
glFogCoordfEXT(0.0f);

```

Edit: An extensionless alternative is to disable fog when rendering everything, then enable fog with appropriate start/end distances when rendering your character.
> 0 votes

---
Tags: opengl, c++, rendering
---


title: Skybox texture artifact on edge

text:
# Question
Title: Skybox texture artifact on edge
I have strange problem with drawing skybox texture on Mac. On iPhone everything is going fine. I have tried to change near and far planes value with no success.

It is a skybox of six textures, and for every texture I set this:

```
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

```

What could be the problem?

Screenshot:

**EDIT:**

I have tried to set background color to red, to ensure if it is bleeding through the texture

I have also tried to change coords of the texture to this:

```
float err_corr = 0.5 / TEXTURE_SIZE;

GLfloat vertices[24] = {
        -1.0f - err_corr, -1.0f - err_corr,  1.0f + err_corr,
    1.0f + err_corr, -1.0f - err_corr,  1.0f + err_corr,
    -1.0f - err_corr,  1.0f + err_corr,  1.0f + err_corr,
    1.0f + err_corr,  1.0f + err_corr,  1.0f + err_corr,
    -1.0f - err_corr, -1.0f - err_corr, -1.0f - err_corr,
    1.0f + err_corr, -1.0f - err_corr, -1.0f - err_corr,
    -1.0f - err_corr,  1.0f + err_corr, -1.0f - err_corr,
    1.0f + err_corr,  1.0f + err_corr, -1.0f - err_corr,
    };

```

And the box is drawn in this order:
`GLubyte indices[14] = {0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1};`

**SOLUTION:**

The solution is to set **GL\_CLAMP\_TO\_EDGE** for the cubemap itself!

```
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

```

# Answer
> 8 votes
Are you positive that you've set GL\_CLAMP\_TO\_EDGE **for each individual texture**? This is a part of individual texture state and it defaults to GL\_REPEAT, so this needs to be done after binding with glBindTexture. I realize in the original post you literally say that you set it for each texture, but I'm wondering what the code actually looks like?

For example:

```
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glBindTexture(GL_TEXTURE_2D, tex1);
//upload texture, etc.

glBindTexture(GL_TEXTURE_2D, tex2);
//upload texture, etc.

```

This is not the same as:

```
glBindTexture(GL_TEXTURE_2D, tex1);
//upload texture, etc.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glBindTexture(GL_TEXTURE_2D, tex2);
//upload texture, etc.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

```

# Answer
> 1 votes
inset '0.5f / texture\_width' from the left and right side of the texture and '0.5f / texture\_height' from top and bottom. You're seeing sampling artefacts - texture samplers usually sample from the centre of texels so on the left and right, top and bottom (at 0 and 1 uv) you're getting 50% of whatever texel your sampler gets when it's out of bounds. That's either the other side of the texture or a default sampling colour.

# Answer
> 0 votes
My best guess is that the difference between MAC and iPhone is caused by antialiasing on the MAC. My 3D programming is a bit rusty, but I guess you would have to make all the squares part of the same mesh or something like that.

Dirty hack solution would be to make all the squares a bit too big so they overlap and clip each other and adjust UV coordinates accordingly.

# Answer
> 0 votes
This is usual problem with cubemaps on older HW (or iphones maybe). Check for the

```
GL_ARB_seamless_cube_map

```

extension if it is available on your hw. If so. Problem will be propably solved by using it.

# Answer
> 0 votes
Are the six textures set up, specifically, as a cube map or are each of the skybox faces rendered separately with their own texture? I heard some *early* PC systems had rather poor filtering when it came to handling cubemaps in that they didn't necessarily filter across the from one face texture to the next when you sampled near the cube edges. AFAIK the SGX (iphone GPU) should filter across edges correctly.

It did occur to me that the bottom of your side textures looks to be a similar shade of blue to the artefact . Could you try, say, making the bottom row (or a few rows) of pixels a hideous shade of magenta and see if that changes the artefact colour? That might give some more idea of what may or may not be happening.

---
Tags: opengl, textures, macos, sky
---


# Question
Title: Game programming books that don't teach programming?
I am an normal programmer with about 3 years of experience, who is interested in getting into game development. The problem that I face is that when I look at these "beginner" books, most of them teach basic programming skills, and I don't have the patience to sit through it or find them worthwhile. But, when I look at more advanced books, they're over my head, and once again, fruitless to me. What I'm looking for, are books that explain the nitty-gritty internals of games, but at a more reasonable level.

For example, I'm very familiar with all kinds of data structure (hashes, trees, linked lists), and with many common algorithms (sorting, searching), but I wouldn't know how to, say, implement collision detection effectively. I also have experience using foreign libraries, so I know how to use documentation to learn an API, so I don't need a "Learn to use X" book either.

Personally, I don't care what platforms/languages/libraries are used in the books, since I'm comfortable in many languages, but the game I'm looking at making would use Javascript and the HTML5 canvas.

Any suggestions? Any that are free?

P.S. I should note that my level of mathematics and physics is relatively low, and a book that gently integrated those things would be a plus.

EDIT: I should mention that I'm interested in 2D programming, and at this point I don't really care for 3D yet.

# Answer
Have you looked at Game Programming Gems series? It might give you the specifics you seem to be asking for. There are not many books out on HTML5/canvas as it is quite new, especially ones talking about game programming.
> 11 votes

# Answer
What aspect of game programming are you curious about? There's quite a few books that discuss specific aspects of game programming. Getting a game up and running is not difficult, and any game logic is just like how you'd manage data for any other application, perhaps a little more concerned with speed of execution. Getting into stuff like graphics programming though, can be something else entirely. Start with a basic framework of a game, then focus on one area you're interested in, like designing a robust combat system, or synchronizing animation, or shaders.

General-info type books that I've found useful:

You're probably at the stage where you'll get the most information by looking at various tutorial postings for specific engines online. There's also a decent enough number of open source games you can check out.

One interesting thing to study might be the Monocle Engine.

---

**Edit**:

With regards to math, I'm also a little shaky on my foundations. A good resource for these general subject areas is Khan Academy.

For other free stuff, just browse GameDev.net, and possibly the MSDN articles for XNA.
> 9 votes

# Answer
If you're confident with object-oriented programming, you should make sure you pick up something which covers component-oriented design. It's a programming approach within OOP that is very powerful in games development and has become a standard approach within the last decade.

Two resources that contributed massively to my understanding of COD:

There is an answer on Stack Overflow that contains an incredible list of resources: Component-based software engineering in game literature.

Note: COD isn't used solely in games development. You may find resources that explain COD in completely different contexts, which won't necessarily be helpful at all for understanding the role it plays in games (YMMV).
> 6 votes

# Answer
I'll add to the deluge of titles here:

Game Engine Architecture by Jason Gregory (Naughty Dog) for general game engine overview at a reasonably detailed level.

Real-time Collision Detection by Christer Ericson (God of War) for an in-depth and comprehensive overview of collision detection systems.

Real-time Rendering by Tomas Moller and Eric Haines for a similarly in-depth treatment of rendering.
> 6 votes

# Answer
I recommend Introduction to Game Programming with DirectX 9.0c: A Shader Approach by Frank Luna. It's also available for D3D10 if you're curious. The book assumes basic C++ knowledge but nothing game-specific and no COM, and begins with various mathematical foundations like vectors and matrices, and fairly gently guides the user through setting up games from basic to the intermediate. What's notable of course is that as time goes on, then things change- for example, he doesn't teach hardware instancing or other optimizations that are *relatively* new.
> 5 votes

# Answer
I just found a publisher with what seems to be a great list of possible books: http://www.courseptr.com/Courses.aspx?MenuId=8&MenuSubId=0 \- they're the publishers of the Game Programming Gems series.
> 1 votes

---
Tags: books
---


# Question
Title: Different collision effects on different objects
I'm a beginner to Corona and game development. I am using a variety of objects in my game. On collision, they all perform the same function. I want them to do different things, and also want some objects to only collide with certain other objects. How would I go about doing this?

# Answer
> 1 votes
Collision events parameters for the objects involved in a collision. The parameters are named "other" or "other1" depending how how exactly you setup the collision event listener. Here's the documentation:

http://developer.anscamobile.com/content/game-edition-collision-detection#Global\_collision\_listeners

To have control which objects actually collide use collision masking: http://developer.anscamobile.com/content/game-edition-collision-detection#Collision\_categories\_masking\_and\_groups

---
Tags: collision-detection
---


# Question
Title: Experienced coder/designer moving into game development - what's involved?
I am interested in moving into game development once my current project is done, as it's nearly at a point where it will pay my bills and allow me to hire someone else to take the driver's seat, meaning that, for the first time in my working life, I'll be in a position to devote a proper amount of energy to getting into game development, which has been something I've wanted to do for a long time but forced myself to wait on, as there are only so many hours in the day to devote to projects.

I am an experienced web developer (12 years) with most of my experience programming in C# and .Net (8 years). I am also a capable graphic designer. I have a surface knowledge of C++, though it's been 10 years since I wrote any C++ code. I also played with the DirectX 5 API back then as well.

I am happy to outsource graphics and sound, leaving me with coding, game design, level design and so forth.

* Do I need to learn C++ properly, or can I rely on my C# and .Net knowledge?
* If I'm going to leave C++ out of the equation, am I seriously limiting myself with regards to platform agnosticism?
* Given that my memory of mathematics (high school level) is hazy at best, how much time I do I need to devote to pure maths self-education, or can I pretty much figure it out as I go?

In a nutshell, I'd love to get some idea of what the best approach for me would be, including DO's and DON'T's that might slow me down. I know that baby steps will be required at first, but it would be nice to get some advice as to what path I should follow to get myself up to speed quickly so that I am able to create decent indie games with nice looking 3D graphics, AI, particle effects and so forth.

# Answer
> 4 votes
The main focus when first getting into game development, especially if you are doing solo development, is choosing an approach which will allow you to finish a game. The world is littered with half-finished prototypes of every game genre imaginable, but bringing a game through to completion is much more difficult.

So, to expand on what void said, stick to what you know, and choose a game to develop that is both something you would enjoy playing and is a relatively simple concept. Bring it through to a fully playable state with a simple version of every subsystem in place (that is, as appropriate have some simple graphics, a frontend system, HUD/overlays, a save/load system, networking, whatever the game needs to be complete). Then you can upgrade each part of the game as you get more comfortable. Don't worry too much about your first game being your magnum opus, as you get more confident in game development you will know when the time is right to step up your work, start work on a new game with a larger scope, or start focusing on cross-platform development.

As for mathematics, your knowledge will need to scale with the specific tasks that you are trying to accomplish, and will also depend on how much you are trying to develop on your own versus using third-party packages to accomplish things for you. For example, manipulating objects in 2D or 3D space requires some knowledge of matrix algebra and vector math, but nothing too complicated. Creating an animation engine will likely require knowledge of quaternions. Developing a physics engine requires some knowledge of calculus - the more complex your physics engine, the more complex calculus you need to get into.

I would recommend looking into third party packages like ODE so you can sweep away some of the more complicated mathematics and focus on developing your game. Then later, if you decide to take on developing these underlying systems yourself, you can buckle down and learn the maths you need to develop effectively in a just-in-time fashion.

# Answer
> 1 votes
As you are just doing this for yourself and are not aiming to get employed as a game programmer, I would suggest sticking to what you know: Use C#. There seems to be a lot of movement doing gamedev in C# with tools like XNA and Unity3D. There has also been some cross platform games like SpaceChem delivered using C# on mono.

You can always try to do stuff in C or C++ just to learn something new, or fresh up on old knowledge. Low level programming is not going away, but it might not be your main focus.

---
Tags: c++, c#
---


title: A good way to prototype game ideas?

text:
# Question
Title: A good way to prototype game ideas?
We, as in my 4 person indie group, have an entire whiteboard that looks like graffiti for prototyping our game ideas. We look at it every day and choose which idea draws us in the most when we near time to start a new project. We also randomly draw characters that seem interesting even if they have no gameplay associated with them. This works but doesn't always seem to give us the best understanding of our ideas. We tried a rule that if you come up with a game idea, build a very basic prototype and show us, but that also wastes time.

So, my question is "what is a good way to prototype game ideas". We need a balance between getting the idea across and not skipping it because we don't understand it, but also not wasting time building up a ton of ideas that will never be touched. What is an efficient way to describe the major aspects like gameplay, art feel, special features, audience, etc.

# Answer
> 5 votes
It sounds like you also need some pre-prototyping organization, too. Make a list of all your current ideas. To generate a rough ranking, each team member assigns each idea a score from 0 to 3 that indicates how badly they want to move the idea to the next stage. Everyone should try to have an even number of ideas at each ranking level (with 30 ideas, each person should have 6 or 7 0-ranked ideas, 6 or 7 1-ranked ideas, etc.). Next, for each idea add everyone's scores to get a total that will be from 0 to 12. With luck you will have from 1 to 3 top-scoring ideas to move forward with. After that, follow Tetrad's advice. Personally I love paper prototyping. With things on cards or slips of paper, it is incredibly easy to do things like reorganize a tech tree or explore variations on puzzles. I find a camera very handy for recording the good stuff you find as people are moving things around.

# Answer
> 13 votes
The only thing that's important is getting game playable as quickly as possible, and being able to iterate on the game as quickly as possible.

So with that in mind, there are a lot of things you can do.

1) Pen/paper play it. If it's a level, draw it out on the white board and storyboard the major beats. If it's an RPG style game you can pen and paper it DnD style. If you're trying to prototype an art style, paint it up. You don't have to get everything to 100% in some 3D engine just to test something.

2) Try out ideas in a rapid prototype environment. For example, using Unity. If you have to write code, you should be doing it with the highest level programming language you are comfortable with. There are related questions for this, like Recommended 2D Game Engine for prototyping and When creating quick prototypes, is it better to use the language you are going to use in the end?

3) If you must do it in your own engine, be sure to employ practices that allow you malleability of code and content. Make sure your tools are good so you can drop in content quickly. Try to write code in such a way that you can modify it easily. Employ a source control solution that allows really easy branching like git or mercurial so you can try things with impunity.

---
Tags: game-design, prototyping
---


# Question
Title: Push and damage player pawn when hit by rotating pawn? (UDK)
I'm working on a game in which the player runs around a level themed as a pinball machine. There are flippers that react to the presence of pinballs by flipping (as one would expect pinball flippers to do). The problem that I'm having is that if the player is in the path of the flipper as it rotates, the player is instantly killed. The desired behavior is that the player is damaged and pushed away from the moving flipper.

I've tried all sorts of things to make this stop happening. Currently, in the flipper, I have the following code to handle the collision:

```
event Bump(Actor other, PrimitiveComponent otherComp, Object.Vector hitNormal)
{
    local vector pushVelocity;

    if(/*If Flipper is moving and is bump()ing the Player*/)
    {
        pushVelocity = hitNormal * CalcLinearVelocity(vsize(location - other.location));
        player.TakeDamage(playerDamage, none, player.Location, pushVelocity * 2.1f, class'DamageType', , self);
    }
}

```

By using all sorts of logging, I can determine that the code in question *is* being called when the flipper hits the player and the player is being killed on the first frame this collision occurs--logging within the if() block only appears once. And yes, `playerDamage` is a value low enough that it would take many hits to kill the player.

Does anyone have any insight as to why the player is immediately dying instead of being damaged and pushed away? Or what sorts of things I should try to get my intended behavior?

# Answer
It took a while but I eventually found a fix for it. Some debugging eventually revealed the player was being telefragged. Intercepting `EncroachedBy()` in our player's Pawn class with a no-op has stopped the issue:

```
event EncroachedBy(Actor Other)
{
    //NOP!
}

```

I'm not sure if this is just putting a band-aid on a severed limb here but it's working now.

Thanks for the suggestions above!
> 3 votes

# Answer
There's a chance this is the same problem I saw working on a UT3 mod a long time ago. If your pawn is at risk of interpenetrating the world geometry, the pawn is killed via the event FellOutOfWorld. This happens quite frequently if your pawn is forced to ragdoll and subsequently gets pushed around.

I believe the interpenetration=kill hack was originally implemented in native code in UT3, and I couldn't tell you if it has since been moved out into UnrealScript in subsequent updates to the UDK sources.

My workaround, taken from my pawn class, ended up looking like this (again, this is against UT3 code):

```
/** If someone falls out of the world while ragdolled, they have
    this many seconds to stand up before they're killed. */
var float OOWGracePeriod;

/*
 * Extremely common scenario:
 *   1) Pawn is ragdolled and has a substantial vertical impulse applied.
 *   2) Pawn very briefly "leaves world" upon ragdoll impacting ceiling.
 *   3a) Pawn would recover immediately; however, they were killed for falling out of the world.
 *   OR
 *   3b) Pawn's ragdoll collision geometry interpenetrates world geometry and gets stuck.
 *
 * In the event of 3a (99% of the time), we don't want the pawn to die.
 * In the event of 3b ( 1% of the time), we don't have much choice but to euthanize them.
 *
 * Therefore, give them a grace period in which to recover.
 */

simulated event FellOutOfWorld( class dmgType )
{
    if ( ! bForcedFeignDeath )
        Super.FellOutOfWorld(dmgType);
    else if ( ! IsTimerActive('KillIfStillForcedRagdoll') )
        SetTimer( OOWGracePeriod, false, 'KillIfStillForcedRagdoll' );
}

function KillIfStillForcedRagdoll()
{
    if ( bForcedFeignDeath )
        Super.FellOutOfWorld( class'KillZDamageType' );
}

function FeignDeathDelayTimer()
{
    Super.FeignDeathDelayTimer();

    if ( ! bFeigningDeath )
        ClearTimer( 'KillIfStillForcedRagdoll' );
}

```

---

EDIT: Almost forgot there was a second part to this.

```
/*
 * Another extremely common scenario: Ragdolled pawn gets crushed upon impacting wall.
 * Therefore, don't let crush damage from the world affect us while we're force-ragdolled.
 */

event TakeDamage( int Damage, Controller EventInstigator, Vector HitLocation, Vector Momentum, class dmgType, optional TraceHitInfo HitInfo, optional Actor DamageCauser )
{
    if ( bForcedFeignDeath && dmgType == class'DmgType_Crushed' && DamageCauser == None )
            return;

    Super.TakeDamage( Damage, EventInstigator, HitLocation, Momentum, dmgType, HitInfo, DamageCauser );
}

```

Yes, it was an egregious hack. But there was no way around those when working with UT3, because of how much stuff is implemented in native code. I can't imagine it's that much better with UDK.
> 2 votes

# Answer
Are you moving the player to the boundaries of the flipper when the collision occurs? I guess you don't do that and therefore:

* the player collides with the flipper, ...
* takes damage, changes direction (because of the collision),...
* **but** since the player wasn't moved out of the collision area, it hits the flipper again and takes damage...
* maybe the direction is reversed here once more and therefore you're in some sort of "collision-loop" where the player takes damage with every update.
> 1 votes

---
Tags: udk, unreal
---


title: Open Source Engine for RTS

text:
# Question
Title: Open Source Engine for RTS
I must write a cross-platform real-time-strategy game within 2-3 months. I want use C++ and OpenGL and am looking for an engine.

The engine must be open source and work under both Linux and Windows. Preferably it should work with 3ds Max models. I do not know the game engines. Which engine would you recommend?

# Answer
I know of three that still seem reasonably actively developed: Spring, OpenRA and Stratagus. Wikipedia has a list of open source game engines, some of which may be appropriate for an RTS game (such as FIFE, which used to bill itself as a Fallout-style engine, but should still be appropriate for RTS games).

Some of these engines may work directly with 3DS Max model files, but that file format (.3ds) is actually pretty archaic, cumbersome, and suboptimal for direct consumption by a game engine, so you may find that the engines instead support some other model format that Max can export to (or supply their own conversion tools).

Also, it's not open source (~~and does in fact cost money~~ might cost if you need certain features), but people have used Unity to make RTS games as well.
> 6 votes

# Answer
There is also Glest.
> 2 votes

# Answer
Irrlicht is a great open-source 3D game engine. It doesn't have RTS-specific features but it could certainly be used to create an RTS (or any kind of game).

It's written in C++, runs on Windows or Linux and supports both OpenGL and DirectX.

Irrlicht is
> 0 votes

---
Tags: opengl
---


# Question
Title: Isometric Tile maps - best practice - games like farmville, tapzoo...?
Hey guys, Whats the best practice to create games like farmville, tapzoo...Do I create a simple grid/tilemap as the background and then just have the objects (like houses and whatnot) as sprites ontop? Or can I also just use a regular image as a background and just make my sprites move on the basis of a non graphical grid? How do I go about the isometric perspective of the map? How would I increase the size of the map(for example in an mutable array i could add more locations or I could set already instantiated locations to bool:valid...)? Do I have to use a game-freindly language like cocos2d or can i just use obj-c with UIImageViews...or is very bad practice because of the amount of memory it consumes? What the best practice to create something like this?

If you can answer anyone of these questions you are friggin awesome! Thanks!

# Answer
> 1 votes
If you have custom maps in your game, and want to be able to create many different maps or have map editors, having tiles and then objects like houses on top is probably the way to go. Most older strategy games follow this approach. There are RPGs like Baldur's Gate, on the other hand, which have a big image for each map. The downside of this is that you cannot be really generic in the way you create maps - they tend to end up with a fixed number of maps.

On rendering the isometric tiles - it can get somewhat tricky, but here are some ideas.

Map tilesets, or moveable areas can be represented by many different data structures. Array is one option, quad trees trade off memory-usage for performance as they allow you to compress your map representation somewhat. Both can have variable sizes.

In any case, I recommend you first define more precisely what kind of a game you want to do, and list all the requirements and goals. Try to be able to create something rudimentary first, and optionally evolve it later.

# Answer
> 0 votes
The simple answer is: Do as you like. There are almost as many formulas for creating games as there are games.

If you want a more specific answer you got to be far more specific about what you want to create.

I guess that you are a beginner in game programming, in that case the most valuable piece of advice I can give you is keep it small and simple.

---
Tags: tiles
---