# Question
Title: I can't figure out how to animate my loaded model with Assimp
I have loaded in a model to my C++ OpenGL game. It is a COLLADA file type that I have loaded, and I setup an animation under blender for the file. The problem is I don't know how to animate the model. The Assimp documentation didn't really help me out. Their source code didn't use animations, and I can't seem to find anywhere online that someone explains how to animate your loaded model... I'm sorta wondering if someone could link me to a helpful website, or maybe just help me out, so that maybe I will understand how to do animations with assimp.

# Answer
> 64 votes
Disclaimer: I use AssimpNet which is a managed wrapper around Assimp, though the object graph used by Assimp remains unchanged so the process is equivalent no matter the platform.
I personally think Assimp is a wonderful idea, and has saved me countless hours, but translating their graph to your engine *is* writing an importer and learning everything required to do so.

I am assume you are referring to Skeletal animation, rather than blendshapes or just individual nodes (though the latter I'll mention anyway).

As you'll know, Assimp collects entities in your source file in a tree of `nodes`. These nodes can have things like `meshes` attached to them, to identify visual geometry, or they can be 'abstract' nodes which exist to identify the world transforms of things like lights, and in your case, bones. Many file formats will 'flatten' the hierarchy so you will have a model with a single level of children, each one with a mesh. COLLADA is not one of those, and therefore its a little more complicated because if you want your imported model to behave correctly, you need to preserve its structure.

Take the above diagram. The dashed boxes are Node objects, some have meshes but all exist within the graph eminating from the Root Node which you find in the scene object.

**Importing the Animations**

Importing the animation data is the simplest part of the process. The `aiScene` object will have a member `aiAnimations` which is a list of `aiAnimation` objects. Each `aiAnimation` will have a list of `aiNodeAnim`* objects, in the `mChannels` member. Essentially, each channel controls a single node, and contains a list of keyframes, each with a scale, a rotation, and a translation value for this node at a specific point in time. Animation tracks identify nodes to control via their name.

(It is worth nothing at this point, that some exporters (such as 3DSMax) combine animations in odd ways, resulting in a single animation containing tracks for unrelated nodes, so if you are not animating a skinned mesh, make sure you check all the animation objects!)

So, say you are animating "Box". You have already imported the node 'Box' with its geometry and you have an item in your world with a transform. To animate the box, get the animation from `aiAnimations` and iterate over each `aiNodeAnim` (channel) until you find one with the mNodeName matching "Box". Then, iterate over each of the Position, Scale, and Rotation keyframes in the `mPositionKeys`, `mScalingKeys`, and `mRotationKeys` members, transforming the value (Vectors or Quaternions, and the time offset) into whatever structure your application stores animation data in.

Then just pick a keyframe/interpolate between them as usual and apply the transform specified by the frame to that nodes local transform and see it move!

Extracting skeletal animation is an identical process, since in Assimp bones are just other nodes. The skinning data is slightly trickier. To animate a skinned model you need three things:

1. The transforms for each bone from the animation (which we get above)
2. The hierarchy of the skeleton
3. The skinning transforms for each bone (a.k.a inverse bind pose transforms) which we get from the mesh objects.

The first thing to do, though, is find the skeleton.

**Finding the Skeleton**

The example diagram above is what you will find in every COLLADA DOM I have seen so far. That is, the skeleton will exist as a separate tree of nodes, sibling to the 'visual' geometry just under the root node.
Assimp makes no distinction between 'bone nodes' and 'nodes', which means your importer will have to engage in some guesswork to pick the right starting node before reading in the whole tree.

The reason we need to find the skeleton is because, as can be seem from the diagram, each bone is parented to each other bone; the transforms extracted from the animation tracks/channels need to be combined with the transforms from other tracks to move the vertices correctly.

The way I do it is this:

Go over all the meshes and identify all the bones that they use, then for each bone, I look for a node in the object graph under root with the same name. I check how far down in the tree from root this bone is. The bone with the lowest value (degree of separation) is the root of the skeleton.

Once you have this, it is a case of reading in this node and each of its children, storing the *transform* of the node, and its *parent node's name*. Using this information, you can look up the parent for each bone.

**Skinning Data**

This is the trickiest bit, extracting the bones and weights from each mesh. The member you are looking for this time in `mBones` and it will be a member of `aiMesh`. It contains two things of interest:

1. `mOffsetMatrix` \- this is the skinning transform, or Inverse Bind Pose transform - you want to store this for each bone along with the bones original transform and the name of its parent.
2. `mWeights` \- these are the vertex weights - and they are, well, sort of backwards!

Each aiVertexWeight object contains mVertexId (which identifies the vertex) and mWeight, which is the weighting of the bone. The mVertexId is the index of the vertex in the 'vertex array' that serves the mesh. What that means is that you have to define a 'master list' of bone names, so that you can assign a number to each bone and have it refer consistently to the same bone. Then you need to look up that number for the name of the aiBone object which contains the vertex weight. Now you can update the vertex in your mesh with the bone ids and weights.

(You see what I mean about backwards, the weight contains the vertex id, while its parent contains the bone - although it makes it easier to write importers)

**Summary**

Now you should have, for non-skinned items, a list of keyframes which define transforms of a node (identified by the name) at specific times. Which is all you need to animate a node (just update its local transform).

If you have a skinned mesh then you should have:

a. A list of bones in a specific order
b. A list of bone ids and their weights, for each vertex in the mesh, ready to be packed into your vertex data array.
c. A list of skinning/inversebindpose transforms, one for each bone in the list in (a)
d. The parent for each bone in (a)
e. The bind pose transform for each bone in (a) (same place you got (d), or just take the inverse of the skinning transform)

This is the "standard dataset" for skeletal animation, and if you know about skeletal animation then it's all you need! If not, that best be a different question since it's quite a large area ;)

*I hope that has helped, or at the very least not added to the confusion. Good luck!*

(\*Animations also contain mMeshAnim which allow for animating the mesh directly, I assume you are not talking about this just yet)

# Answer
> 6 votes
I was waiting for a more experienced answer, but as nobody seems to have anything to help you, I will give you the informations I found.

Obviously there is a lack of documentation about Assimp animations and except if you dig into the Assimp code directly it seems that there is no available informations about this precise point.

But I did found this forum thread where you can see some interesting code portions wrote in order to import and use animations.

The other potentially useful information I found is this blog entry where you can find an *Open Asset Import Library animation loader* with the code which is free for use for anyone for any purpose (as wrote at the end of the entry).

I hope this could help...

---
Tags: c++, opengl, animation, collada, assimp
---


# Question
Title: Creating several instances of the same object, and selecting only one
I'm playing around with making a puzzle game, haven't done that much before I run into my first problem. I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a `for` loop to `push` the objects in? Then I need to be able to select one of these objects by clicking on it, how would I do that? How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas). This is what I want to do, but with more balls. How would you solve this?

# Answer
There are several issues here.

1. Storing several instances of object(s) in memory

This is generally done using an array or some more complex data structure. You can use a single array to hold everything (with polymorphism, for instance) or have one array per type of objects. Which is preferable depends on the kind of behaviour your objects will have.

Objects don't need to be stored in a variable at all, they can be an array member. You can do

```
a = new Array();
a.push(new MyGameObject(some params ... ));

```

Alternatively (more typically), you might temporarily assign the object to a local variable in the function, then set some properties, or call initialisation methods

```
function init_everything() // Call this when your game starts, or when a new level starts etc.
{
  objects_list = new Array();
}

function add_a_new_thingy() {
  var t = new Thingy();
  t.someproperty = 42;
  t.init_method();
  objects_list.push(t);
}

```

Then call add\_a\_new\_thingy several times.

1. Initialising some objects in some pattern at the start of a game or level

At the start of the game, or at the beginning of a level, you'll probably want to set up some objects with known states, in your global array of things (or arrays of things, if you have more than one).

Simplest way: hard-code each level as a Javascript function somewhere, which creates them all (NB: You don't need to put it in the same .js file as other things!)

Slightly more complex way: Create some kind of JS data structure, which you read to create the objects:

```
var level1_things = [
   { type:"monster", x:42, y:99 },
   { type:"bonus", x:128, y:100 }
];

```

Even more complex way: read them in some other format from the server, using XMLHttpRequest.

You could, for example, parse a text-file where certain characters indicate types of objects, so if you did a Sodoku-type game, you have a "W" for "wall", "P" for "player", "B" for box, "T" for target or something (maybe a blank space for an empty tile).
> 2 votes

# Answer
You could user JSON to store your objects, that's the easiest way to serialize objects in Javascript that I know of.

Then for your picking, a `for` loop with a bounding box or sphere test does the trick. If you've got tons of objects and run into performance issues you'll need some kind of space partionning system, such as a quad tree.
> 1 votes

---
Tags: javascript, html5, html-canvas
---


title: 2D wave-like sprite movement XNA

text:
# Question
Title: 2D wave-like sprite movement XNA
I'm trying to create a particle that will 'circle' my character. When the particle is created, it's given a random position in relation to my character, and a box to provide boundaries for how far left or right this particle should circle. When I use the phrase 'circle', I'm referring to a simulated circling, i.e., when moving to the right, the particle will appear in front of my character, when passing back to the left, the particle will appear behind my character.

That may have been too much context, so let me cut to the chase:

In essence, the path I would like my particle to follow would be akin to a sine wave, with the left and right sides of the provided rectangle being the apexes of the wave. The trouble I'm having is that the position of the particle will be random, so it will never be produced at the same place within the wave twice, but I have no idea how to create this sort of behavior procedurally.

# Answer
> 4 votes
When the object is created, create a variable `t = 0`. Increment this at regular intervals; this is your time.

When placing the object, don't give it a random position. Place it at `phi = rand(0, 2*pi)`. This is your phase term.

If your gaze direction is parallel to the plane of rotation, evaluate `x = A*cos(t*f + phi)` where `f` is your frequency. You will play with `f` until you get the right rate of rotation. You will add `x` to the x-coordinate of the character to obtain the position of the object. You will check if `(t*f) mod (2*pi)` is `0` to decide whether to draw the object's sprite behind or above the character. `A` is the maximum distance from the character, i.e. the radius of rotation.

If your gaze direction is not parallel, you will evaluate `x = A*cos(t*f + phi)` and `y = B*sin(t*f + phi)` where `A` is half the width of your bounds rectangle, and `B` is half the height. In other words, maximum vertical and horizontal distances. Your rectangle better be centered on the character, or else.

You will add `x` to the player's x and `y` to the player's y to obtain the position of the object. You will again consult `(t*f) mod (2*pi)` to determine draw order.

# Answer
> 3 votes
Before you make it random, first make it be at em-placed points (iterate to functionality, it works) like directly along the rotation vector of the character.

I think one of the things that might be tripping you up is thinking of it as a sine-wave instead of thinking of it as a circle. Instead of having the sprite follow a given function have it position determined by:

```
Vector2(Player.position.x +(cos(Player.rotation)*k),Player.position.y + (sin(Player.rotation)*k))
//Can be extended to vector3, and could move along a hemisphere if you wanted

```

Where `Player` is the player that holds a `position` and a `rotation` member, and `k` is some distance you want the sprite to be at from the player. to generate this randomly then you would replace the `rotation` of the player with some random value.

alternatively this implementation might make more sense depending on how you are holding/calculating you data.

```
Vector2(Player.position.x +(Player.rotation.x*k),Player.position.y + (Player.rotation.y*k))

```

This method assumes the `rotation` is a normalized vector that the player sprite is looking along. this method stops the requirement to use trig functions, and still gives you a circle. To make this one more random then you can maybe replace the rotation vector with a random normalized vector (if it is not normalized then you will not have a circle)

Where you made reference that the sprites `position` was to be pseudo-random then you could replace the `player.rotation` with a copy rotated some random angle. the amount of that angle will be a testing/feel thing.

---
Tags: xna, 2d, xna-4.0
---


# Question
Title: HTML5 mobile game development vs. native game apps
What is the current state of game engines, frameworks, libraries and conversions related to the HTML5 set of technologies (including CSS3 and JavaScript libraries such as RaphaelJS, Impact, gameQuery); and how does the best of that compare with developing a native app (especially for iOS and Android)?

Especially in terms of performance, visuals and getting that "native feel".

Thoughts on solutions such as Appcelerator and Corona SDK are also appreciated. In regards to Unity3D, is it possible to develop in it and still have the game be playable on a browser (such as current releases of Chrome or Firefox, at least) without any dependencies or having the user install anything (no unity web player).

What I'm looking for is how to develop in web standards as to reach the maximum number of platforms (including outside mobile) while still retaining a native experience for mobile without having to implement the game anew for iOS and Android.

# Answer
The HTML5 libraries are surprisingly good especially considering its young age. There are solid 2D/3D engines that support particle effects, physics, and the like. However, there is nothing comparable to established and mature game engines such as Unity or the Unreal Engine.

Also HTML5 libs in my experience like to be event driven. For example sprites will have an onclick events and there will not really be a traditional game loop.

For performance native apps are much, much quicker than anything having to do with the HTML 5 canvas. That is the extent of my experience though, I have no idea about Appcelerator or Corona SDK.

However if your goal is more the "maximum number of platforms" than the "web standards" part, I suggest a solution such as Unity which works on almost everything and thanks to its built in editor is a very productive engine.
> 7 votes

# Answer
Tom here from Scirra, we make Construct 2 the HTML5 game maker.

We recently blogged about this, comparing HTML5 Canvas/WebGl/C++ DX performance. You can read about it here:

http://www.scirra.com/blog/58/html5-2d-gaming-performance-analysis

And here's the graph:

I know it's not a performance in comparison to native mobile formats, but it is a comparison to desktop native apps which should give some indication of the performance gap.
> 6 votes

# Answer
First and foremost, Corona SDK is lovely to work with. Lua's a great language, Corona's a very thorough framework, and the documentation's been great thus far.

In my opinion HTML5 game development isn't worth it yet. Both on desktop and mobile browsers. If your goal is to make an awesome game to run on desktops and mobile devices, then don't bother. If your goal is to make an HTML5 game, then go make it and use one of the frameworks people have mentioned (also look at Crafty or Gee for more of a drawing-type interface).

The primary reason is that when I make a game, I want to make a complete and polished game. Part of making a complete and polished game is good audio. Although the `<audio>` tag is supported on major browsers (assuming you provide enough different formats), managing your soundtrack programmatically with `createElement` is kind of a pain. SoundManager 2 is a band-aid, not a solution. In many cases it will just fall back on using a Flash object for desktops. At which point I ask, *why not just make the darn thing in Flash?*

On iOS, unless you use a hack like in Zynga's Jukebox library, you're actually limited to only playing sounds in response to user input. It's ridiculous.

Also, unless you're packaging your HTML5 game up as an app, people need a connection to play. The time I spend playing mobile games most is on the subway--no signal. And if you do package your game up, *won't it be weird to not have sound?* If I'm downloading a game I expect a certain level of responsiveness and polish. Read: a native app.

Until HTML5's further developed and mobile browsers are faster and HTML5 audio stops sucking, I will have fun playing with Javascript and `<canvas>` and all that, but I will not go so far as to produce a polished game with it. It boils down to what your goals are. Very few I know who play games and are not developers even have mobile HTML5 games on their radar. Again, if you want to make awesome HTML5 games, make HTML5 games. If you want to make and sell awesome games, make the quality of your players' experience a priority.
> 4 votes

# Answer
Check http://cocos2d-javascript.org/

Its not yet completely implemented. But once done, it might be the best :)

There are a few demos in that site, they are quite good...

Edit: Just checked, the demos are not mobile friendly...
> 3 votes

# Answer
As other answers have shown, the performance difference is quite large. However, there are new ways being used to get native web performance on the web (using Chrome).

MonoGame is an opensource implementation of the XNA framework which is designed to work across as many platforms as possible. When this is combined with Google Chromes NaCl (Native Client) the results are pretty amazing (requires chrome).

My advice would be build a native app in XNA or MonoGame and consider NaCl and/or ExEn to get your game onto other platforms. The vast majority of your code base will be the same for all platforms, but the down size is releasing your game will not have the simplicity of a HTML5 game.

HTML5, in my opinion, just isn't there yet in regards to usable performance but other options exist that almost rival HTML5s accessibility, though adding a bit more complexity (and cost in some situation) to the release of your game.
> 3 votes

# Answer
I highly suggest libgdx, its a java based framework mainly made for deploying on android and desktop, but recently has added html5 to its arsenal, I would heavily recommend it. http://code.google.com/p/libgdx/

Some games ported to html5:
> 1 votes

# Answer
You might want to try PlayN. It's not very mature or well documented at the moment, and it takes some effort to get it working, but it allows you to program in Java and export your game to a number of different platforms (at the moment, Java, HTML5, Flash, Android and iOS, and in the future, Windows Phone 7).

The advantage it has over Corona, Phonegap, etc is that it compiles your game for each of the platforms rather than just running it using a virtual machine; this ensures that you get near-native performance on every platform.
> 1 votes

---
Tags: javascript, html5, mobile, cross-platform
---


# Question
Title: Turn-based Client-Server Card Game - Unicast (TCP) or Multicast (UDP)
I am currently planning to make a card game project where the clients will communicate with the server in a turn-based and synchronous manner using messages sent over sockets. The problem I have is how to handle the following scenario:

(Client takes it turn and sends its action to server)

1. Client sends a message telling the server its move for the turn (e.g. plays the card 5 from its hand which needs to placed onto the table)
2. Server receives messages and updates game state (server will hold all game state).
3. Server iterates through a list of connected clients and sends a message to tell of them change in state
4. Clients all refresh to display the state

This is all based on using TCP, and looking at it now it seems a bit like the Observer pattern. The reason this seems to be an issue to me is this message doesn't seem to be point-to-point like the others as I want to send it to all the clients, and doesn't seem very efficient sending the same message in that way.

I was thinking about using multicasting with UDP as then I could send the message to all the clients, however wouldn't this mean that the clients would in theory be able to message each other? There is of course the synchronous aspect as well, though this could be put on top of the UDP I guess.

Basically, I would like to know what would be good practice as this project is really all about learning, and even though it won't be big enough to encounter performance issues from this I would like to consider them anyway.

However, please note I am not interested in using message oriented middleware as a solution (I have experience with using MOM and I'm interested in considering other options excluding MOM if TCP sockets is a bad idea!).

# Answer
> 11 votes
Don't optimize prematurely. Keep it simple. Using TCP in this case is OK, and I don't see any problems with your current scheme.

UDP is usually used for performance critical scenarios such as in an online action game, because it allows explicit control over individual packets as opposed to working on top of a layer abstraction of streams like TCP. However, although you have some speed gain by controlling exactly how you want data to be sent, UDP does not handle packet loss or packet ordering like TCP, in which case you have to code it yourself. So, since this is a turn-based card game, I doubt you'll want to sacrifice reliability over speed, so use TCP.

# Answer
> 3 votes
Even many large, popular MMOs are using TCP exclusively. It will do everything you need with all the efficiency characteristics you required.

UDP requires a lot of extra complexity, multicast requires even more complexity, and you're not going to get anything out of them. If you're just interested in learning, by all means put together a tech demo for yourself, but don't think that the project itself will in any way be better off because of it.

If you're interested in using UDP at all, your very first task is basically going to be to reimplement TCP on top of UDP, just to make sure that you actually understand how to deal with all the problems that TCP solves for you: congestion control, lost packet retransmission, delayed duplicate handling, packet ordering, reliable connection handshake, reliably disconnection sequence, etc.

It's not necessarily difficult to solve all those, but it requires a deep understanding of networking, the IP protocol, and how those problems are solved.

From there, building up the library to offer features that TCP lacks is where the fun really starts. Using a message stream multiplexed over a packet stream, more efficient congestion control, rate limit handling, multi channels, channel configuration (whether the channel requires in-order messages or not, whether dropped packets are allowed, etc.), and so on.

I would suggest you read the following article series. It's not perfect, and makes a few very questionable claims (starting with its "never use TCP in games" nonsense), but its technical details are helpful to new network programmers: http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/

---
Tags: networking, client-server, card-game
---


# Question
Title: Getting a sphere to roll down a .FBX object Unity3D/C#
I'm working on a little ramp and ball game in Unity, I modeled the ramp outside Unity and exported it to a .FBX file, then I imported the ramp in to Unity. I set up the ball and ramp, both have Rigidbodies, Ramp is set to isKinematic = true, yet when I play the game the ball just falls right through the ramp and hits the floor below it fine. So it's something wrong with the ramp.

Am I doing something wrong? Are .FBX files unable to apply physics?

Thanks,

Tim.

# Answer
> 1 votes
Yes you can apply physics to a fbx derived mesh. Make sure the mesh has a MeshCollider and the ball has a SphereCollider.

Make sure you have the Generate Colliders option checked:

Also make sure that the Mesh for the ramp is set in the MeshCollider on your GameObject:

---
Tags: c#, physics, unity
---


title: Following a set of points?

text:
# Question
Title: Following a set of points?
Lets assume that i have a set of path that an entity should follow :

```
const int Paths = 2
Vector2D<float> Path[Paths] = { Vector2D(100,0),Vector2D(100,50)   };

```

Now i define my entity's position in a 2D vector as follows :

```
Vector2D<float> FollowerPosition(0,0);

```

And now i would like to move the "follower" to the path at index 1 :

```
int PathPosition = 0; //Start with path 1

```

Currently i do this :

```
Vector2D<float>& Target = Path[PathPosition];
bool Changed = false;

if (FollowerPosition.X < Target.X) FollowerPosition.X += Vel,Changed = true;
if (FollowerPosition.X > Target.X) FollowerPosition.X -= Vel,Changed = true;
if (FollowerPosition.Y < Target.Y) FollowerPosition.Y += Vel;,Changed = true;
if (FollowerPosition.Y > Target.Y) FollowerPosition.Y -= Vel,Changed = true;

if (!Changed)
{
    PathPosition = PathPosition + 1;
    if (PathPosition > Paths) PathPosition = 0;
}

```

Which works except for one little detail : The movement is not smooth!! ...So i would like to ask if anyone sees anything wrong with my code.

Thanks and sorry for my english.

# Answer
> 11 votes
If you want fancy looking curves then you might want to use Bezier curves to interpolate between your set of points like below (picture taken from an article mentioned below, it only shows the **result** of the interpolation though, it doesn't show any "control points" which are discussed later below):

I hope you have some basic linear algebra knowledge.

In short, Bezier curves are mathematical functions allow you to construct a smooth path that passes from a starting point to an ending point while using a set of "control points" to control where and how the path should curve.

**P0** is a starting point, **P2** is an ending point. **P1** is an arbitrary control point that curves the path towards it. The number of control points determine the mathematical order of the Bezier curve. Shown above is a **quadratic** Bezier curve with the following equation:

You would sample discrete positions along the curve that your object should be at by plugging in values of t ranging from 0 to 1 into the equation.

You can piece together a smooth path from a **set** of points by combining together a number of Bezier curves and calculate their control points by iterating through a few points at time from the set. Please refer to the following article series for more details:

Bezier Curve Basics

Using Bezier Curve to find a Path from N points

# Answer
> 3 votes
What you're looking for is something called Spline Interpolation or Approximation. There are several ways to achieve this, including Bezier curves, B-Splines, and some naive methods. I'll give a brief overview.

There are two options when it comes to creating curves: Interpolation and Approximation. Interpolation means that the curve will pass directly through the points you specify, while approximation means that the curve will just be influenced by the points you specify. Bezier curves and B-splines are both approximation curves. Both interpolation and approximation have their pros and cons, which are usually related to how the curve actually looks when it's generated (sharp turns, loops, etc).

Another method which I've actually used in an implementation before is called Catmull-Rom spline interpolation. For more information I'll direct you to this question posted on StackOverflow some time ago.

Finally, I'll leave you with a simple method of generating an approximation curve, which you may want to start with before getting into more detailed algorithms. It's called De Casteljau's Algorithm for generating Bezier curves. Given four input points or so, you could generate a longer list of points, perhaps 50, that represent points on the curve at 50 incrementally larger values of t (see the Geometric Interpretation section of that page on de Casteljau's algorithm). Then you can use your current path following algorithm on this new list of points.

EDIT: Alternatively you could have an algorithm which weights the influence of a point in the path by its distance from the object following it. In other words, as an object approaches point A, he is also getting closer to point B, the next point in the path, so some of his velocity will be towards A, and some will also be towards B. Summing these will give a total velocity which falls somewhere between the two. Since weights change with distance, this would theoretically result in a smooth curve as the object follows the path. Note that a lot of tweaking would have to be done to calculate weights to get the desired behavior.

This method is favorable to the spline interpolation I originally posted because it generates much smoother motion, whereas the spline method will suffer from the same problem you are having now, in that motion will not be perfectly smooth, but it will just be less noticeable because the objects moves on a higher resolution path.

# Answer
> 1 votes
If you want to move on lines (not curves), your implementation is almost good enough.

I would edit your code this way:

```
if (FollowerPosition.X < Target.X) FollowerPosition.X += Vel;
if (FollowerPosition.X >= Target.X) PathPosition = (PathPosition + 1) % (Paths + 1);
if (FollowerPosition.Y < Target.Y) FollowerPosition.Y += Vel;
if (FollowerPosition.Y >= Target.Y) PathPosition = (PathPosition + 1) % (Paths + 1);

```

This should be almost working except one thing:

Your character will move on line until he's not behind target position, so he doesn't have to stop exactly on line's ending point, but behind it. And then he will turn on other line segment.

---
Tags: mathematics
---


title: How do I get this effect in Unity3D?

text:
# Question
Title: How do I get this effect in Unity3D?
Here is a mockup of a main menu screen I'm trying to put together in Unity.

I'm clueless as to how I should go about creating the blue glow on the left of my menu options. Can somebody point me in the right direction?

# Answer
You will want to create your background (gradient) in another program such as Photoshop or GIMP, and then import it. Following that, simply draw it to the screen in the position you want it. Stretching gradients works well because of bilinear filtering: so you don't need to worry about making it massive (e.g. 512x512 should work fine).

*There is no reason to use shaders/effects here*.
> 11 votes

# Answer
u have apply another texture when mouse over on button
> -3 votes

---
Tags: unity
---


# Question
Title: Is it normal to these Xcode prompts/errors when you deploy to IOS Simulator from Unity?
Just trying out the IOS build process....

Is it normal to see:

Q1 - "upgrade to latest project format - project currently in Xcode 3.1 format, this will upgrade to 3.2" - just click OK and let Xcode do it's stuff?

Q2 - same as Q1 but this time for the message "Remove obsolete build settings - will remove the build setting PREBINDING"

Q3 - also when deploying to "Lastest IOS Simulator" you get the Simulator target produced, but also a non-simulator target which has lots of errors. So I assume you just ignore this target and not use it in Xcode correct? (i.e. just use the simulator target that is produced)

Q4 - get a lot of warning after the simulator target is built? program works ok however....

*Images*

For Q1 and Q2:

For Q4:

Settings used in Unity:

Errors I see in XCode:

# Answer
> 1 votes
In your Unity settings, try setting "SDK Version" to 4.0 and "Target iOS Version" to 3.2.1.

---
Tags: unity, ios
---


title: SDL mouse wheel not picking up

text:
# Question
Title: SDL mouse wheel not picking up
Running Ubuntu 11.04, SDL 1.2 trying to pickup mouse wheel up/down movement with this (stripped down) code:

```
int main( int argc, char **argv )
{
    SDL_MouseButtonEvent *mousebutton = NULL;

    while ( !done )
    {
        if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_LEFT)
            yrot += 0.75f;
        else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_RIGHT)
            yrot -= 0.75f;
        else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_WHEELUP){
            xrot += 0.75f;
        }else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_WHEELDOWN){
            xrot -= 0.75f;
        }

        while ( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
                case SDL_MOUSEBUTTONDOWN:
                    mousebutton = &event.button;
                    break;
                case SDL_MOUSEBUTTONUP:
                    mousebutton = NULL;
                    break;
                default:
                    break;
             }
        }
    }
    return 0;
}

```

strange thing is, scrolling with the mouse button does nothing, but if I hold down a mouse button or two and then move the mouse it hits the SDL\_BUTTON\_WHEEL code occasionally. This honestly reeks of a pointer issue, which would make sense since I've been spoiled with C# for the past couple years, but I am just not seeing it.

How do i correctly find mouse scroll events in SDL?

# Answer
I'd recommend going through these two tutorials:

If you still have problems after going through these tutorials, let me know - I'd be glad to help you out :)
> 3 votes

---
Tags: sdl, events, linux
---


# Question
Title: XNA - Saving Game Data without TypeWriter?
In the past, I've had some trouble with reading and writing content for XNA. I think I'm firmly set on this tutorial which sets up a four project structure (Game, Content, Library, Pipeline Extension) for the solution that other websites suggest, too. The options it offers for content reading seem great.

But problem! This tutorial (and all others I've found) have stated that the Content Pipeline Extension Project is not distributed with the game, which is fine in itself, but this is combined with the fact that any content *writing* objects are placed in this non-distributable library. The ability to actually write content of an already existing type (save game files, namely) is pretty critical to the project I'm trying to make.

I've already learned the hard way you simply can't place the Content Pipeline reference in another project besides the extension for easier access to the intermediate deserializer. Is there another object I can access for writing save game data? Am I actually, despite the warnings of this tutorial, able to use the TypeWriter outside of the Content Pipeline Extension Project? Or is there a third option I am missing here?

# Answer
> 4 votes
The Content Pipeline is not for your game's save data. What the Content Pipeline does is allow you to import assets (whether it be sounds, textures, models, XML files, or whatnot) to your project and compile them into an efficient format for distribution with your game. It may seem like this is somehow limiting, but having this easy-to-use unified framework for handling asset compilation is a huge deal.

The way you save game files on XNA is via the storage API in the `Microsoft.XNA.Framework.Storage` namepsace. On XBLIG, these classes handle saving data to memory cards or the Xbox hard drive. On Windows, this typically saves to the user's `%APPDATA%` or a similar location (the specifics are in the docs).

If you're targeting Windows, you also have the option of using file I/O to save and load data. Look at the `System.IO` namespace, and more specifically, the `File` class within that namespace.

# Answer
> 0 votes
All XNA platforms have support (some partial) for the System.IO class. To save data using XNA, you can either use isolated storage or the XNA storage system (or just default System.IO on windows). Those will give you an IO stream which you will then use the System.IO classes to write with. (BinaryWriter, StreamWriter, etc.)

---
Tags: xna, xna-content-pipeline
---


title: Draw order in XNA

text:
# Question
Title: Draw order in XNA
It is possible to set draw order of a `DrawableGameComponent` by setting `DrawOrder` property. But is it possible to set draw order of "main" `Game` class?

I have 2 DrawableGameComponents, and Draw method of a main Game class is called first, while I want it to be the last. Should I just mode all "main" draw code to another component and set it `DrawOrder`?

# Answer
I wanted to clarify: Inside `MyGame.Draw` there is usually a call to `base.Draw`. It is my impression that this line is responsible for drawing attached components. Whatever code you put above it will be drawn before, whatever you put below it will be drawn after. If you remove the call to base, presumably the components will not be drawn.

If you have components A, B and C, and you would like `MyGame.Draw` to draw A and B, then draw some of its own stuff, and then draw C, it seems you'd have to draw each component manually by iterating through `MyGame.Components`.
> 0 votes

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


title: Desura sales experiences

text:
# Question
Title: Desura sales experiences
Does anyone know of (or have) an experience selling an indie title through Desura? How does it compare with other typical indie game distribution avenues?

# Answer
> 1 votes
Swing Swing Submarine published a bit of info for their Blocks That Matters sales. It appears that Steam and Indievania brought them more revenue than Desura.

---
Tags: distribution, sales
---


# Question
Title: Detect two specific objects collision with bullet physics
I have got some problem with defining collision between objects in my game using bullet physics.

I know that objects are colliding with each other simultaneously and I don't have to do anything more. However I need to be noticed when one object collides with one of the rest.

It is quite awkward written so I will tell what I want to achive. I have got ball which hits wall from tubes. Everything is on the floor. When ball hits wall some fragments fall down to infinity. So I have got bellow floor btStaticPlaneShape. This is place where most of objects is stoping and then I can start another action. But not all of them.

So I've been trying to use function `checkCollideWith` but it isn't good method as it was said in reference and wiki.

So I've checked method described in wiki http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision\_Callbacks\_and\_Triggers called contact information. This isn't good method either because it is extremly hard to identify what is what when colliding. You have to also remember that ball is almost all the time colliding with something - floor, wall or eart level.

So is there any other method to check what is colliding with what?

# Answer
`checkCollideWith` isn't for dynamic collisions, it is used to see if an object is set to collide with another, not to see if there's a collision.

Also, you can `setUserPointer` in your `rigidbody` to have a pointer to anything, be it your own class or not. with that, you can then check what-is-what when colliding by using `getUserPointer` on the two `btCollisionObjects`.
> 4 votes

---
Tags: opengl, bullet-physics
---


# Question
Title: How do I draw a 2d plane and rotate camara (To be a board) in a 3d XNA game?
I am trying to create a simple board game, but the 3d part of this is really killing me.

From what I can gather I have created a plane, but it never moves even though I turn the camara, but that partially makes sense as I only turn the camara with a 3d model, but in my head that makes 0 sense, in my head if I turn the camara it should affect ALL my models? But with this code the camara only "cares" about the 3d cylinder, the plane is just completely still

```
private void OnDraw(object sender, GameTimerEventArgs e)
    {
        SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (ModelMesh mesh in cylinderModel.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                //effect.World = Matrix.CreateRotationX((float)e.TotalTime.TotalSeconds * 2);
                effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

                effect.EnableDefaultLighting();
            }

            mesh.Draw();
        }

        //cameraPosition.Z -= 5.0f;
        _effect.World = Matrix.CreateRotationZ((MathHelper.ToRadians(((float)e.TotalTime.Milliseconds / 2) % 360)));
        foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
        {
            pass.Apply();

            SharedGraphicsDeviceManager.Current.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 1, VertexPositionColor.VertexDeclaration);
        }
    }

```

Is there a way to get the camara to affect all models?

# Answer
> 2 votes
A camera is not an object in the game that once you add it it affect everything. You need to apply the camera to the things you want to draw in reference to the camera.

So just like the Cylinder is being drawn you set the `effect.View`, you need to do the same for the `_effect.View`.

```
    //Add this line
    _effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
    _effect.World = Matrix.CreateRotationZ((MathHelper.ToRadians(((float)e.TotalTime.Milliseconds / 2) % 360)));
    foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
    {
        pass.Apply();

        SharedGraphicsDeviceManager.Current.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 1, VertexPositionColor.VertexDeclaration);
    }

```

---
Tags: xna, 3d
---


# Question
Title: What is the correct way to use glTexCoordPointer?
I'm trying to work out how to use this function `glTexCoordPointer`.

The man page states that I must set a pointer to the first element of the array that uses the texture cordinate.

Here is my array:

```
static const GLfloat GUIVertices[] = {

    //FIRST QUAD
    1.0f,  1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
   -1.0f,  1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
   -1.0f, 0.94f, 0.0f, 1.0f, 0.0f, 1.0f,
    1.0f, 0.94f, 0.0f, 1.0f, 1.0f, 1.0f,

    //2ND QUAD
    // x     y      z    w      X    Y
    1.0f,  -1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
   -1.0f,  -1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
   -1.0f, -0.94f, 0.0f, 1.0f, 0.0f, 1.0f,
    1.0f, -0.94f, 0.0f, 1.0f, 1.0f,  1.0,
};

```

But how do I set the pointer correctly for the fifth element on the 2nd quad first row? I was thinking something like this:

`glTexCoordPointer(1, GL_FLOAT, 6, reinterpret_cast<const GLvoid *>(29 * sizeof(float)));`

# Answer
> 3 votes
The call you're looking for is

```
glTexCoordPointer(2, GL_FLOAT, sizeof(float)*6, (GLvoid*)(sizeof(float)*4));

```

The first argument is the number of elements that need to be read per element (vertex), and it's two because texture coordinates are just u and v coordinates. The second argument describes the type of data being passed. In this case, they're floats.

The third argument is the stride, which is the byte offset between consecutive texture coordinates. In this case, it's simply the size of one of your vertex-texcoord pairs (if I'm understanding the way you packed the data correctly). In other words, there are 6 floats between the start of two texture coordinates and the start of the next two.

Finally, the buffer offset specifies how far into the structure OpenGL must look before it finds the first values. You set it to 4 because you have to instruct OpenGL to skip the first 4 float it reads, as they are the vertex coordinates. Also note that this last pointer is casted to a `GLvoid*`.

Edit: If you want to point only to the texture coordinates of only the second quad, then use:

```
glTexCoordPointer(2, GL_FLOAT, sizeof(float)*6, (GLvoid*)(sizeof(float)*28));

```

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


# Question
Title: Matrix rotation of a rectangle to "face" a given point in 2d
Suppose you have a rectangle centered at point (0, 0) and now I want to rotate it such that it is facing the point (100, 100), how would I do this purely with matrix math?

To give some more specifics I am using javascript and canvas and I may have something like this:

```
var position = {x : 0, y: 0 };
var destination = { x : 100, y: 100 };
var transform = Matrix.identity();

this.update = function(state) {

  // update transform to rotate to face destination

};

this.draw = function(ctx) {
  ctx.save();
  ctx.transform(transform); // a helper that just calls setTransform()
  ctx.beginPath();
  ctx.rect(-5, -5, 10, 10);
  ctx.fillStyle = 'Blue';
  ctx.fill();
  ctx.lineWidth = 2;
  ctx.stroke();
  ctx.restore();
}

```

Feel free to assume any matrix function you need is available.

# Answer
> 2 votes
Here's my first take on it:

Assuming you want the top edge of the rectangle to be the edge that sets the "facing direction" as per your comment, and that would be considered your identity direction (0, -1) or zero angle in 'JustinSpace', rotating the rect so that that edge faces 100,100 would in effect be a 135 degree rotation clockwise. Most Math libraries think of 1,0 as being the identity direction (or 0 angle) requiring a 90 deg shift of the angle to place it into 'JustinSpace'.

A matrix that rotates something 135 deg clockwise on a 2d XY plane looks like this:

```
float angle = Math.Atan2(100,100) + Math.Atan2(-1, 0); // 45 deg + 90 deg

//RH coordinate Row Major system
Matrix m = Matrix.Identity();
m.11 = m.22 = cos(angle);
m.12 = sin(angle);
m.21 = -sin(angle);

//for column major
//m.Transpose()

```

If eBusiness' answer works however, I would use it as linear algebra is almost always favorable over trig in game dev.

# Answer
> 2 votes
If I got my maths right in order to rotate from facing A to facing B you can use the matrix:

```
 [ A1*B1+A2*B2   A2*B1-A1*B2 ]
 [ A1*B2-A2*B1   A1*B1+A2*B2 ]
_______________________________

            |A|*|B|

```

---
Tags: 2d, javascript, matrix, rotation, html-canvas
---


# Question
Title: How to track and find entities within radius in realtime game?
What is best approach to implement tracking in real time for, say, 1000 npcs? Every frame update simple a square grid (remove or insert into linked list) and every time check in square radius? I tried kd-tree but its really bad in real time updates even with 100 entities I can't reach 10 FPS.

# Answer
Not your typical answer, but I think it's useful to add this for future googlers. Here's some snippets from our chat:

> Denis: minimum size of map 1000 x 1000 pixels
>
> Denis: maximum can be 2500 x 2500 not more i think
>
> Denis: units are 50 x 50

For sparser and larger worlds, I'd advocate the Quadtree, but I think for small and busy worlds, it is probably going to be slower than a Spatial hashing.

> Denis: i see every time it clear all buckets and fill it again, is it good for real time game?

Personally, I'd expect it to be cheaper to test if the entity has moved into/out of a spatial grid, and only do some recalculation at that time. I know for my QuadTree, it's *way* quicker to test a moving object before removing and re-adding it. Also... don't re-calc the position of every object in the spatial hash. When the object moves, it should set a flag (or something) then *and only then* should it re-calculate its position in the spatial hash.
> 3 votes

# Answer
Maybe you could use a secondary structure that can be partitioning into the quadtree. If you can break your world down into components like rooms, or even subsection (and just track what is in which subsection then construct collision structure for those it should greatly improve performance. for example

if I have a world composed of 50 rooms, and each of those rooms has several entities then each room gets its own collision structure, and it can even be possible to take objects out of one structure, and transition it to another structure.

Another one I have seen is implementing a quadtree, and then having a BSP tree inside the lower levels of the quadtree (this is assuming that these low levels can still be large enough to accommodate a BSP tree.

in short many partitioning systems do not have to exist independently.

a good resource on the logic behind many collision detection algorithms is "Real Time Collision Detection" by Ericson
> 0 votes

---
Tags: algorithm, performance, data-structure, efficiency
---


# Question
Title: Can I get enough experience to get an industry job just by reading books?
I've been recently working with DirectX and getting familiar with game engines, sub-systems and have done game development for the last 5 years. I have a real question for those whom have worked in larger game making companies before. How is it possible to get to into these big game creators such as Ubisoft, Infinity Ward or EA.

I'm not a beginner in my field and I'm going to produce a real nice 2D platform with my team this year, which is the result of 5 years 2D game creation experience. I'm working with prepared engines such as Unity3D or Game Maker software and using .Net with C# to write many tools for our production and proceeding in my way but never had a real engine programming experience 'till now.

I'm now reading good books around this topic but I wanted to know: Is it possible to **become an employee in big game company** by just reading books? I mean beside having an active mind and new ideas and being a solution solver.

# Answer
> 7 votes
I have never worked in a game company of any size. However:

> Become an employee in big game company by just reading books?

If you then get certified, maybe. If you don't even have a related degree or demonstrable work, why would the employer assume you have any skills at all? And if you do, why would they care what books you've read? With job applications, saying "I've read about X" makes no difference at best and hurts your chances at worst.

> I have games that I made and would like to work at a games company.

I don't see why not. I'm sure the fact that you can demonstrate your ability will be a big plus during the selection process.

> I made a 2D platformer while avoiding engine programming as much as possible and would like to get a job programming state of the art engines.

No offense, but this is like saying "I have driven a racecar that other people maintained and repaired, can I become a car mechanic?". If you want to work on engines, you should work on engines. In practice, that means make a 3D game, write your own engine, and have it do something interesting.

Maybe the employer will see your unrelated programming experience and decide that you are worth hiring due to the overall skills you must have. But it seems a really bad idea to bank on that.

Also, out of curiosity, if you already have a team which can release a game, why are you trying to get a job at a big company? I had gotten the impression that they're quite awful places to work at if you want to make games.

# Answer
> 9 votes
I am an engineering lead and hiring manager in the games industry.

> Is it possible to become an employee in big game company by just reading books?

No. Reading books is all well and good, but it doesn't impart the practical knowledge that even entry-level positions require. A fresh-faced college graduate with a CS degree under her belt has, if nothing else, four years of having actually written code and solved problems of varying complexity and will hands-down beat out somebody who has done nothing but read books for a job interview.

But it sounds like, from your original question, you've actually been working on making games for the last five years anyhow, so you should have at least some practical experience -- I'm not even sure this question you've posed even applies to you. Finished games are far more useful than the assertion of book knowledge (even for those who want to be "engine" programmers, because a finished game demonstrates the effectiveness and quality of an "engine" far more than the engine would on its own).

> How is it possible to get to into these big game creators such as Ubisoft, Infinity Ward or EA.

You apply for a job, same as any other industry. Prepare a portfolio of your best projects and code and send that with your resume, if asked. There's nothing special about games.

# Answer
> 5 votes
I don't currently have a job at a "big game company" but I am looking for one and have interviewed to various extents with many of them: Bungie, Rockstar, Microsoft, Amazon, EA, Disney, etc. I have received one offer and am expecting to hear back from another of those companies tomorrow.

From the questions I've been asked, having book knowledge is, of course, helpful and will get you through a lot of the programming-specific interviews; to be a programmer, you're obviously going to need to know programmer things. Much of this can be learned by reading if that's how you learn. In every interview, though, I have pulled heavily from knowledge I picked up by doing various projects both professionally and as a hobby and being able to show things I've worked on—sometimes by pulling out my phone and showing a mobile game or by pointing them to my software development blog. My experiences have shown that interviewers are much more interested in what you have *done* than what you *know*. At a games programming panel at this year's GDC, the speakers all agreed that they want to see what you've done and don't care as much about schooling or book knowledge. Your mileage, of course, may vary.

As Superbest said, if you want to be an engine programmer, start programming engines. Similarly, if you want to be a gameplay programmer, write games and be able to show them off. They're very different disciplines that work together but are still quite different.

Additionally, there's more to being in a games programming job than knowing how to write code in a specific language. If your reading doesn't also include learning what makes games programming different from other kinds of programming, that may hurt you. If you can't demonstrate that you will mesh with the group, that may hurt you. In one interview, I spent over an hour doing linear algebra on a whiteboard, if you don't know the math that company is looking for, that may hurt you. In short, you're going to want to be well-rounded in ways that only reading programming books probably isn't going to enhance.

# Answer
> 0 votes
I'd suggest "no" too.

Reading books on it's own can get you to a certain level of knowledge, yes. You can become quite competent and capable, even.

Going to college and doing a 4 year course gets you one thing that no book in the world can give. You are able to demonstrate straight away that you are able to begin a 4-year project, stick to it, see it through, and get a result at the end.

Another disadvantage of just reading books is the risk that you might pick and choose the parts you like (or the parts you understand!) and skim over (or just copy/paste) the rest. You don't have that option with a course; you have to knuckle down and learn all the horrible stuff, you have to learn the theory behind it and the reasons why.

Yes, there are the occasional mavericks who never went to college and who obtained their knowledge other ways (John Carmack is probably the best known example) but you'll find that they're extremely rare and that they are generally people who start their own companies rather than people who get jobs at existing companies.

---
Tags: game-industry
---


# Question
Title: How come the 3d graphics and animations of MMORPGs are usually worse than non-online 3d games?
I have noticed that in general it seems like the 3d graphics and animations for MMOs and MMORPGs seem not as seductive and polished as the graphics for normal, non-online 3d games.

* **How come this is the case?**

or
* **Is my judgement inaccurate?**

*If my judgement is inaccurate please provide examples of MMORPGs that render 3d graphics and animations that are superior to normal, non-online 3d games.*

# Answer
> 27 votes
The main reason is that *MMOs blow away any attempt at asset budgeting*.

Take a game like Crysis or Gears of War, with top-end graphics. They have a fixed number of player models. The enemy types are often broken down by zone or level; often those enemies will share textures or materials with other things in the environment, to save memory. At most you're going to have a dozen people (by far the most expensive things to render) on-screen at once.

By sharing textures and only having a handful of models, these games can afford to have more polygons, more shader effects, and more detailed animations. So when they fix their budget at, say, 512MB of RAM and a 3.2GHz processor, they know exactly what the most expensive scene in the game is, and can make sure that machine can play it at an acceptable framerate.

In MMOs, you don't have that luxury. The levels are large. Enemies can be trained from one end of the map to the other. Players can wear whatever they want, and expect that to appear on their character model - meaning their models are often many separate models in practice. You need to be able to render dozens or hundreds of players and enemies at once. You're animating more, and you need to be prepared to render any character model or texture at any time.

When figuring out the budget for an MMO, you *have no idea what the most expensive scene is*. Fifty players in your frustum? A rare item you didn't expect to need to load? Better have the graphics memory and CPU resources ready!

But these are exactly the kind of situations players love - as many people as possible at the same place, drawing myriad mobs into the middle of a town, showing off as much sparkly alpha-blended light-emitting gear as possible.

What everyone else has said about MMOs targeting lower hardware is sometimes true, but it really comes down to that. The worst rendering scene in an MMO is *not known at development time* and you can count on players to try to make it as bad as possible, no matter how good their hardware is. The "worse" graphics you have, the more you can scale up before the game becomes unplayable.

# Answer
> 8 votes
Having done A LOT of research on MMO creation the single biggest issue on graphics is that a designer really has no way of knowing how much content will be present in an area at any given time.

In a single player, or even a multi-player with under 12 players, the designers can control how much content needs to have drawcalls made on them at any given time. Additionally they can control fully how many textures any scene, or area if you will, has. Since they can fully control these assets they are able to turn the model detail far up the spectrum with High poly model and richly detailed textures.

The problem in an MMO is you have little control over how many "assets" are going to be in a given area at any given time since players can wear what they want, where they want, when they want.

Take a game like Skyrim, single player game, lush graphics, high detail. But if you pay close attention, there are seldom more than 5 or 6 moving "characters" at any given time on screen, and when there are more if you carefully look around you'll often notice that they've cut back a little on the amount of material present in the scene. Additionally games like Skyrim know's exactly what every character will be wearing in each scene.

In an MMO, by contrast, a zone can be devoid of any other players other than yourself, or there could be hundreds, and each and every character is often wearing different texture and shader combinations. MMO's, however, can look very nice if the creater get very clever and efficient with their use of well designed meshes that are applied to models. And this can compensate a lot on the graphics difference between mmo's and stand alone games. But in the end the graphics detail level of an MMO will never be the detail level of a stand alone game with equal system requirements. Resource management just doesn't permit it, at least not if you want an MMO framerate above 5.

# Answer
> 5 votes
The other answers are quite good. Another reason for MMOs to be low-tech in the graphics department is that they are often designed to be played by low-end hardware, to increase the possible user base and encourage gameplay on laptops or while multitasking.

# Answer
> 3 votes
I think the answer is in the definition of MMO: Massive Multiplayer. These games are typically aimed to run on as wide of a player base as possible, including low-end hardware, laptops, netbooks, etc. So the graphics usually don't take advantage of the latest advances in hardware and CPU tech. All the reasons above are also good as well.

P.S. - Looks like Gregory beat me to it :)

Edit: Vote down if you want, but I'm not stating an opinion, it's an absolute fact. WoW has 11 million players and Blizz has stated many times that they want to keep the game so that it can run on low-end hardware. Age of Conan, Aion, where are those games now? They're not so massive, if you get my drift. Name a successful MMO, one that actually has, you know, players, that requires a high end graphics card and then we'll talk.

# Answer
> 2 votes
MMOs often have **much** more content than traditional games. If you think about it, your traditional one-player game has a mostly linear storyline, so the levels are very straightforward, linear, small and restricted. They can be scrutinized and made to a high level of detail. A MMO, however, has an entire world's worth of content, so a lot more art and content is required to match that same level of detail.

It is also the case that MMOs often have many things on the screen at once; this can differ based on the game, but some games allow many people to be standing in one area (for example if there is an important event or party). That is a lot of polygons; so each character must be low detailed in order to be able to draw them all on the screen at once. Similarly, even in the fighting areas there can be a generous number of NPCs/mobs on the screen at once. Level-of-detail algorithms can be used to tune the detail levels based on how much is on screen, but then you are introducing even more content that needs to be made (each thing would then need to be made several times -- or an algorithm can try to do it automatically).

# Answer
> 0 votes
Your point is valid. But keep in mind that a MMORPG has more models, textures and animations than a normal game; making those assets in a very high resolution would need a lot of disk space, and they wouldn't be easy to stream to system/graphics RAM. So they are kept low-res to easily load a higher part of the world, and to make the development of the game shorter.

---
Tags: graphics, 3d, animation, mmo, rendering
---


# Question
Title: How do I convert matrices intended for OpenGL to be compatible for DirectX?
I have finished working through the book "Game Physics Engine Development 2nd Ed" by Millington, and have got it working, but I want to adapt it to work with DirectX.

I understand that D3D9+ has the option to use either left handed, or right handed convention, but I am unsure about how to return my matrices to be usable by D3D. The source code gives returning OpenGL column major matrices (the transpose of the working transform matrix shown below), but DirectX is row major.

For those unfamiliar for the organization of the matrices used in the book:

```
[r11 r12 r13 t1]
[r21 r22 r23 t2]
[r31 r32 r33 t3]
[ 0   0   0   1]

```

`r##` meaning the value of that element in the rotation matrix, and `t#` meaning the translation value.

So the question in short is: **How do I convert the matrix above to be easily usable by D3D**? All of the documentation that I have found simply states that D3D is row major, but not where to put what elements so that it is usable by D3D in terms of rotation, and translation elements.

# Answer
First, a point of clarification: **row-major** means something different than **row vector**. OpenGL uses **column vectors**, which abstractly means that you consider a vector as a 4x1 matrix, and transform a vector *v* by a matrix *M* with *v'* = *M* · *v*. DirectX uses **row vectors**, which means that you consider a vector as a 1x4 matrix, and transform a vector *w* by a matrix *N* with *w'* = *w* · *N*. Notice that the two vectors are simply the transpose of each other: if you have an OpenGL vector *v*, then the DirectX vector is *v*T. And thanks to the linear algebra rule (*A · B*)T = *B*T · *A*T, you can see that the DirectX transformed vector (*v'*)T = (*M* · *v*)T = *v*T · *M*T. That is, the DirectX matrix is simply the transpose of the OpenGL matrix.

And unrelated: OpenGL expects **column-major storage**, which means that the in-memory representation of a matrix keeps columns contiguous. So your example matrix would be stored as `{r11, r21, r31, 0, r12, r22, r32, 0, r13, r23, r33, 0, t1, t2, t3, 1}`. DirectX expects **row-major storage**, which means that the in-memory representation of a matrix keeps rows contiguous. So your example matrix would be stored as `{r11, r12, r13, t1, r21, r22, r23, t2, r31, r32, r33, t3, 0, 0, 0, 1}`. (Incidentally, in C and C++ two-dimensional arrays use row-major storage.)

And the fun part: it's easy to conflate these because they have "similar" effects. That is, if you take a matrix that's intended to be used with column vectors, and store it in column-major format, you get exactly the same thing as the transpose of that matrix (i.e. a matrix that represents the same transformation, but on row vectors) stored in row-major format. In a sense, the two operations cancel each other out. So OpenGL matrices and DirectX matrices look the same in raw memory. (And, of course, both of these are different than right-handedness vs left-handedness).

To summarize: If you're working in DirectX and looking at references that present OpenGL matrices, just transpose them to get matrices that you can use with DirectX.
> 9 votes

# Answer
D3D isn't row-major; you can quite happily use column-major matrixes with D3D code and they will work. So the answer to your question is: "do nothing, because you don't need to do anything".

D3D itself uses column-major matrixes internally. The D3DX utility library matrix functions will generate row-major matrixes for you, and work on the assumption that you use row-major matrixes, but you don't *have* to use this library with D3D. You can just as easily use a different library, or roll your own.

Likewise it's worth noting that you can also use row-major matrixes with OpenGL in the same way if you wish. (You can even use the D3DX library functions with OpenGL, which amply illustrates that this is really not that big a deal.)

The whole D3D vs OpenGL row-major vs column-major thing is completely blown out of proportion. All that a matrix is is an array of floats. Feed them to your pipeline, do the multiplications in the correct order, and nothing else matters.
> 2 votes

---
Tags: physics, graphics, directx
---


# Question
Title: What are the tools, programming languages and development processes of AAA games?
Only thing I am able to find about "big" games like ac, hl, bf, cod is engine used to run the game. But I am interested in what software development methodology, programming and scripting languages were used. As well as tools for creating models, music, animations and other media. Further, were the team team organisations and so on for a certain game (or game series). Is this information even available to the public?

# Answer
> 0 votes
many times the engine will determine the language (or possible set of languages) UDK uses Unreal script with the option of C++ DLL binding. Uninty uses either Java, or Mono with the option of their own scripting language. XNA uses C#. what this amounts to is if you are trying to figure out what language, or engine to use it should be determined based on more then just what others have done. (see my answer here for more on that When should I decide what language and platforms I will use for a project? )

The software tools used will depend on familiarity with the product, capabilities of the product, and the licensing. the specific tool used for GameX is not the point its the artistic direction of the game, and that is a design concern.

For constructing the teams this is rather open ended, and vary diverse. it could be anywhere from a group of friends who like games, and want to get together, and make one. It could be a group who went to a school for game development, and want to work together. or it could just be that a person undertakes the project to start with, and then puts a posting on craigslist for help. how you chose to build your team is up to you.

the overall answer is simply "don't be a ape taught to make something good. be an individual who has an idea, and goes for it"

---
Tags: tools, methodology
---


# Question
Title: In a 2D platform game, how to ensure the player moves smoothly over sloping ground?
I'm developing a physics engine for a 2D platform game. I'm using the separating axis theorem for collision detection. The ground surface is constructed from oriented bounding boxes, with the player as an axis aligned bounding box. (Specifically, I'm using the algorithm from the book "Realtime Collision Detection" which performs swept collision detection for OBBs using SAT). I'm using a fairly small (close to zero) restitution coefficient in the collision response, to ensure that the dynamic objects don't penetrate the environment.

The engine mostly works fine, it's just that I'm concerned about some edge cases that could possibly occur. For example, in the diagram, A, B and C are the ground surface. The player is heading left along B towards A. It seems to me that due to inaccuracy, the player box could be slightly below the box B as it continues up and left. When it reaches A, therefore, the bottom left corner of the player might then collide with the right side of A, which would be undesirable (as the intention is for the player to move smoothly over the top of A). It seems like a similar problem could happen when the player is on top of box C, moving left towards B - the most extreme point of B could collide with the left side of the player, instead of the player's bottom left corner sliding up and left above B.

Box2D seems to handle this problem by storing connectivity information for its edge shapes, but I'm not really sure how it uses this information to solve the problem, and after looking at the code I don't really grasp what it's doing.

Any suggestions would be greatly appreciated.

# Answer
> 14 votes
**Platforming and Physics**

These edge cases are numerous. Good fun platformers do not behave in any kind of physically-accurate manner, and the control and behavior that players expect after years of "perfect" platformers like Mario are incredibly difficult to implement with general techniques like you get with Box2D or other physics engines. Most good platformers do not use any kind of generic physics or collision response in their player controllers.

**Generate Hulls**

Regarding your specific question, the best solution is to stop using boxes as your ground. Use a series of connected line segments (a hull). That allows the collision detection engine to only focus on the actually walkable surfaces and not look at the "fake" edge that exists between A-B and B-C. That is what Box2D does, in fact. The shapes are used to generate the outward surfaces, which are linked together to form a hull.

You need this even in tile-based games, or in situations where you have two AABB objects next to other acting as the floor. The collision engine will pick up those vertical edges and cause the player to catch on them. There are hacks that can help, but not eliminate the problem. The solution is to just have a single line segment representing the surface rather than a full 2D box.

You can generate the hulls in the generic case by clipping the polygons against each other and joining the clip points into an edge list.

**Sloping Surfaces**

Since your example includes a slope and you're mentioning restitution and other physical properties, I'll point out a few other problems you're going to notice soon, which further illustrates why generic collision detection and response does not work well for platformers. First, try standing on the angled platform, jump up, and then land. You will likely notice that the character will "slide" a bit when landing. The problem is that the contact normal you're generating is usually going to be pointing out from the angled surface. Then, when resolving the collision, the player is pushed out in that direction. Even though the character was fall straight down, he'll be pushed up and a little to the right when landing, resulting in the slide. This can be hacked by taking the relative velocities into account, or by just hacking it so that the contact normals for static surfaces are always snapped to be axis-aligned.

The second problem you're going to notice, which is much harder to fix, is what happens when you try to run quickly down a ramp. The player is going to "hop" down the ramp. This is very visible even in most AAA games today. It not only looks silly, but if your game requires the player to be footed on the ground to jump, it makes it difficult to run down a ramp and jump halfway down, because the player is only contacting the ramp during a small portion of the time spent going down it. A simpler fix is to simply do some ray casts when the player moves, and snap the player position down to the nearest surface (if it's very close to the player) if the player is not jumping and was previously on the ground.

You may also find that the player launches into the air when running up a ramp if you try to model velocity, friction, and restitution on the player as if he were a normal rigid body. The player's movement should be constrained to horizontal movement unless falling/jumping. Of course, if you play older golden-age platformers, you may notice that the player's horizontal velocity is often constant between horizontal and sloped surfaces. This needs to be taken into account when walking up/down slopes as well.

There's going to be a number of other odd corner cases you'll eventually run into, too. If you're trying to make a good platformer, it's really just best to implement a platformer player controller separate from physics and hardcode the movement and control behavior you want, rather than relying on generic physics and collision response algorithm.

# Answer
> 5 votes
I think both problems could be solved by treating your boxes, for collision response purposes, as if they had rounded corners (of a similar radius to your numerical error). This will make the effective combined surface of the meeting corners between A and B, and B and C, smoother.

Thus if PLAYER moving left hits the corner of A, the collision normal would be diagonal rather than purely rightward, so allowing continuation of the left-and-up motion.

---

However, a more typical solution, on reviewing what I know of platformer physics, is to make the *player* a more highly rounded shape, and leave the terrain alone. In particular, consider making the player's shape a capsule (stretched-in-the-middle circle (2D)/sphere (3D)) — then your collision normals will *naturally* be nearly vertical, eliminating any catching problem.

You say you're using a collision algorithm specifically for OBBs, but you should still be able to, after finding an OBB-OBB collision, use a further test against a shape which is entirely within the OBB.

---
Tags: 2d, physics, platform
---


# Question
Title: Any open source game engines for Android?
Is there any open source android gaming engine ?

# Answer
> 12 votes
There is no open source game engine available on Android equal to commercial Unreal Engine or Unity. But you can use different Open Source Projects for little games or applications.

Java 2d Game Engine (as cocos 2d on iphone):

C++ 2d Game Engine:

* Cocos2d-x: cocos2d is a reference on iPhone. If you know it, try this project.

Java 3d Game Engine:

* libGDX: many parts are native, so it is an efficient **framework** (not engine) for games. There is a backend with OpenGL do develop on your Desktop.
* jmonkey

C++ 3D engines available on Android:

Ogre3D and Irrlicht aren't well packaged but you can develop games for iPhone and Android devices. Linderdaum is currently available only for Windows and Android.

# Answer
> 10 votes
The AndEngine
Candroid
Cuttlefish Engine (Commercial)
Mages (mostly networking AFAIK)

All these from googling 'android game engine'.

# Answer
> 2 votes
There is a list of at least 23 Open Source Android Game Engines here: http://mobilegameengines.com/android/open\_source\_game\_engines

---
Tags: android
---


# Question
Title: How do I make A* check all diagonal and orthogonal directions?
I'm making a turn-based tactical game and I'm trying to implement the A\* algorithm. I've been following a tutorial and got to this point, but my characters can't move diagonally up and left.

Can anyone help me with this? The return x and y are int pointers which the characters are using to move towards the target.

```
void level::aStar(int startx, int starty, int targetx, int targety, int* returnx, int* returny)
{
    aStarGridSquare* currentSquare = new aStarGridSquare();
    aStarGridSquare* startSquare = new aStarGridSquare();
    aStarGridSquare* targetSquare = new aStarGridSquare();
    aStarGridSquare* adjacentSquare = new aStarGridSquare();
    aStarOpenList.clear();
    for(unsigned int i=0; i<aStarGridSquareList.size(); i++)
    {
        aStarGridSquareList[i]->open=false;
        aStarGridSquareList[i]->closed=false;
    }
    startSquare=getaStarGridSquare(startx, starty);
    targetSquare=getaStarGridSquare(targetx, targety);
    if(startSquare==targetSquare)
    {
        *returnx=startx;
        *returny=starty;
        return;
    }
    startSquare->CostFromStart=0;
    startSquare->CostToTraverse=0;
    startSquare->parent = NULL;
    currentSquare=startSquare;
    aStarOpenList.push_back(currentSquare);
    while(currentSquare!=targetSquare && aStarOpenList.size()>0)
    {
        //unsigned int totalCostEstimate=aStarOpenList[0]->TotalCostEstimate;
        //currentSquare=aStarOpenList[0];
        for(unsigned int i=0; i<aStarOpenList.size(); i++)
        {
            if(aStarOpenList.size()>1)
            {
                for(unsigned int j=1; j<aStarOpenList.size()-1; j++)
                {
                    if(aStarOpenList[i]->TotalCostEstimate<aStarOpenList[j]->TotalCostEstimate)
                    {
                        currentSquare=aStarOpenList[i];
                    }
                    else
                    {
                        currentSquare=aStarOpenList[j];
                    }
                }
            }
            else
            {
                currentSquare = aStarOpenList[i];
            }
        }
        currentSquare->closed=true;
        currentSquare->open=false;
        for(unsigned int i=0; i<aStarOpenList.size(); i++)
        {
            if(aStarOpenList[i]==currentSquare)
            {
                aStarOpenList.erase(aStarOpenList.begin()+i);
            }
        }
        for(unsigned int i = currentSquare->blocky - 32; i <= currentSquare->blocky + 32; i+=32)
        {
            for(unsigned int j = currentSquare->blockx - 32; j<= currentSquare->blockx + 32; j+=32)
            {
                adjacentSquare=getaStarGridSquare(j/32, i/32);
                if(adjacentSquare!=NULL)
                {
                    if(adjacentSquare->blocked==false && adjacentSquare->closed==false)
                    {
                        if(adjacentSquare->open==false)
                        {
                            adjacentSquare->parent=currentSquare;
                            if(currentSquare->parent!=NULL)
                            {
                                currentSquare->CostFromStart = currentSquare->parent->CostFromStart + currentSquare->CostToTraverse + startSquare->CostFromStart;
                            }
                            else
                            {
                                currentSquare->CostFromStart=0;
                            }
                            adjacentSquare->CostFromStart =currentSquare->CostFromStart + adjacentSquare->CostToTraverse;// adjacentSquare->parent->CostFromStart + adjacentSquare->CostToTraverse;
                            //currentSquare->CostToEndEstimate = abs(currentSquare->blockx - targetSquare->blockx) + abs(currentSquare->blocky - targetSquare->blocky);
                            //currentSquare->TotalCostEstimate = currentSquare->CostFromStart + currentSquare->CostToEndEstimate;
                            adjacentSquare->open = true;

                            adjacentSquare->CostToEndEstimate=abs(adjacentSquare->blockx- targetSquare->blockx) + abs(adjacentSquare->blocky-targetSquare->blocky);
                            adjacentSquare->TotalCostEstimate = adjacentSquare->CostFromStart+adjacentSquare->CostToEndEstimate;
                            //adjacentSquare->open=true;*/
                            aStarOpenList.push_back(adjacentSquare);
                        }
                        else
                        {
                            if(adjacentSquare->parent->CostFromStart > currentSquare->CostFromStart)
                            {
                                adjacentSquare->parent=currentSquare;
                                if(currentSquare->parent!=NULL)
                                {
                                    currentSquare->CostFromStart = currentSquare->parent->CostFromStart + currentSquare->CostToTraverse + startSquare->CostFromStart;
                                }
                                else
                                {
                                    currentSquare->CostFromStart=0;
                                }
                                adjacentSquare->CostFromStart =currentSquare->CostFromStart + adjacentSquare->CostToTraverse;// adjacentSquare->parent->CostFromStart + adjacentSquare->CostToTraverse;
                                //currentSquare->CostToEndEstimate = abs(currentSquare->blockx - targetSquare->blockx) + abs(currentSquare->blocky - targetSquare->blocky);
                                //currentSquare->TotalCostEstimate = currentSquare->CostFromStart + currentSquare->CostToEndEstimate;

                                adjacentSquare->CostFromStart = adjacentSquare->parent->CostFromStart + adjacentSquare->CostToTraverse;
                                adjacentSquare->CostToEndEstimate=abs(adjacentSquare->blockx - targetSquare->blockx) + abs(adjacentSquare->blocky - targetSquare->blocky);
                                adjacentSquare->TotalCostEstimate = adjacentSquare->CostFromStart+adjacentSquare->CostToEndEstimate;
                            }
                        }
                    }
                }
            }
        }
    }
    if(aStarOpenList.size()==0)//if empty
    {
        *returnx =startx;
        *returny =starty;
        return;
    }
    else
    {
        for(unsigned int i=0; i< aStarOpenList.size(); i++)
        {
            if(currentSquare->parent==NULL)
            {
                //int tempX = targetSquare->blockx;
                //int tempY = targetSquare->blocky;
                *returnx=targetSquare->blockx;
                *returny=targetSquare->blocky;
                break;
            }
            else
            {
                currentSquare=currentSquare->parent;
            }
        }
    }
}

```

# Answer
> 7 votes
Here is a list of bugs I could spot on first check. I'm not sure which one will fix your problem or if any of them would actually fix them but here it goes:

1. `startSquare` is a simple pointer which you are allocating when your function begins. Later on line 13 you are reassigning another value to that pointer, which causes memory leak. Since you'll not be able to delete it's old value. The same goes for `targetSquare`.
2. Before returning on line 19 you need to deallocate all the memory you've got in the function. Note that it's C++ you are working with, it doesn't have fancy things like garbage collector so you need to keep track of everything you are not using and delete them manually.
3. All your `for` statements from line 30 to line 50 is just rubbish, if you want to find the minimum estimated cost it's a single `for` loop iterating over `aStarSquareList` and checking which one has minimum value. Here is how you should have implemented it (with minimum change, also this one seems to be causing the problem):

```
{
    {
        currentSqaure = aStarOpenList[0];
        for(unsigned int j=1; j<aStarOpenList.size(); j++)
        {
            if(aStarOpenList[i]->TotalCostEstimate<currentSqaure->TotalCostEstimate)
                currentSquare=aStarOpenList[i];
        }
    }
}

```
4. Instead of using an array and searching for minimum value yourself it's much better to use a priority queue. If you don't know what it is check C++ reference.
5. There is no need to keep both `close` and `open` flag for all the sqaures. Just `close` is enough. Adding a state multiple times to the `aStarOpenList` doesn't hurt anybody, just check everytime you choose `currentSquare` that it's not already closed. So remove `if` statement at line 69.
6. At line 72 `if` is not necessary, you simply know that no parent is NULL since you are assigning some value into it just before `if`. Note that `currentSquare` also can't be NULL.
7. Also line 80 is a duplicate to line 74, just as in line 74 you are taking `startSquare->CostFromStart` into account which is completely irrelevant to path chosen. It only helps you to find minimum distant. You can add that value only once when you are returning.
8. Also forget the `else` part from line 90 line 111, as I said adding a value multiple times doesn't hurt anybody. It might look a bit slower at first sight but believe me, it'll prevent many possible implementation bugs.
9. You should change the comment at line 117, change it from `//if empty` to `//if there was no path`, it makes more sense.
10. At line 127 how can a parent be NULL unless it's the starting square? Every other square beside the starting square has a parent. In your case, also the second square in your path (for which the parent is `startSquare`). So change that `if` statement to this one `if(currentSquare->parent==startSquare)`
11. This one also depends on your style but I prefer `return` instead of `break` at line 133.
12. Again I think you are leaking some memory both at line 121 and at function end.

I hope I've fixed everything but it's almost impossible, so don't worry if there are still some bugs in your code after these fixes.

**EDIT**

On the second check you are also leaking memory by allocating memory for both `currentSquare` and `adjacentSquare`. Just drop the `new` statements from their declarations and everything about them will be fixed.

---
Tags: c++, path-finding
---


# Question
Title: How do I properly implement zooming in my game?
I'm trying to implement a zoom feature but I have a problem. I am zooming in and out a camera with a pinch gesture, I update the camera each time in the render, but my sprites keep their original position and don't change with the zoom in or zoom out.

The Libraries are from libgdx.

What am I missing?

```
private void zoomIn()
{
    ((OrthographicCamera)this.stage.getCamera()).zoom += .01;
}

public boolean pinch(Vector2 arg0, Vector2 arg1, Vector2 arg2, Vector2 arg3)
{
    // TODO Auto-generated method stub
    zoomIn();
    return false;
}

public void render(float arg0)
{
    this.gl.glClear(GL10.GL_DEPTH_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT);
    ((OrthographicCamera)this.stage.getCamera()).update();
    this.stage.draw();
}

public boolean touchDown(int arg0, int arg1, int arg2)
{
    this.stage.toStageCoordinates(arg0, arg1, point);
    Actor actor = this.stage.hit(point.x, point.y);

    if(actor instanceof Group)
    {
        ((LevelSelect)((Group) actor).getActors().get(0)).touched();
    }

    return true;
}

```

**Zoom In**

**Zoom Out**

# Answer
My best guess is that your sprites reside in the same world space as the camera does while your hit boxes (collision rects) reside in screen space. Your world space sprites are affected by the camera's zoom but screen space collision boxes are not.

Your best shot it to quantify your collision boxes in world space like your sprites are instead of screen space and then you will not have this problem.
> 2 votes

---
Tags: camera, libgdx
---


# Question
Title: Level Editor + Game -> Duplicating rendering/game specific code?
I've been reading about how to design code for a game. One thing I haven't been able to figure out is - how do you manage writing an outside-game level editor (not an 'in-game level editor') without 'copying' code from the game? For example, you might have to copy all code about the different types of entities you can have. You'll have to add the game rendering code.

My guess is this can be done by making a DLL out of the 'engine' part of the game. Then, share it between the actual game and the level editor.

Or is there a better/easier way to do this?

# Answer
You will have to separate your code into separate projects (in the same solution). Usually you would have the following setup:

```
-Engine Core       (DLL)
-Game + Game Logic (EXE)
-Content Pipeline  (DLL)
-Editor            (EXE)

```

For even larger projects you might want to separate the Engine Core over multiple projects like Core, Physics, Graphics, Audio, Input and Networking. All these projects can't reference each other, but they all reference Core where you can store some common base types.

If they would reference each other the separation would be useless.

Anyway this should help you reuse parts of your engine in other projects. For example for the editor you would need to reference the Graphics project which references Core itself.

This separation also means that you can now use Windows Only technologies, like WPF, in your editor while your game can still target Windows and XBLIG.

For more info on using XNA inside a WPF environment see this link.
> 13 votes

# Answer
Separate out rendering logic as best as you could from actual game logic when designing your game engine. One way of doing this is to use Component pattern when building your game engine. For example, XNA uses this pattern at the framework level for flexibility. Use the same code-base for rendering with your level editor; write wrappers if you have to.

Similarly, another somewhat popular pattern is MVC (Model-View-Controller) which could also help. Code your engine using MVC normally. You can then use the same code for View and Model, but inject a custom Controller for editing the Model for your level editor instead of the game engine's Controller that updates according to game input. Implement serialization for game Models to load/save them from editor or game.

Keeping components in separate assemblies will of course encourage separation...
> 4 votes

---
Tags: xna, map-editor, 2.5d
---


# Question
Title: Any way to set up a grid for a board game in cocos 2d?
My first idea was to create a 2d array for my columns and rows, but it seems like there should be a better, or possibly cleaner, way to achieve this. Each square on the grid is going to have a background image, probably a .png although I might just draw the images with a draw method. Basically, I want to be able to drag and drop images onto the individual grid squares. I've been searching for a solution and the closest thing I can find is the tiled map solution. That just seems like a little overkill for what I'm trying to accomplish. Also, I don't know if this helps but i need my grid to be 12 by 12 and take up the entire width of the iphone screen.

# Answer
> 2 votes
Use tiled map editor compatible with cocos2d.

A tutorial on this subject: http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

---
Tags: cocos2d-iphone, grid
---


# Question
Title: Is there an engine that allows the use of webcams in an MMO?
For MMOs, are there engines for mapping inputs from a webcam into the virtual world? In other words, if there is a group of 50 online characters together, is there a way to see all their facial expressions or real faces together?

# Answer
> 1 votes
There are very few "MMO engine" middleware products at all -- see this question for some examples. None of them support splatting webcam feeds onto player models; such a thing is not really an MMO-specific feature and consequently there's no reason for it to be part of an MMO middleware package.

---
Tags: mmo
---