# Question
Title: A few queries about my Map Data (& ideas of improvement, seconded opinion required)
so like the title says i'm trying to think of ways that i can basically improve my level/map data. Currently it's "alright" but i don't feel it's great. There's certain things that i'd like to-do to improve on it, but i have concerns on things that i have in mind. So i guess i'm looking for seconded opinions. For some more basic info, the game is written in C# using XNA.

So i'll begin by showing you guys a example of a level i currently have; http://pastebin.com/dnYQfMYV

So currently the files are in a .txt format, i'm 100% sure that i'm going to change this into XML. I think purely because i can hopefully add in extra data with ease, without having to worry about the reading of that data as much. Especially since using the new XElement API, it makes things so much easier :).

But onto my concerns:

1. Currently, you'll see my collision layer containing a variety of numbers, currently these numbers represent items to load, or collision objects i.e 1 references a normal collision, 2 is a right slope object, 3 is a left slope etc. But my idea is separate the object items from the collision data, to give them there individual data section. What i mean is saving them directly into the level data file, underneath the layers. Instead of how i'm doing it now which really is taking the numbers and creating them just after the collision layer has been read. My concern; Lots more data will most be saved, especially in bigger areas were there might be a-lot of enemies, maximum enemy count for a big stage, will likely be around \<=20. So should i be worried in terms of having to load that data? And also with saving data, i guess both go hand-in-hand.
2. My next idea i had was perhaps on concerning a way of improving the level flow of the game, currently again you'll see in the Collision Layer the Number "50" at the far edge of the screen, this here means that we've hit a level exit. Sort of a trigger to say ok, were should we go next. At the top of the file, you see the map exits, currently showing that if the player leaves the map via those edges, what level should we open up next. Right now i guess i don't necessarily like the system, i have the idea of having the level exit data also be it's own entity in the map data, that way hopefully i can customize it and i guess it's restrictive in that i would only be able to have 1 exit per edge, were i might like to change things up with multiple exits to levels on the edges. But i'm curious to if this is a good way of going about it? Or if there is perhaps a better alternative?
3. Third & finally, its all good talking about these ideas, and mainly they really are concerned with placing things into there own unique structures in the level data, and there pros/cons of doing that. But in terms of placing these items, i'm going to need a form of library in which i can then use to select what objects i want to place. Whether these be some form of animation tile, or enemy. I've been looking around at a few examples of this, i think what i'd like to-do is somewhat similar to this video: http://www.youtube.com/watch?v=lbmaVlGXE0A&list=UUlkmq35aIgZCy5KHst78C5g&index=5&feature=plcp If you skip to 5:15 mark you'll see his approach. He manages all his objects, animated files etc. via the menu interface he has, which i think should work quite well for what i'm thinking of doing. My concern, will that be suitable to fit the purpose of what i have in mind? In terms of a few coding questions here, i myself will be using .net like he has, so i'm wondering what toolbox object he uses to show the hierarchy of his folders\> \*You see this at the 5:20 mark. I'm also wondering when he right clicks on his animated tile template, he has his own little "edit/delete" menu pop-up, i think something like that would be a nice addition to my editor, and am curious on how to achieve this myself.

And there's my concerns, ideas and questions i have. Quite a bit to read, sorry about that. But really I've been looking back at my progress on my game over the last few weeks, to notice how annoying certain things are, and i guess i just really want to improve things. Make things easier on myself, and perhaps learn something while i'm at it :). So thanks in advance for any help :D.

# Answer
> 0 votes
Firstly, your pastebin is hard to read. I took the liberty of doing a simple search and replace, to make it Tab-delimited instead of space: http://pastebin.com/YiSUiEmJ

Hope you don't mind. Don't forget to toggle off line wrap!

1. I don't entirely understand your question, but I'll do my best.

* Text files are not big. Your text file is tiny. If you are really concerned about space in this age of cheap 1 TB hard drives, you should think about saving the files in some binary format (and including a level editor if you want people to make their own levels).
    * Do separate the collision map and the enemy placement map! An extra map is not that much space in the grand scheme of thing, but it will make things a lot more sane and organized for you or any other level designer.
    * For placing a small number of enemies on a large map, consider using a list instead of an explicit matrix. Your file's enemies section would have 20 lines like "56: 12, 24" which your game would interpret as "place an enemy of type 56 at coordinates 12, 24".
2. Again, you can use a list for exits. It would be a separate list for exits only, and go like "7: 64, 2" which means there is an exit at 64, 2 which goes to level 7. You can easily come up with a system for defining whole rectangles as exits if you need to mark large exit areas.
3. Again, I don't understand.

* Do you have trouble remembering what the numbers mean? For inside the program, check out `Enum`. Besides that, you can use letters (and even words) instead of numbers. Currently, I use colors, which has the added benefit of making my levels look nice in Paint.
    * Do you want a level editor? Then make one. It's a fairly trivial application. Even Excel is a pretty powerful tool (Ctrl for selecting multiple cells, don't forget about conditional formatting) for making such files.
    * Do you want a program you can use that someone else wrote? Simply find a game similar to yours which does have a level editor, and make your game's file format compatible with that game's level editor.

---
Tags: xna, c#, maps, .net, data
---


title: General 2D Collision Detection Question

text:
# Question
Title: General 2D Collision Detection Question
Everytime I have coded "working" collision, I always went about it very haphazardly and unstructured. If I use Axis Aligned, or Verlet, Or Euler, any or all of these theories, my problems always lie in the edge cases. Let me invent a scenario to better explain my question.

Imagine a 2D game, let's use Mario as the best example. So there is gravity, there is acceleration and friction. If the world is being loaded as all individual, let's say 32 x 32, tiles, while the player is moving along the ground, there will always be that edge case of when he happens to be in the dead center of both tiles, and collision ends up being checked on both tiles below him and of course he gets moved based on both tiles' positions.

So in that case, I assume I would only want to be checking top block collision (bottom of player) only, and not side collisions, but then when I'm jumping onto a tile, or block, I know I want to check bottom player collision, so I can land, but that doesn't stand for anytime the player is in the air right? Cause what if I'm falling/jumping, and I hit the side of a block or wall, I want to check side collision. And then what if I hit the side of one block, but in that frame of collision when the player overlapped the tiles, he also got into the top of one of the tiles and now gets his y position moved because of it.

So the tl;dr version of my rambling is...

What's the most sensible way to structure collision? Totally case specific, i.e. only check specific collisions dependant on surrounding tiles, or the movement of the player?

Or is there a broad way to keep all collisions being checked (top, sides and bottom of player) and deal with the edge cases as well?

Also this isn't language specific, I'm speaking totally in generics. Any code examples are welcome. (Any language)

Thanks. (Hope my rambling isn't too convoluted and it makes sense. \>\<

# Answer
Here's how I've done it in the past (for AABB rectangle sprites):

* Find the position the player would be this frame after a position update.
* Create a rectangle at that position the player will be at and check that rectangle against all other rectangles the player could collide with (preferably only the nearby ones, for efficiency).
* For any overlaps found, find how far the overlap is from each side of the rectangle. For example, maybe the players sprite is overlapping another sprite such that two sides of the other are overlapping.

In the image here you can see the overlap distances are 5 and 7. From this you can create determine how far to push the player so the they will not be overlapping any longer, you would move the player up 5 units and over 7 units.

The tricky part can be when you're overlapping multiple squares at once though, if you resolve them all one at a time, pushing out of one box can push you into another. To solve this, combine all the results from each rectangle into a single position change, and once you have all of those results you'll know the final position to move the player to this frame.
> 3 votes

# Answer
1. If differentiating collision with bottom (stops falling) and sides (stops movement) is a problem, do them separately. If you check sides, and push, before starting to check bottom, you will be out of the sides by the time bottom is checked. Also, you can do friction and collision checks separately.
2. What I do is use a rectangle intersect method similar to Nic's. I have a small area around the sprite representing "space where the sprite can go", and if any colliding objects overlap that boundary, the boundary is shrunk. Then the sprite is locked to the boundary. It seems simple enough.
3. http://info.sonicretro.org/Sonic\_Physics\_Guide has a detailed explanation of a sophisticated collision system.
4. It is impossible for an object to be "above two tiles"- its position is a vector, and is above only one tile, unless tiles overlap.
> 1 votes

---
Tags: 2d, collision-detection
---


# Question
Title: Designing a game that allows for selectable perks/customization
Call of Duty games all have the core functionality of any FPS (walking around, killing, dying and repeat). Layered on top are various stuff. Of interest to me is during pre-game when you pick your perks. These perks can have very different effects and targets. Some affect walking speed and persist throughout the game, others are only activated at certain events and last for a certain duration. I am wondering what sort of design architecture/pattern would allow such a system that supports a wide variety of perks that have little in common.

For instance, imagine I want to add a perk that speeds up the rate of fire:

Do I make all my gun classes take as a constructor argument 'rateOfFire'? but then I will need to expand the code for each perk that affects the gun and the constructor gets bloated.

Maybe have it as a setter property on each gun? but then I can also bloat properties and make code insecure since I don't want anyone except the appropriate perks to change that property. I will also have to go back exposing more properties for each new perk. In addition, other classes that depend on this value might have already been initialized after the gun was created and acted upon the original 'rateOfFire' value before I get to change it.

and so on... and to further complexity, now imagine I want to add a new perk 'walk faster for 5 seconds after you die 5 consecutive times without killing anyone(death streak)'. This perk has nothing in common with the 'rateOfFire' perk.

And also there is the issue of how to deliver those chosen perks to their targets? I was thinking of the visitor pattern, but it seems inefficient since a perk that affects only certain guns will be passed to all game components that are customizable(level manager/presenter/physics and so on). And I will also need to expose their properties so that the perk can change them once visited.

I thought of other solutions that might work, but they all seem either too complex/over engineered. I am wondering how the Call of Duty developers might have implemented what seems to be a flexible and extensible perk system (many sequels).

Any suggestions are welcome.

Note am not remaking COD, instead I am making a simple mobile puzzle game but the perk problem is similar.

# Answer
Here's my suggestion,

The main idea is let the Perk class control things.

Perk class should be like this:

```
class Perk {

    Perk(GameObject* owner);

    //called when this perk is added to perk list
    //apply things that will stay as long as player has this perk
    void onAdded();

    //called when this perk is removed from perk list
    //Usually to redo what you have done in onAdded
    void onRemoved();

    //called when this perk is activated
    //apply things when the perk is activated
    //For example, increase player speed and set the timeLeft to 5 secs
    void activate();

    //Undo things you've done in activate()
    void deactivate();

    //called each update
    //for example, reduce the timer, when timer reach 0, call deactivate
    void update(double deltaTime);

    //Handle event
    void onEvent(Event evt);
}

```

Gun attribute modifier: Gun should have two kind of attributes: baseAttribute and modifierAttribute. modifierAttribute can be accessed from anywhere. In your concrete Perk class, get modifierAttribute and do things, like: `modifierAttribute.rateOfFire += 5`. Gun class will consider the values in modifierAttribute when necessary. Separate those attribute is neat, because probably you'll need the original attribute (for example, increase rateOfFire by 5% effect).

For activating the perk based on certain event, you'll need event system in your game. When perk is added into the perk list, you'll register to certain event in the event system. Here is and example:

```
Perk.onAdded() {
    EventSystem.add(Event.PLAYER_DAMAGED, this);
    EventSystem.add(Event.PLAYER_KILL_ENEMY, this);
}

Perk.onEvent(Event evt) {
    if(evt == PLAYER_DAMAGED) {
        if(++_playerDamaged >= 5)
            this.activate()
    }

    else if(evt == PLAYER_KILL_ENEMY) {
        //do something else
    }
}

int _playerDamaged;

```
> 2 votes

# Answer
If you want a perk that affects RateOfFire, you must allow the guns' RateOfFire to be open for modification by outside actors, by definition. Escaping that would be a logical problem.

For your example of running faster after dying five times, wouldn't that work nicely as an event for your class?
> 1 votes

# Answer
What you would need is a Perk class with a public map (or something) that stores the effects of perks. This class would also need access the Player object.

Perks fall into 2 general categories (off the top of my head)

1. Modify base stat
2. Give certain ability/item/new action

All perks that fall into category 1 can insert their modifier value into the map \[rateOfFire; 1.1\] and whenever that value needs to be used you just make sure to check the perk object as well. Also, you can determine which perks are permanent, put them in a separate map, and have all affected objects reference it at match setup. For goal based perks, such as "+speed for 5 secs after killstreak" you just need an event trigger that modifies the Perk object.

For cat 2 perks (e.g. thing where you drop grenades as you die) you just need to code up actions, which a bunch of event triggers that get set at match setup based on a call to/from Perks class
> 1 votes

# Answer
Perhaps you can have a class `Perk` which contains read-only properties for each thing you want to perk. Then pass all the perks to your various classes in a `List<Perk>` whenever you need to. Inside the different classes of your game, you change each property that's relevant.
> 0 votes

---
Tags: c#, xna, architecture, effect-modifier
---


title: Trace with 2D terrain

text:
# Question
Title: Trace with 2D terrain
I currently have some 2D terrain in my game defined by 2D coordinates with lines drawn in between them (linear interpolation too keep it simple).

Now I want to cast a ray from anywhere above the terrain and see if it collides with the terrain for drawing bullet tracers.

Here is a quickly drawn example:

# Answer
The answer you're looking for is covered by many answers on this page:

https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect

**Here is the exact text of the most popular answer at the time that I'm posting this, posted by user Gareth Rees:**

There’s a nice approach to this problem that uses vector cross products. Define the 2-dimensional vector cross product v × w to be vxwy − vywx (this is the magnitude of the 3-dimensional cross product).

Suppose the two line segments run from p to p + r and from q to q + s. Then any point on the first line is representable as p + tr (for a scalar parameter t) and any point on the second line as q + us (for a scalar parameter u).

The two lines intersect if we can find t and u such that:

> p + tr = q + us

Cross both sides with s, getting

> (p + tr) × s = (q + us) × s

And since s×s = 0, this means

> t(r × s) = (q − p) × s

And therefore, solving for t:

> t = (q − p) × s / (r × s)

In the same way, we can solve for u:

> u = (q − p) × r / (r × s)

Now if r × s = 0 then the two lines are parallel. (There are two cases: if (q − p) × r = 0 too, then the lines are collinear, otherwise they never intersect.)

Otherwise the intersection point is on the original pair of line segments if 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1.

(Credit: this method is the 2-dimensional specialization of the 3D line intersection algorithm from the article "Intersection of two lines in three-space" by Ronald Graham, published in Graphics Gems, page 304. In three dimensions, the usual case is that the lines are skew (neither parallel nor intersecting) in which case the method gives the points of closest approach of the two lines.)
> 1 votes

# Answer
I guess you can handle the rest, but the main idea is written in this wiki page.

using the formula above you can find the intersection point of a ray and a segment; note that ray is defined by (x1,y1) and (x2,y2) and the line segment is between (x3,y3) and(x4,y4).
> 0 votes

---
Tags: c#, 2d, collision-detection, terrain
---


# Question
Title: Perspective projection with 90 degrees between X-Y axis?
I'm trying to create a game that mimics Tibia's projection style:
<sub>(source: mmoginfo.com)</sub>
,

As you can see, a 3d point is mapped to 2d like this:

So I've downloaded Three.JS and a lib to create a Orthographic Camera. But I'm getting this:

Where, as you can see, the projection is like this:

Which is not what I want. What can I do to get the desired projection?

NOTE: I noticed the Orthographic Camera object is just a regular camera with camera.projectionMatrix changed, so I guess I could create my own kind of camera object, probably finding out the right projectionMatrix, but how?

# Answer
What you'll need to do is create a sheared projection matrix that leaves the X and Y axes alone but bends the Z axis up and to the left. The matrix to do the shearing would generally look like this:

```
1 0 A 0
0 1 B 0
0 0 1 0
0 0 0 1

```

Or possibly the transpose of that, depending on whether your math library is using a column vector convention (as above) or a row vector convention. You'll probably need to multiply the above matrix with a regular 2D top-down projection matrix (which order they go in will also depend on the vector convention). Here, A and B are numbers that control how far the Z axis gets sheared along the X and Y axes respectively. I'd suggest trying values between -1 and +1 for these and tweaking to get the look you want.
> 5 votes

---
Tags: 3d, camera, projection
---


# Question
Title: Cocos2d -- Check if place is free before moving (all objects)
Is there a method in Cocos2d like `CGRectIntersectsRect`, except instead of limiting it to one sprite, it checks for ALL objects?

# Answer
> 3 votes
What you can do is get all the children in the current layer and then iterate through then and use the `CGRectIntersectsRect` function to check if the any node is present at your desired location.

After that you can do what ever you want to do with the nodes that are present at that frame.

You need to get all the nodes like this

```
CCArray *childrenNodes = [self children];

```

and check for intersection like this

```
for(CCNode *someNode in childrenNodes)
{
    CGRect rect = ((CCSprite *)someNode).textureRect;
    if(CGRectIntersectsRect(rect, desiredRect))
    {
        // --------------------->Do something
    }
}

```

**Edit:**
As mentioned in your below comment you can modify the above code to only check for a particular type of sprite or sprites. For this to happen you need to subclass ccsprite or give a tag to a set of sprite representing a particular type of object, then in the for loop only check for that sprite or sprites depending on your requirement.

```
for(CCNode *someNode in childrenNodes)
{
    if([someNode isKindOfClass:YourSpriteClass] || someNode.tag == 81)
        continue;
    CGRect rect = ((CCSprite *)someNode).textureRect;
    if(CGRectIntersectsRect(rect, desiredRect))
    {
        // --------------------->Do something
    }
}

```

I think you will get the idea from the above code.

---
Tags: cocos2d-iphone, objective-c
---


# Question
Title: What kind of gaming platforms for Linux are available?
Which libraries/platforms are available on Linux to start game development?

# Answer
OpenGL and SDL are both open source and cross platform.

For C#, there is also a Mono library, which attempts to be a game library like XNA but cross-platform. I have not used Mono, but heard bad things about it.

PyGame is another popular cross platform library.

I don't know much about Java libraries, but Java itself tends to be easy for simple beginner projects, and it is obviously suited for multiplatform stuff.

The Unreal Engine apparently works on Linux using OpenGL, you might be happy to hear.

In general, anything open source will probably support GNU/Linux. More than that, they usually "start" on Linux. Proprietary stuff rarely strays outside Windows, on the other hand.

Keep in mind that if you develop for Windows, using for instance DirectX 9, your games might be playable through Wine on Linux if you're lucky.
> 4 votes

---
Tags: linux
---


# Question
Title: Generic item collision/reflection in Pong (Flash)
I am trying to find a good way to handle ball/paddle collisions/reflections in Pong. I've tried the "naive" approach of just checking x and y coordinates against each other, figuring out where the ball hits on the paddle and how to change reflection, etc, but it seems so tedious to do it this way. I feel like I have to check collisions against the front of the paddle, then the sides, etc.

Is there a good, general way I can check for a collision between the ball and the paddle (be it sides, front, etc), ensure the ball doesn't pass through the paddle, determine where the ball touches the paddle in terms of tangency (if we don't allow the ball to move through the paddle), and determine reflection rules based on that point of tangency?

I've already looked into Corey's Detection Kit but it didn't seem to work for my purposes.

Consider the picture at the bottom of this post. Let's say the red ball is where the ball WANTS to appear based on the speed/frame-based update routine for the ball. Using some routine, it determines there is an intersection because either the sprites overlap or the path of travel overlays the paddle. But I really want to bring the ball back up to where it's actually touching the paddle at tangency. Is there a general way to do this?

https://i.stack.imgur.com/Xo99a.png

# Answer
> 3 votes
General-purpose solutions *are always harder to implement than specific, corner case solutions*. That is a fact of life in engineering. And it is the nature of shortcuts: They're quick, and you don't get to do everything you would have on the longer route. If you can shortcut it, when it comes to games anyway, then do. Anyhow...

Look at the point of tangency in your drawing. Connect that line to the centre of the green circle.

Now what you find is that that line is of length R, where R is the radius of your ball. In other words, at that perp distance, the ball is tangent to the paddle. So we need to find some point on the incoming trajectory where a line extended directly (perpendicularly) toward the surface of the paddle is of length R. That will be the exact point where the centre of the ball will be, as it becomes tangent to the paddle.

* T: the point of tangency, which you marked as a square;
* I: the point where the trajectory *line* intersects the paddle surface *line*;
* C: the centre of the green circle, that we need to find.
* A: the last point in free space where the ball was before the collision (last update).

Tan(theta) = Opposite/Adjacent

Adjacent = `TI`, the line whose length you want to find, so that you know exactly the x value at which to place the centre of the ball such that it is tangent to the paddle. Opposite = `TC` = `R`, the radius of your ball. Theta = angle `TIA`, the angle made by the tangent point and the last valid position of the ball. You should be able to determine this easily enough, it's just the angle between the two lines. So,

`TI = TC / Tan(TIA)`

Now you have the x (TC) and the y (TI) offset relative to your point of intersection, that shows where the circle's centre should be for it to be tangent.

New Centre = Intersection + Offset

HTH.

# Answer
> 0 votes
For a simple implementation of 'checking' whether collision has occured. You could use this algorithm.

```
private function enterFrameListener(event:Event)
{
    if(ball.hitTestObject(paddle))
    {
        //assuming ball comes and hits the paddle from top and
        // x coordinate increases to the right and y to the down
        if( ball.y >= paddle.y ) //
        {
           //paddle.y is assumed to be the toppest point on the paddle
           // if paddle.y is the center point, use
           // paddle.y-paddle.height/2

           //okay since the ball has hit the paddle and is intersecting it
           // this is a situation we do not want. change the position of the ball to
           //a position where you are sure there would not be a
           //collision with the paddle. ie at that point ball.hitTestObject(paddle)
           //should return false

           ball.y = paddle.y - ball.height/2;
           //  here I am assuming the ball has
           //its orgin at center point

           //now just write your code for reversing the ball movement direction
           //i'm assuming its like this
           yVel = -1* yVel;

```

This should work for Pong ball - paddle collision.

Happy coding

---
Tags: flash
---


# Question
Title: What online games would let me practice AI development?
I am working on a project experimenting with Artificial Intelligence design methodologies for *online world* avatars. *Online world* here is quite open to interpretation; *Second Life* is just as applicable as *Counter Strike*, for example. To carry out these experiments, I must first develop an intelligent agent for the world in question. However, I am honestly quite stuck as to which game I could use for this.

My preference was to develop an intelligent "bot" to play an MMORPG, but the legal restrictions of such games prevent me. Likewise with most FPS games the use of an intelligent agent in place of a human player is considered cheating.

The alternative, of course, is to create an NPC bot; an intelligent agent that populates the world alongside the player(s) rather than replacing a particular player. However, I'm struggling to find a game that would enable me to create an intelligent opponent either.

I suppose the main requirements would be a game allows a third party program to use the function calls usually utilised by players and read feedback on the state of the world.

Quake III and Unreal Tournament have been suggested before, but they have already been the subject of work on this research project.

Short of writing my own online game from scratch, what games would allow me, through middleware, an API, or otherwise, to create either an artificially intelligent player or a bot?

# Answer
You could try setting up your own server running one of the open-sourced MMO codebases. PlaneShift is one such game, and WorldForge has (last time I looked) several games with simpler rulesets. Ryzom is a formerly closed-source MMO that released both their code and their assets as open source.

Setting up your own server from these codebases will probably take a bit of work, and more hardware. On the upside, you'd be able to control the environment, and possibly get better data about your agent. You'd also have access to the code, which should help immensely in implementing your agent's communication with the game servers.
> 7 votes

# Answer
This is aimed at the path of Counter Strike more than Second Life, but the game Cube 2 is a fully open source FPS which has been used in lots of research projects that need a fully modifiable multiplayer game. This is the one paper I know of that uses it for its ease to mod.

For a more MMO type game, you could always try finding private servers of popular games such as WOW. I'm pretty sure these are illegal in the first place, so botting on one isn't going to hit any legal issues, though server admins may kick you.

Lastly there's Minecraft, seems to fit the bill of online game, and its really simple to set up your own server. Also there's previous work done towards bots, as seen with the auto building bots, and complex enemy AI mods.
> 5 votes

# Answer
I can give you access to my homemade "MMORPG":s communication protocol if you want to.

It is in French but I plan to change that.
> 1 votes

---
Tags: ai, online
---


# Question
Title: Panda3D documentation, manual, and tutorials for offline viewing?
Is there a way to get the Panda3D's manual and tutorials available for offline viewing? I'm going on a business trip and I will spend a good deal of time at the airports and on long flights. I'd love to get started on Panda3D while in flight. Is there a way to get all that information available for offline, or use some program to download the tutorials and manual webpages?

Thanks

# Answer
> 7 votes
If you go to the Downloads section, under Snapshot Builds, you can find the documentation bundled as a zipfile or as chm, ready for downloading:

# Answer
> 0 votes
The manual for version 1.5.0 is available here.

---
Tags: python, manuals
---


# Question
Title: throw a 2D ball facing the target to simulate a 3D like effect
How would you update the state of a 2D object that is thrown forward(with an arc) facing a target to simulate a 3D(depth) like effect?

```
var ball; //2D ball from a sprite sheet
ball.x = 0;
ball.y = 0;
ball.scaleX = 1;
ball.scaleY = 1;

ball.throw(); //set ball to a throwing state
ball.update(); //update the ball's positon and depth by calculating its current coordinates and scale.
ball.render();

```

# Answer
> 2 votes
i think you should add a z property to your ball, and then update scaleX and scaleY accordingly :

throw()

```
ball.vx = 0.0f; //no move horizontally
ball.vy = 3.0f; //to have arc effect
ball.vz = 5.0f; //throw forward

```

update()

```
//move the ball
ball.x += ball.vx;
ball.y += ball.vy;
ball.z += ball.vz;

//gravity
ball.vy -= 0.097f;

//add code here to check collision against floor and bounce
//...

//some friction
ball.vx *= 0.99f;
ball.vy *= 0.99f;
ball.vz *= 0.99f;

```

render()

```
//projection
//very simple formula, assume camera is origin

float x = ball.x / ball.z;
float y = ball.y / ball.z;

float scaleX = ball.scaleX / ball.z;
float scaleY = ball.scaleY / ball.z;

draw ball at pos (x,y) , using scaleX and scaleY

```

---
Tags: 2d, 3d, algorithm, javascript
---


title: XNA: SpriteFont question

text:
# Question
Title: XNA: SpriteFont question
I need some help with the SpriteFont. I want a different font for my game, other than Kootenay. So, I edit the SpriteFont xml, i.e:

```
<FontName>Kootenay</FontName>

```

or

```
<FontName>Arial</FontName>

```

No problem with Windows fonts, or other XNA redistributable fonts pack. However, I want to use other fonts, that I downloaded and installed already, they are TTF or OTF, both supported by XNA. My problem is, I cant use them, I got this error:

> The font family "all the fonts i tried" could not be found. Please ensure the requested font is installed, and is a TrueType or OpenType font.

So, checking at the windows fonts folder, I check the properties and details of the fonts, I try all the names they have, and but never works. Maybe I need some kind of importing or installing in order to use them, I dont know, and I hope you guys can help me, thanks!

# Answer
> 5 votes
If you see your font in fonts directory, just try to restart Visual Studio or whole system. It should help.

I tried it - I installed new font, add it into running MSVS project, then compile and get the same error as you. When I restarted MSVS and compile again, it worked.

# Answer
> 1 votes
Try putting the font file in the same directory as your spritefont file.

# Answer
> 1 votes
It appears the problem is this: XNA claims to support Truetype and Opentype fonts. However, some Opentype fonts have Postscript outlines, which XNA *doesn't* support. So they won't import. One example is Philosopher, an otf font which doesn't have compatible outlines.

The solution is to convert the font to Truetype. The font I mentioned won't work in XNA, but after converting it to ttf with this online tool, it does. Make sure you delete the old font from Control Panel/Fonts to avoid confusion.

Moreover, restarting the OS is unnecessary. Restarting VS is sufficient.

---
Tags: xna, c#, fonts
---


title: XNA Silverlight 5 3D Model Position

text:
# Question
Title: XNA Silverlight 5 3D Model Position
I am use to XNA and starting to learn XNA for Silverlight 5. My Question is that in XNA when you create a Model and load it using content.load you are able to access the models Position, scale etc.. In Silverlight XNA these options are not available. It would be possible to change the Models position using World Translate, but I need the models position for collision detectection using boundingSphere Any Advice??

# Answer
XNA should allow you to do something like this to create your `BoundingSphere`, so long as you get grab the vertex buffer for your model.

```
List<Vector3> vertices = GetModelVertices(scale);
BoundingSphere sphere = BoundingSphere.CreateFromPoints(vertices);

// Gets the vertices that make up a model
public List<Vector3> GetModelVertices(float Scale)
{
    List<Vector3> verts = new List<Vector3>();

    VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[numVertices];
    vertexBuffer.GetData(vertices);
    foreach (VertexPositionNormalTexture vertex in vertices)
    {
        verts.Add(vertex.Position * Scale);
    }

    return verts;
}

```

Alternatively, you should be able to iterate through each `ModelMesh` part in your model, and each of those have a `BoundingSphere` that you can query. From that you can call `BoundingSphere.CreateMerged(BoundingSphere, BoundingSphere)`, for each of the bounding spheres on the `ModelMesh` objects, and combine them to get your final bounding sphere.
> 1 votes

---
Tags: xna, collision-detection, silverlight
---


# Question
Title: How to put an invisible marker on a model and refer to it in the game?
I am using XNA/C# to load up 3ds Max models exported in FBX format. Is there some way to mark a specific point in the model like the pipe of a gun so I can just refer to it and place a bullet in there directly to make shooting look good?

# Answer
I'm not familiar with XNA specifically but most 3D development tools allow you to refer to bones in the model. In 3ds max just put a bone in the gun and then refer to that bone's position in your code.
> 7 votes

---
Tags: xna, c#, 3dsmax, fbx
---


# Question
Title: Artificial Intelligence - when to update pathfind?
Right now I have a pathfind algorithm A\* so I'm already using it to move the player around. My problem comes to the NPC'S. They find the path to the player but if the player change the position they have to find a new path all the time? or there's something I can do to avoid so many calculations?

Example I have an enemy 5 units of distance from the player. He moves to 4 units of distance based in the path he already found and then search the path again? or does he make half of the path until he search for a new path?

I imagine making that for 5 or more enemies may make the game slow? (I never tested it before) Any toughs?

# Answer
> I imagine making that for 5 or more enemies may make the game slow? (I never tested it before) Any toughs?

Don't optimize until you run into performance problems. Get the stuff working first before you make things more complex than they need to be.

That being said if you do run into problems I see 2 simple ways to optimize this issue.

1. Add an event to your player that is triggered when the players character changes orientation. The AI can subscribe to this event and update only when needed.
2. Update the check at a slower rate than the default 60hz of the XNA update loop. The average human reaction time is about .2 seconds so nobody is going to notice (or care) that the AI isn't adjusting to their movements on the millisecond. Even running the loops as slow as 5 - 10hz should be hard for a player to notice and take a lot less time.

Super Official Research
> 10 votes

# Answer
Here are some reference materials on a similar A\* search algorithm called Fridge search. This is a search which uses the last search path as a reference point to the new search path that needs updating. I believe this will help a bunch. My buddy in my CS class showed me this and it solve this same issue for me... that is if I understand your question correctly.
> 2 votes

# Answer
If your map is static (or mostly static), you might want to consider using Dijkstra's algorithm, instead of A\*. Precalculate it for every node in every map and store them as game data. When loading a level, load every shortest path for each of its nodes, and you won't need to calculate anything at runtime.

If your map is dynamic, however, Dijkstra is not an option. I'd recommend recalculating things every so often, or once the main character has deviated a certain distance from the previous known destination. It might be a good idea to run this calculations in a secondary thread. Once the calculations are ended, update each enemie's path. This will probably make their reactions a bit slower, but that often looks more natural.
> 1 votes

# Answer
By accident I was playing Killing floor and I notice how their A.I. mostly works by look. They have a huge number of monsters running around in 3d (my game is 2d by the way). So it looks like the monsters walk to a point and after they reach that point they just rush to the player. I believe this can be optimized by detecting an area where the players are and make several paths to "surround" this area. Also I believe they might be using the same path (from previous monsters) to get to the players.

Another thing I notice is that most of the monsters might never recalculate the path since they die before getting to the player. This might also turn to be an "accidental" optimization.

Finally i remembered the days I use to level design for half life and I recall of having map nodes to define pre defined paths which the monsters would use as guides to turn around. These were only used when the characters went to a certain distance around the node. But i don't believe this would be a good solution.
> 1 votes

# Answer
There is no single answer, the exact frequency probably changes from game to game. You're right in that recalculating every frame is probably not all that necessary or optimal. Decouple the pathfinding update from the other updates, and tweak the frequency to your liking. Find the point that is just often enough to not look unresponsive.
> 0 votes

---
Tags: xna, ai
---


# Question
Title: Which is better for mobile games, PNG or SVG?
I want to make several 2D games for mobile platforms, mainly using Qt for iOS, Android, Symbian, MeeGo and whatever supported by Qt.

I've made one game already using PNGs. Now I'm thinking of making a game similar to Battle Heart. What do you think is the best option, PNG files or SVG files or other formats?

# Answer
> 2 votes
If you plan to port things to reach a maximum audience I would go with SVG because of the fact that they can be easily scaled without a loss of quality. Very useful with for porting to tablets (btw polished table top games on the iPad are doing quite well) and handling the varied screen sizes between various apple and android products.

Note rendering an SVG is going to be slower than a standard file format. However, for a card game you should be fine. Also iOS likes PNGs and PNGs are the only thing that support transparency.

TL:DR

SVG if fast enough and PNG otherwise

---
Tags: android, ios, file-format, svg
---


# Question
Title: Programmatically drawing a "pencil" line or curve
If you look closely (scan it on a computer and zoon in) at a carbon pencil line you can see that there are differing shades of gray. I tried looking on the Internet for any kind of algorithm or statistical model for how that gray would be drawn programatically. Does anyone have information on this? Thanks a lot!!

I want to make drawings on a computer that look they were drawn with a pencil.

# Answer
> 2 votes
Depending what tool you're using to draw the line to the screen will change the solution to this question, but the simplest method would be to have the intensity of line color be a function of its distance to the center of the line. Therefore you would have a black line that greys out at the edges.

The other form that you could be talking about was the fact that paper is not perfectly smooth, thus the pencil will be darker on the hills and lighter on the valleys (on a minute scale of course). To do this you could just apply a couple of layers of noise in different shades of grey over your black pencil lines.

The are further methods that come to mind, but they all depend on how you're actually planning on drawing to screen.

For further research you can look into how digital artists fake pencil effects and see if any of those methods translate well into a programmable method.

# Answer
> 0 votes
It sounds like you're looking to implement something similar to anti-aliasing on whatever lines you're drawing. The high overview of anti-aliasing is it aims to reduce the jagged edges we perceive on pixelated lines by shading the pixels surrounding the line, so that the line fades into the background color. The result will look very much like the pencil effect you're describing.

This article gives a very good explanation and sample implementation of anti-aliasing.

Hope this helps :)

---
Tags: software-engineering, algorithm
---


# Question
Title: Help Reading this Data in XML as a List (ContentReader)
Edit:

So i'm going to rephrase the question a bit, seeing as now i think know how i'm going to read this data. Looking at this example as my guide: http://forums.create.msdn.com/forums/p/53404/323877.aspx

This is pretty much what i'm currently doing, and to be clear and show you guys: http://pastebin.com/GxqQcBDg, that's how i'm loading my data.

So looking at that guys example from his post, he has a similar layout, his "Enemies" can equal my element "Animated\_Tiles" and then his "Items" could be equal to my "Tile" objects, at least if you compare my data to his they look extremely similar, and yes i did update the Data as Richard Marskell - Drackir suggested, But i'm wondering if i can have "Type" definitions like the guy has in his example, to show what i mean:

```
  <Animated_Tiles Type="System.Collections.Generic.List[Namespace.Class]">

```

Can that be done? Or is it only the "Asset" element that can have the Type definition? Currently this is what my new data layout looks like: http://pastebin.com/i42166ZQ

But currently, it seems to start reading it but i get this error by the first "Tile" Element. So the only difference i see between his & my layouts are that he has the Asset containing the List definition whereas i have "Animated\_Tiles". So i'm unsure can any element can have the "Type=Blah" definition?

# Answer
Well i got it going now :). It seems that i can have other elements using the "Type=Blah" definition, i didn't know that but it's good to know. The Animated\_Tiles all needed to be "Items" of the List, i feel stupid :/ make so much sense now that the Elements in the "Animated\_Tiles" Element would be required to have the title of Item.

But it works great now :D. Thanks you guys for your answers though.
> 0 votes

# Answer
You could skip Deserializer and just use Linq to Xml:

```
var xelement = XElement.Load(file);
var tiles = xelement.Element("Animated_Tiles")
    .Elements()
    .Where(el => el.Name.LocalName.StartsWith("Tile"))
    .Select(el => new Tile {
        PositionX = (int)el.Element("PositionX"),
        PositionY = (int)el.Element("PositionY"),
        Type = el.Element("Type").Value
    })
    .ToArray();

```
> 3 votes

# Answer
Load in the XML file into a DOM tree and then iterate though the tiles.

http://support.microsoft.com/kb/317662

Edit: Or use Jimmy's Idea :)
> 0 votes

---
Tags: xna, c#, xml
---


# Question
Title: Can I use the Minecraft avatar in my game as long as I texture it differently?
I'm creating a block-based game and am ready to start developing the avatar. I would like to use the Minecraft avatar model but use my own higher resolution texture. Can I do this or will I be breaking some law or setting myself up to be sued?

# Answer
*This is not legal advice because I am not a lawyer, you should consider talking to a real lawyer if you want a proper answer to any law-related topic.*

You can't use the assets that ship with Minecraft. You can, however, create your own box-man avatar, and that would probably be a much better idea for a variety of reasons even disregarding the legal or ethical issues involved.

For example, it would be built for your technology instead of somebody else's, you have more control over it and can be more creative, et cetera.
> 11 votes

# Answer
First off, I totally agree with Josh Petrie's answer, you should have your own models. But in this kind of case there is an obvious solution that people seems to forget or doesn't want to consider...

You can ask the owner the right to use its work... explains how you would like to use it, what you need exactly etc... don't be too greedy, but if you don't ask you won't get anything.

On the following page about the Minecraft author http://www.mojang.com/notch/,you can find notch email : notch@mojang.com

He/They will probably answer you "NO", but nothing ventured, nothing gained.
> 4 votes

---
Tags: models, legal, minecraft-modding, character, avatar
---


title: 2D layerDepth not working XNA 4.0

text:
# Question
Title: 2D layerDepth not working XNA 4.0
I'm struggling with getting the depth layer to work properly. No matter what I do, the line is drawn over the top of the circle texture.

```
public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Begin(
            SpriteSortMode.BackToFront,
            BlendState.AlphaBlend,
            null,
            null,
            null,
            null,
            Camera.getTranslation());

        // Draw all planets
        foreach (PlanetNode p in planets)
        {
            p.Draw(spriteBatch);
        }

        spriteBatch.End();
    }

```

PlanetNode's Draw:

```
public void Draw(SpriteBatch spriteBatch)
{
    // Draw forwarding line
    if (resourceForward)
    {
        double dist = Math.Sqrt(Math.Pow(location.X - forwardTo.location.X, 2) +
                                Math.Pow(location.Y - forwardTo.location.Y, 2));
        float angle = Utility.GetAngle(location, forwardTo.location);
        spriteBatch.Draw(Textures.BlackPixel, new Rectangle((int)location.X, (int)location.Y, (int)dist, 1), null, Color.Black, angle, Vector2.Zero, SpriteEffects.None, 0.9f);
    }

    // Draw Planet
    if (mouseOver)
    {
        Color c = new Color(color.R + 0.2f, color.G + 0.2f, color.B + 0.2f);
        spriteBatch.Draw(Textures.Planet, position, null, c, 0f, texOrigin, SpriteEffects.None, 0.5f);
    }
    else
        spriteBatch.Draw(Textures.Planet, position, null, color, 0f, texOrigin, SpriteEffects.None, 0.5f);

    // Draw overlay text
    Vector2 size = Textures.TextFont.MeasureString(resources.ToString());
    spriteBatch.DrawString(Textures.TextFont, resources.ToString(), new Vector2(position.X - size.X / 2, position.Y - size.Y / 2), Color.Black);
}

```

# Answer
To be honest, judging by the way you're drawing your sprites (which all look fine to me, by the way) it may be better to just switch to SpriteSortMode.Deferred and keep a constant layerDepth.

Doing this and keeping your layerDepths at 0 will produce the result you want.

So, a quick sample:

```
 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
 //Draw your line here

 //Draw your Planet(s) here with layerDepth set to 0

 spriteBatch.End();

```

If, for some reason, you desperately need to use layerDepth, I will take another look and update my answer for you.
> 1 votes

---
Tags: xna-4.0
---


title: XNA a Simple 2D Point Light

text:
# Question
Title: XNA a Simple 2D Point Light
I want to make a 2D Point Light in XNA, I was able to find some helpful information but it is too advance for me, since i know nothing about Shaders

http://www.soolstyle.com/2010/02/15/2d-deferred-lightning

So my best aproximation is use a texture and use alpha blending, but im not happy with this result.

So I was wondering, what is the most simple method to make a simple 2d point light? I'd rather code examples.

# Answer
> 1 votes
Well I'm afraid you are going to have to learn about Shaders. Catalin's XNA Blog is an excellent place to start and has a great tutorial on using them for lighting effects.

Shader Overview

Smooth Shadow Tutorial

# Answer
> 1 votes
If you want something a little easier, without having to know about everything going on under the hood, I've heard that Krypton is a pretty good 2D lighting engine for XNA.

Alternatively, there's the blog posts from Catalin Zima (here and here) as well as a pretty enlightening (minor pun intended) thread on the subject here.

Lastly, although it's not free for commercial use, the Sunburn Game Engine has support for 2D lighting, among many other things.

Otherwise, you're probably going to have to get your hands dirty and learn the shaders if you want to implement it yourself.

---
Tags: xna, 2d, shaders, lighting
---


# Question
Title: SDL and OpenGL resize window event question
So basically my question is im making a 2D game with openGL and SDL.

So what im trying to do is resize the game and have the openGL quad scale to the size my window becomes.

```
void CApp::OnResize(int w, int h){

textureWidth = (float)w;
textureHeight = (float)h;

SDLWindow::SetGLWindow(w, h, Surf_Display);

}

bool SDLWindow::SetGLWindow(int width, int height, SDL_Surface * Surf_Display)
{
if((Surf_Display = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_OPENGL | SDL_RESIZABLE)) == NULL) {
    return false;
    }

glClearColor(0, 0, 0, 0);
glClearDepth(1.0f);

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0, width, height, 0, 1, -1);

glMatrixMode(GL_MODELVIEW);

glEnable(GL_TEXTURE_2D);

glLoadIdentity();

return true;

```

}

So this works just fine. However while resizing the window, the image isnt scaling. It only scales after i release the mouse button. I am curious if i can scale the image at the same time?

# Answer
I'm not too familiar with SDL (more experience with GLUT), but I looked around a bit and found this post. The reply you're looking for is near the bottom by the user 'rip-off'.

It seems that SDL will halt while certain events are occuring, such as resizing the window. However, the program still has to draw, so there are portions of it which are still executing. rip-off suggests taking control of the portion which continues executing by passing your own event filter to `SDL_SetEventFilter`, and calling your `draw()` function each time the event is a resize.
> 2 votes

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


# Question
Title: An evaluation of game UI, based on certain usability criteria?
Is there a resource online which has made the effort to evaluate game user interfaces and estimate their usability (by genre)? (something like what Nielsen does). In-game reviews in magazines unfortunately do not always present an objective and quantifiable point, based on established heuristics or criteria

# Answer
> 1 votes
Short answer, no.

There however has been quite a bit of research into the topic (google "game ui evaluation").

The problem with this is its a very hard thing to measure, as a lot of it comes from the target audience of the game, or a players previous experience. Watch someone who's never gamed before playing a FPS and it'll be a world of difference to anyone who's gamed before.

That makes it near to impossible to pin down a universal set of criteria that makes a UI "good".

# Answer
> 0 votes
How helpful (or otherwise) the interface is tends to be a crucial aspect of the game, so it often falls within the domain of reviews. You might have some luck searching for "game name review interface" for instance.

Personally, I have a blog where I review a game occasionally, and I make a point of explaining what's wrong with the interface in detail when it's a big hindrance to my enjoyment of the game. I can't be the only one.

---
Tags: game-design, ui-design, user-experience
---


# Question
Title: How do I alert enemies to my presence when I make a sound?
I am working on a raycast-based 3D game, using Lua with Löve2D, and I am now currently working on the AI for the enemy. I want to make it like how *"DOOM"* did it, but I don't know how to handle how and when an enemy can hear your gunshot so they can "wake up" and become alert.

The map format is a simple grid, where 1 represents solid, and 0 represents open area. How did *"Wolfenstein"* and *"DOOM"* do it?

# Answer
I don't think those games used a realistic sound perception model. Probably the best approach is to evaluate the distance between source and hearer and distribute the probability of state change in the enemy.

A gaussian distribution would be perfect but heavy; you may divide the distance in tree ranges: near (always wake), far (never wake), middle (chance to wake).

In the latter case you can degrade the wake probablity from 1 at the "near" end and 0 to the "far" end; a sigma interpolation would be good but chances are that you will not notice the difference beteen sigma and linear interpolation... When you are in the "middle" range roll a dice at each shoot and see what happens.

To add a little thrill you may consider to make the waking up monster to scream so they may advise others slipping neighbors using the same model (play a scream sample would be nice)

The distance can be measured in terms of difference of positions or by casting a ray and summing up the "impedence" of each tile crossed (empty space:low impedence, concrete wall:high impedence). In the latter case the "impedence" can be seen as a lenght measure.

If your monsters don't go around when sleepping, you can consider to take the opposite way by precomputing the sensitive zones for each slepping monster (I suggest you to do this way).

If you want to precompute you may take all the tiles within the audible radius (the radius the moster can perceive with non-zero probability in empty space). For each tile you compute the distance and thus the probablity to wake up the moster standing in this tile.

If the number of tiles are small you may store these results; if not you can summarize these values using macrotiles: 2x2 3x3 and so on tiles wide areas. For each area you associate a chance value that is the average of the chances computed in that area.

The macrotile approach has the advantage to be simple to compute (4x4 macrotile coordinates are the current tile coordinates divided by four), but they may be inaccurate if a macrotile crosses a wall or when there is a large variance between the probablity values of the tiles that make up the macrotile.

If you think that the macrotiles are too rough than you have to tink about a clusterization algorithm and consequently to store those cluster in a more flexible way (a way that is a little harder to compute at run time)

Using a precomputing strategy you can use a better sound propagation model: using the "impedence" model I gave you, you can compute the shortest path and use the shortest path length as distance.

Immagine that the player is in a empty room and between him and the sleeping enemy there is just a single tile wide concrete soundproof wall, using the ray approach you will compute a large "impedence" instance but using the shortest path the sound will "travel" circumventing the wall, stretching a bit the path but strongly decreasing the impedance.
> 2 votes

# Answer
Just download Doom (or wolfenstein) source code and have a look at it. Basically it recursively walk into sectors near current player sector, check if there is monsters inside and wake them up.

there is some conditions : eg : if there is a closed door between sector dont go into it (if door is closed monster is not supposed to hear you)
> 1 votes

---
Tags: love2d
---


# Question
Title: Do you prototype mobile touch games on the desktop with mouse input? What tricks do you use?
So I've been prototyping games that if completed would be mobile apps most likely.

But, I'm developing them in XNA on the desktop because its the environment I like the most.

I know I could target windows phone and be testing the touch interface rapidly on that device but I don't own one and I imagine the build and deploy to the phone loop slows you down a bit.

Does anyone else prototype games that would eventually use a touch interface using mouse controls initially?

What tricks do you use to ensure that it will eventually translate well when you move to touch controls?

# Answer
> 1 votes
If you don't have a WP7 and only a desktop computer the best solution is to use the WP7 Emulator. You can find more informations here:

http://msdn.microsoft.com/en-us/library/ff402563(v=vs.92).aspx

If you have installed the latest version of XNA, the WP7 emulator is installed at the same time. If you don't have it, you can get it from here:

http://create.msdn.com/en-us/resources/downloads

You can also read this post on AppHub, someone else had had the same problem as you:

http://forums.create.msdn.com/forums/p/57651/352828.aspx

---
Tags: xna, mobile, touch, prototyping
---


title: Is GLUT obsolete?

text:
# Question
Title: Is GLUT obsolete?
A question was asked about good, up-to date OpenGL resources, one of the answers was a link to a tutorial about modern OpenGL programming.

The tutorial in question uses GLUT and GLEW, but I have read somewhere that GLUT is obsolete. Is that true?

# Answer
Is GLUT 3.7 out of date? Absolutely. You should *never* use it for *anything*.

However, FreeGLUT is perfectly fine to use. It is 100% backwards compatible with GLUT 3.7. FreeGLUT is a good utility to have when you need to slap together a quick and dirty program.
> 18 votes

# Answer
There is freeglut now :

http://en.wikipedia.org/wiki/Freeglut

freeglut
> 7 votes

# Answer
Even though the original GLUT is not in active development anymore, its still a good tool for its targeted domain, which is quick OpenGL testing and demos. It was *never* intended to be a framework for developing complex OpenGL programs.

from http://en.wikipedia.org/wiki/OpenGL\_Utility\_Toolkit

> The two aims of GLUT are to allow the creation of rather portable code between operating systems (GLUT is cross-platform) and to make learning OpenGL easier. Getting started with OpenGL programming while using GLUT often takes only a few lines of code and does not require knowledge of operating system–specific windowing APIs.

So no, if you use it for quick OpenGL tests, demos and learning, then it is *not* obsolete.
> 5 votes

# Answer
Yes GLUT is obsolete and not under developement since 1998 with the release of the 3.7 version.

From French Wikipedia:

> La bibliothèque GLUT n'est désormais plus en développement et s'est arrêtée à la version 3.7 en mai 1998.

http://fr.wikipedia.org/wiki/OpenGL\_utility\_toolkit

Edit:

Sorry for the french reference but i haven't find any date on the english wikipedia. The translation is:

> The GLUT library is no longer in development and stopped at version 3.7 in May 1998.

And the link to the english wikipedia:

http://en.wikipedia.org/wiki/OpenGL\_Utility\_Toolkit
> 3 votes

# Answer
You should have a look at GLFW: http://www.glfw.org/

It's a very easy to use cross-platform API that is still in development and has good documentation!

All it does, is to create an OpenGL context and provide means to get input (+ some extra features like threading)
> 3 votes

---
Tags: opengl, glut
---


title: Choosing a server for a PVP game

text:
# Question
Title: Choosing a server for a PVP game
So I am starting a game with a friend as a small project, and we are considering what game servers would we need.

Firstly, the game is a multiplayer(player vs player) game, for example, like an online chess game. However it is real time, so the latency cannot be too high. The players basically take turns, but in a real time fashion. The platform is going to be Android (and perhaps extend to iOS in the future)

The server would need to synchronize the players' moves to each other devices.

I don't really need anything large scale and I am thinking of using PHP since the volume of data isn't really that big, this is like a web-based game with a requirement of a slightly lower latency.

What would be the advantages and disadvantage of using Apache + PHP for a game like this?

If that seems to be a bad choice, I would be grateful if you can share your experience with me. Thank you.

(We are both programmers and we are familiar with Java C++ Obj-C Apache PHP Tomcat JSP Javascript)

# Answer
> 4 votes
A normal PHP/Apache setup is stateless, and that sucks for a game server since it forces you to use the database for basically everything. If you can handle the extra centiseconds it may be a working solution, but server performance is going to be pretty bad.

You could take a conventional language like C++ or Java and write the gameserver in that, that is potentially the fastest option.

Alternately, especially if you intent to use HTTP anyway, you could use Node.js. Almost as easy as PHP, faster, and most important to keep you sane, allows you to share data between requests without going through the database.

# Answer
> 7 votes
PHP/Apache theoretically could do it. BUT - they are designed for making active webpages and will most *probably* not be the best tool for the job.

You would be probably better off writing a server in the language of your choice - out of your familiarities, I would suggest Java or C++. Use the relevant sockets library, and code it directly.

If it is a real time, though turn based game, I would use MySQL as a datastore, as it can interact with Java or C++ (or PHP if that is what you eventually decided to use). Make your server application Fork for each connection, read the current state of the game off MySQL and apply the rules (storing changes to the MySQL datastore, so any other players who connect will see the relevant data), provide accept the players input and output etc. This would also minimize the problems related to multithreading. However, using Forks as well as C++ (or, to a lesser extent, Java) will ensure scalability.

I will warn you - I have limited experience in the area, so you can take my answer for what it is worth.

---
Tags: server
---


# Question
Title: Is there a sprite sheet creator that satisfies these requirements?
I'm looking for a decent sprite sheet packer.

Features:

* Command line interface for Linux.
* Effective packing algorithm.
* Configurable padding between sprites in the sheet.
* Configurable fixed sprite sheet size (i.e. pack to many sheets).
* Duplicate sprites detection, preferably with some tolerance to allow for FP errors when packing rasterized vector images.
* Auto-crop by transparent pixels (i.e. sprite is cropped when packed and it is correctly reflected in the data).
* Support for web-graphics formats (jpg, png at least).
* Reasonable data output format (sprite sheet indes).

Paid software is okay as long as the price is reasonable.

# Answer
My TexturePacker currently supports Ubuntu. What Linux would you need? The command line works too - and it has all the features you need.
> 6 votes

# Answer
Have you checked TexturePacker? It has a considerable list of features and at first sight seems to cover all or most of the features you listed. For instance, it seems to work under linux and has a command line tool that you can plug into your build process. Also seems to be capable of detecting and handling duplicates.

As for the price, it states on the front page that most features are available for free. If you need one of the features that aren't available, you can request a free license if you're a blogger or a framework developer. Otherwise the full price at the moment seems to be 25$ for TexturePacker Pro.
> 3 votes

# Answer
John Ratcliff has a code snippet to do this, and it's hosted on Google Code. You'd still have to write the command-line code around it, though.
> 1 votes

# Answer
TexturePacker does all of the things you're looking for. There's a Linux version but according to this (rather old) post, the command-line interface isn't working yet. I don't know if that has been fixed in the mean time or if it's still an issue.
> 0 votes

---
Tags: graphics, tools, linux, spritesheet
---


# Question
Title: Simulating a 3D body with a skeleton in iOS
I would like to make an iOS application that simulates a 3D body with joints and bones, but I am not sure how to do that. The aim of the app is that you can move its arms around and throw it around (x and y axis only). The app should need to:

* import a 3D model with bones and joints (in which format to import this kind of model?)
* import the collision boxes for each part of the body (I would probably need ragdoll?)
* detect a collision when you touch a collision box of the ragdoll
* apply inverse kinematics (IK) on the body when you move your finger (do I need IK or can this be done any other way? Apply a force on a part of the ragdoll?)
* apply physics on the ragdoll

How could I achieve these tasks? And are there any libraries that support these things? What is the difference in a ragdoll with and without inverse kinematics?

# Answer
**IK** IK can be described in terms of it's opposite, forward kinematics. IK is perfect for animation. Why? Because any task should be driven by it's goal(s), and that is exactly what IK does. While forward kinematics requires you to position each joint in a limb sequentially, from the base to the tip, in order to get the exact tip placement and orientation you want, IK allows you specify the position of the tip (say a fingertip) and get the sequence of transformations you need on all the joints involved in that tip placement (shoulder, elbow, wrist, finger). This is why IK came about, otherwise you'd have to use FK with trial and error, or store a vast database of precalculated, quantised positions that map to the exact transformations required to get that tip position -- plain silly. In answer to your question then, yes: this is the only really sensible way to go about positioning a character in various poses.

*(EDIT)* IK is typically used for animation. That means physics don't affect IK motion, because they can't be allowed to or they would interfere with the IK solver's logic (there may be exceptions to this). In physics engines, there are two types of bodies: kinematic and physics-driven. Kinematic means "transform this object in the way I say, ignoring the limitations of traditional physics". Grab one of the boxes in this online demo to see what I mean. You can apply theoretically infinite force with that kinematic object under your mouse. Generally speaking, this is what IK does in physics engines. "What happens when an unstoppable force hits an immovable object?" Well, one has to give -- either the specified animation, or the physics. In this case, the physics.

So your choices depend on what you want to achieve. If the character is first posed using IK (in "frozen" state), and then physics simulation is activated, no problem -- write an IK solver, let it do it's thing with user input, and then turn the physics on to see what happens to the character... it now becomes a ragdoll, from the original pose you set. If you want, however, to have kinematic motion, such as the character standing up (kinematic) while his arms are swinging freely in realtime (pure physics), or the character falling while waving at the user, you will need both kinematic and physical bodies as part of your ragdoll in the physics simulation; you will also likely need to lock joints on kinematic limbs so that they stay at some fixed angle (that is not actual kinematics though). Lastly (the hardest option), if you want to be able to position body parts as the character is eg. falling through space, well, you're going to need kinematic body parts that are positionable on the fly using IK, while other parts of the body might be left as physics-driven, thus floppy/ragdoll-like. In other words, IK can be applied in a physics engine, but you need kinematic bodies (+joints?) to do this, and you will need to make sure the limbs stay rigid after you've positioned them this way, or else gravity will take over. Fortunately, most if not all physics engines support kinematic bodies.

Lastly just to add -- the reason you can't just tug an arm in pure physics mode /ragdoll mode and expect thing to work is that this applies *force* to the whole connected body, ultimately. You would have great difficulty in positioning say, just one arm, without the rest of the body falling all over the place. So IK is the answer, since it will usually move just that limb. If you let the IK chain length go all the way down to the torso, then the torso will also bend to accommodate the hand position.

**Collision Boxes** Transformations of 3D objects are the first, and larger matter you'd need to achieve here. For that you'll need to be familiar with vector math, matrix transformations, quaternions. Collision detection on transformed planes is really not too difficult, the Graphics Gems books have tons of these, and you can find tons more for free here; vector math is usually enough for this.

**Model Formats** I would suggest Collada or FBX, as they both support a good subset of the most commonly used features. Tou will need to locate the spec online for either one. AFAIK, the FBX spec is not that clear. I'm guessing Collada is much better in that regard. You will also need to write a parser to import the files into your application.

**Physics** You'd need to integrate something like Bullet, PhysX, ODE or whatever. Depends on what sort of physics you need, overall.

**The Conclusion** To avoid implementing much of the above from scratch in Objective-C, use Unity3D. It runs on iOS, imports a range of different model formats, and instead of doing everything yourself (which I don't recommend!), you have access in Unity to your models' bone structures and so on and can manipulate these as you wish, while getting all your 3D rendering and physics requirements sorted as well. For collision boxes in Unity, I believe the integrated Nvidia PhysX may accommodate that, otherwise you could bring them in as part of your actual model, on a separate layer or something of that sort. You'd need to ask further questions about your needs over at the Unity forums, and do a bit of browsing there as well for IK stuff, but I think this will fulfill your needs.

**Unity links**

The big guy over at the Unity community for IK stuff is Rune Skovbo Johanssen. He's done some really awesome stuff with this, that you can in fact pick up in the Unity store IIRC.
> 4 votes

# Answer
2003 walkthrough of Hitman ragdolls.

Bullet engine I think handles ragdolls as well. Not much point writing it all yourself unless you are a real propellerhead.
> 1 votes

---
Tags: 3d, ios, skeletal-animation
---


# Question
Title: Determine Resulting Angle of Wall Collision
So I have an object moving in a direction towards a fixed horizontal or vertical wall. How do I compute the angle that the object should bounce off at? The object can approach the wall at an arbitrary angle.

# Answer
> 18 votes
If you know the wall's normal vector and have an incoming direction for the object, then what you want is the reflection of a vector across a plane.

If **n** is a normalized vector, and **v** is the *incoming* direction, then what you want is −(2(**n** · **v**) **n****v**). The minus sign accounts for the fact that the reflection formula doesn't actually reverse the direction, as an object's velocity would reverse.

This answer is given in terms of vector math, not an angle, because that's usually preferable if you don't have an explicit reason to use an angle. Note that if you must talk about angles, the angle of reflection is equal to the angle of incidence. If the angle is measured from the normal, the outgoing angle is the negation of the incoming angle; if the angle is measured from the wall, then it's the complement of the incoming angle.

# Answer
> 14 votes
You didn't specify if it was a 2D or 3D game. But if it's a 2D game and your walls are guaranteed to be horizontal or vertical and you just want to bounce the object off them, there's a much easier way than having to deal with reflections.

Simply negate the X-component of the object's velocity when hitting a vertical wall, or the Y-component of the object's velocity when hitting an horizontal wall. Example:

```
if( /* hit vertical wall */ )
{
    object.velocity.x *= -1;
}
if( /* hit horizontal wall */ )
{
    object.velocity.y *= -1;
}

```

But if you really care about knowing the angle, then in general terms, the angle of reflection is the same as the angle of incidence. This angle is measured in relation to the wall's normal. Here's a picture that should make it clear:

In case you ever need to handle this for arbitrary walls, you'll need to look into how to reflect a vector. It's really just a small formula that takes the wall's normal and the incidence vector, and returns the reflected vector for you. Here's the formula XNA uses:

```
public static Vector3 Reflect(Vector3 vector, Vector3 normal)
{
    return vector - 2 * Vector3.Dot(vector, normal) * normal;
}

```

And for 2D you could just do:

```
public static Vector2 Reflect(Vector2 vector, Vector2 normal)
{
    return vector - 2 * Vector2.Dot(vector, normal) * normal;
}

```

# Answer
> 2 votes
This is just about reflecting a vector along the walls normal vector.

http://www.3dkingdoms.com/weekly/weekly.php?a=2

---
Tags: mathematics, physics
---


# Question
Title: How do I avoid losing prediction responsiveness due to client interpolation?
In my online game, I am using client prediction and client interpolation to give the illusion of responsiveness over a networked connection.

The **client prediction** applies inputs that haven't yet been acknowledged by the server to incoming server states. When the input *is* acknowledged, the client's entity will already be in the final position.

The **client interpolation** works by buffering world snapshots and rendering the entities 100 ms in the past. While new snapshots arrive within the next 100 ms, there will always be valid data to interpolate between.

My problem is that the responsiveness gained from client prediction is lost due to client interpolation. The client's local inputs are applied to *incoming* server states. However, those incoming states aren't actually rendered on the client until 100 ms later, due to the client interpolation. The result is that there is always a 100 ms lag between pressing a key and rendering the change to the screen.

How can I get the best of both worlds, rendering entities in the past, but rendering the client's inputs instantly?

# Answer
> 9 votes
The problem was a misunderstanding about what client interpolation is for. Only entities that *aren't* controlled by the player should be interpolated. Player controlled entities always update themselves using the freshest data available from the server, since we want to simulate them as close to real-time as possible.

That also makes clear what client prediction does. If player controlled entities only use the latest data, then how can they be rendered smoothly? Well, since we control that player, we can extrapolate what its next position will be, most of the time with perfect results. Then just render positions between the server-received position and the predicted position.

However, there is still the issue of making the interpolated entities mingle with the player controlled entities during its update step. I solved this by temporarily placing the player controlled entity into the snapshot that is currently being rendered to the screen (from 100 ms ago). The inputs are applied in the context of that snapshot, so the player looks like it's interacting with the interpolated entities. After the simulation is done, the player is removed from the old snapshot.

With all of that in place, it's looking good!

---
Tags: networking, client-server, movement-prediction
---


# Question
Title: How can I know how big my game "world" should be?
here is the world map (randomly generated) for a game I'm making: The green rectangle corresponds to the size of one screen. Each pixel represents 3x3 tiles in my game, this makes the whole map be roughly 7,9 km² (2,3 x 2,3). How can I assess if the game is too big or too small?

# Answer
By playing it!

Whether a game world is too big or small depends on a countless number of factors, including:

* How big the player is
* How fast the player moves
* How many other characters there are
* Whether the game is multiplayer
* The hardware capabilities of the target platform
* Your target audience
* How the save mechanism works (can I pick up where I left off, or from checkpoints?)

Obviously, I could go on and on into infinity. And hence my conclusion that there probably is not going to be a very effective analytic means of determining how big a game world is; instead, you should play it and determine for yourself what feels right. When you have a good idea of what this size is, you should start asking others to play and see what they think.

Once your game is in the hands of many people, you can start collecting statistics about where people travel in the game. If most people tend to stay within a relatively small portion of your world, you may very well have a world that is too large. Conversely, if most players have visited every corner of your world, it may be too small.

Edit:

Another idea is to play for a while (say, 10 minutes) and see how much ground you cover. Decide how much time you expect the average person to play. Determine how much, on average, a player should revisit a given area. With this information, you should be able to come up with a good estimate of how big your world should be. All you're really doing here is creating some rough goals and tweaking some parameters to meet them. You should still continue tweaking these parameters as you get feedback from others.
> 19 votes

# Answer
I approach games from the opposite point of view; instead of "how big should my world be?", I ask: "how small can my world be?"

If your game doesn't absolutely require a particular bit of space -- if that space isn't accomplishing something useful (thematically, emotionally, or in terms of game mechanics), then I say that that space should be removed as it is diluting and therefore harming your game.

This does, of course, require that you know what your game is about on several different levels, which some developers never consciously think about. But it's worth knowing; it's much easier to know how to improve a game (and not only in terms of its game space) when you understand the game's core.
> 11 votes

# Answer
There is a good answer for the question if you arrange your game under the premise that you want to optimize it's usability for human access.

But sometimes the fun comes from beeing initially overwhelmed so apply the principle with care.

Get your scope and the taxonomy. Scope first, i use the example of a chess game: A user chooses a piece to move (or a role in your game). The role now determines the scope of his actions. A pawn can only move so far in the game so the world is pretty big from a player using only pawns. This is the smallest scope of your game.

Your largest scope will be the queens scope. You should be able to relate your largest scope and your smallest scope by shared interactions. The queen shares movement principles and movement-space with pawns. Your average game might share movement, resources of fighting principles that could be used to deduct scope. The pawns scope will be our basic magnitude of scope.

Keep in mind that the average human brain is able to keep a total of 5 to 8 items available in the short term memory. Basicly your gameworld should reflect that everywhere. Not more than 8 distinct locations in a town, not more than 8 kingdoms, not more than 8 item categories at once,etc... That also applies to spatial movement. Depending on your world it might not always be trivial for a designer to get the information on what the user will actually store in his/her short term memory.

No route should be more than 5- 8 user interactions long. If your game gets more complex than tiles/travel clicks you might want to think in other measures like "no more than 5-8 landmarks to travel" instead of 5-8 turns. You will find that this number is actually lower for alot of modern games. The Witcher 2 for example places most of the quests in the close proximity to just a few landmarks per world.

Create a tree and place all your spatial locations in a taxonomy of your choice where no element has more than 4-7 siblings. For example you have 6 continents with 6 large countries with 5 cities with 6 shops.

Each sibling and the parent´should be reachable by travel within 5-8 distinct movement interactions. (i.e. walk to that large tree, then turn right to the street until you see the big swan. Enter the golden door, first door on the left). The pawn needs to travel one unit of scope at a time where the queen would be able to travel most of the distance in a few turns. That's not only the size of your gameworld but also a very nice progression and reward arc possibility for your users.

It's totally feasible to change movement interactions when travelling in another magnitude of your spatial locations. Simple example: Travel by ship, foot, aeroplane.
> 3 votes

# Answer
Similarly to Trevor's answer, perhaps you could work backwards, starting from the question: "How big does my world need to be in order to accommodate X, Y and Z?"

X, Y and Z here are of course your game's contents. They can be cities, or distinct areas, or targets, and so on. Unfortunately a lot of work may need to be done before you can reach even having a list of X-Z; you may even end up with A-Z and still not be finished! But once you know what your game is going to contain, you might then be able to make the world "just big enough", possibly with enough "breathing space" for some DLC or updates.

I look forward to finding out how you eventually decide to proceed. Good luck!
> 3 votes

---
Tags: game-design, game-mechanics, maps, world-design
---


title: Calculate vector in local space

text:
# Question
Title: Calculate vector in local space
I have a vector (8,5). It's origin is at (10,9)

I can calculate a perpendicular like so:

```
MyPerpendicularVector.x = -MyVector.y
MyPerpendicularVector.y = MyVector.x

```

Given that I now know these two axis, how do I make these axis (made up of my new vectors) now my "local" axis? for example I want to plot a vector (2,3) on the "local" axis but I have no idea how to calculate it in relation to the "global" axis

Image of the problem here:

# Answer
I'll start by saying that your vector cannot technically have an 'origin.' A vector is only a representation of a direction.

It's a bit unclear which coordinate system your vector (2,3) is defined in. I'm going to assume from your image that it is defined in your local coordinate system and you're trying to rotate it into your global coordinate system.

For a vector, all that you have to do is rotate it by the angle difference between your local and global coordinate systems. You can calculate this by taking the inverse cosine of the dot product of your two x-axes:

```
angle = cos^-1((2,3) * (1,0))

```

Then to rotate the vector you would use a simple 2D rotation matrix, which involves sines and cosines:

```
rotatedv = (x*cos(angle) - y*sin(angle), x*sin(angle) + y*cos(angle))

```

And this will be your vector in your global coordinates.

I should also mention that if your local coordinate system is *centered* at a different point than your global coordinate system (as it seems to be in your image), then you will need to take that translation into account *only for points*, not vectors.
> 5 votes

# Answer
What ktodisco says is right, but the way I'd do it would be with matrices. Essentially, your coordinate system is expressed as xI+yJ+K. In the case of the origin/standard system, that represents the matrix equation:

http://mathurl.com/7hoegjb

likewise, for your transformed coordinate system with origin (x0,y0) and direction (a,b), the matrix would correspond to:

http://mathurl.com/6n3vevw

So to convert between systems, set both of the matrices equal to each other. All you need to calculate is A^(-1)\*Vector and you're done.

The same thing can be done in three dimensions.

Also note that with this way, each unit in the alternate coordinate system would be the length of (8,3) in the normal coordinate system. To have a point at (2,3) in the alternate system be where you drew it, you'd have to normalize the vector first. Then the transform matrix.

(I'd also like to point out that in ktodisco's post, you would want the atan2 or atanfull function instead of the inverse cosine function.)
> 4 votes

---
Tags: vector
---


# Question
Title: Spherical fractal noise generator in shader
I have a growing sphere in space, and I thought of having a procedural generated texture over it. Since it is growing, I thought a fractal would be a great choice, because more details would be visible the larger the sphere get (and I could mess with some parameter over time to have it animated).

A quick Mandelbrot implementation in GLSL showed it would be too expensive to have it in the devices I am targeting; also, I don't know how to map a cool looking fractal over complex plane onto a sphere without distortions (I expect the players to fly around this sphere in every direction, so there should be no "glued" edges or collapsed points), neither I have the background to devise/project a fractal over the spherical surface myself (probably was done before, but I could not find).

So weighting the requisites of the procedural texture:

* Fast to run, for low-end/mobile GPU;
* Over a spherical surface domain;
* Growing in details with growing in size;
* Possible to animate (BONUS);
* Cool looking (of course);

then I thought it might be impossible within the constraints. But since I am no expert in this fractal thing, I thought I could ask it here first before scraping out the idea.

Maybe it is really not a fractal I need, and there is some other kind of noise with growing details I could use. Do you know of such noise generation procedure?

Do you know of any noise generator with uniform distribution over spherical sufaces, or any fractals whose domain is a sphere?

Can you suggest any alternatives for my situation?

# Answer
> 4 votes
A very common way of generating noise on the surface of a sphere is to use 3D Perlin noise. I'm not sure how feasible it is to evaluate 3D Perlin noise in real-time on a low-end GPU, though. It is possible to implement it directly in a pixel shader, as this article shows. It's also possible to precompute it and store it in a volume texture, although this will take a lot of memory for a reasonably high-res texture.

Perlin noise is band-limited (its features are all about the same size in 3D space), so it is not in itself fractal. However, if the sphere grows larger then the noise features will get smaller relative to the sphere, which may give you the effect of increasing detail that you want.

Another way to get detail is to sum several Perlin noise functions at different scales and amplitudes to create a kind of fractal noise. In this context, each noise function in the sum is called an "octave". The way this is normally done, the smaller-scale octaves have much lower amplitudes than the larger-scale ones, so if you zoom in it will become featureless. To fix this you might try increasing the amplitudes as you zoom in, while repeatedly fading out the largest octave and fading in a smaller octave to maintain a constant amount of visible detail.

---
Tags: textures, shaders, procedural-generation, fractal
---


title: DirectX -- Best version to develop for?

text:
# Question
Title: DirectX -- Best version to develop for?
> **Possible Duplicate:**
> learning Direct3D 9, 10 or 11?

I'm just starting to learn DirectX, and I was wondering what the best version would be best to develop for. I'm trying DirectX 9 right now, but was wondering if I should use 10 or 11... Which version is the most commonly used version for games nowadays? I want to be able to play my game on most versions of windows... Is DirectX 9 still used a lot now?

# Answer
> 4 votes
I like 10, because my laptop supports it, and the 590 in my desktop doesn't like the airplane charger.

9 is good because that's what the PS3 and XBOX 360 support.

11 is freakin' amazing because of the features it offers (hull shaders induce a Pavlovian response).

However, this is really a "target audience" question. If you're writing a paper, who comprises your target audience? Do you have to explain "pixel" or "floating point underflow?" Do you want to run on OLPC devices, or Sager custom laptops?

The Steam stats are a good start, but there are a few things to consider:

1. What hardware do you have available **right now** to work on? If your PC is ten years old, it may be a good benchmark for what your clients will have, and actually *writing and finishing a project* is the biggest hurdle every game developer has to conquer.
2. How long do you think it'll take to finish the game? Multiply that by four, and guess what most COTS PCs will have in terms of video capability at that point.

I've read that big game shops target next gen hardware for everything they do, and provide the ability to dial it back if necessary. However, building a game from scratch that targets multiple back-ends (DX9,DX10.\*,DX11,OpenGL2/3/blah, OpenGL ES blah) is a huge task - in fact, some companies have built their business around it (Unreal).

DX10 is pretty safe because most hardware supports it and it provides a *lot* of capabilities and performance that DX9 doesn't, and a dev cycle of less than year is impractical if you're married or have a real job, so that's what I'm working with.

Good luck!

# Answer
> 1 votes
I'd go for either 9 or 11 (with feature levels). 9 is for the case where you know that you still need to run on Windows XP; if you're happy to ditch XP on the other hand, then 11 will run on any device that can run 9 or 10, and feature levels will give you legacy hardware compatibility.

# Answer
> 1 votes
**The goal is to make your games look great on the lowest (common) target**, which is often the average consumer, I would make your development aim at making your game look great on Direct X 9, and then when you have that working well, add support for all the fancy features in Direct X 10/11. My inspiration for this opinion is the fact that there is still a major portion of the consumer market still gaming on Windows XP (Direct X 9 Maximum), a large portion on low cost graphics cards, and Xbox 360 and PS3 only offer Direct X 9 support \[This is kind of a lie, Xbox 360 supports Direct X 10 features\].

---
Tags: c++, graphics, directx
---


title: 3D Bone Animation API in C#

text:
# Question
Title: 3D Bone Animation API in C#
i have been looking for 3d Bone Animation for plain C# (to be used with Sharpdx or Slimdx) but i did not find anything !!! I just find some for XNA.

Any Suggestions! Accept c++ suggestions also

# Answer
> 2 votes
I think Ogre might have what you are looking for, check out the Skeleton class, and the section on Skeletal animation in the manual.

I'm not sure if it goes to as low a level as you like, but seeing as Ogre has its own .animation and .skeleton formats, I think it does.

However Ogre is for C++, so what you would want to use is Mogre which is the official port of Ogre to C#. I use it, and it is great.

A slimmer solution might be Cal3D, which is an open source bone animation api, which is independent of any graphics API, unlike Ogre. It is also in C++.

Irrlicht is another alternative, it is a quite popular open source C++ graphics engine, which seems to have bone-morphing capabilities.

Lastly, I know this is not exactly what you are looking for, but Blender has some awesome animation capabilities, and is open source. There was also a recent overhaul of its animation API, so it is much cleaner and more usable. I have not done any scripting or development of Blender, but I know that its scripting is primarily in python. However, in the API Overview, it mentions that more advanced modules (which I think includes animation) is programmed using C++. (The link I provide here may not be exactly accurate, the site seems to be down right now, so I will find and post the correct link later if you are interested)

Even if you dont intend to do scripting in Blender, studying its animation techniques would certainly help you.

Good luck! :)

**EDIT:** Looks like this is pretty much ignored, but user Erwin Coumans mentioned in a different question that AnimKit is also a good one.

> AnimKit is a small basic open source skeletal animation system with skinning, that loads the data straight from a Blender .blend file. It uses the liberal ZLib license, like Bullet. The code is portable, it works under Windows, Linux, OSX and some iOS and Android samples are planned.

See http://code.google.com/p/gamekit/downloads/detail?name=animkit\_src\_r1020.zip and http://gamekit.org/forum/viewtopic.php?f=9&t=144

---
Tags: c#, animation
---


# Question
Title: Sprite-sheets vs Sprites/MovieClips in Flash
We create 3D models in Maya2011 and create PNGs and import the bunch into Adobe Flash CS5 to create a sprite.

I read somewhere that sprite-sheets can save space over making the sprite in Flash. How big of a difference does it make? None of our art team has experience in creating sprite-sheets. Is it worth learning it and adopt that workflow? How difficult is it? How much of a difference in file-size can we achieve?

Keeping size constraints apart, I see a draw back using sprite-sheets: I wont be able to create multiple combinations of loop animations using the same set of images. I can even create multiple sprites within the same SWF with our current workflow.

# Answer
> 3 votes
You can save some memory by using sprite-sheets, because a good packer will ignore transparent pixels around a sprite and place the sprites as close together as possible. The benefit in file size is really marginal though.

The main reason why sprite-sheets are being used is to make the best use of power-of-two textures and to reduce draw-calls. Both things that are relevant if you use a 3D API like OpenGL or the new 3D API for flash. If you're planning to port the game to another platform (eg. iOS, Android or similar), then having sprite-sheets might come in handy, because these systems *will* benefit from the sprite-sheet approach.

In case of `MovieClips`, your approach of single images is going to be simpler, because there's no way to directly use sprite-sheets in flash, unless you create your game with an engine like flixel which directly supports sprite-sheets.

So in short: If you're sticking with flash and would like to animate your sprites using the flash timeline, then single images is the way to go. Using sprite-sheets would mean a paradigm change in how you animate things and you would have to write some code to parse the sprite-sheet information and for animation. It's up to you to decide if that's worth it. If it's for the file-size saving alone, I would certainly *not* do it.

# Answer
> 2 votes
The sprite sheet concept is to have a single image loaded into memory and then blit (copy) smaller portions of the image. Implementation is application dependent, but one would typically load a script file of some sort which lists the tile sprite size and offset for each "frame" of animation, and that list order can be arbitrary. So you don't create loops of animation frames, you create scripts of pixel offsets.

One possible way to do this is: sprite specification is 10px square, you have 100 frames, then you might create a 10 x 1000 px image, and reference the frames by the y-offset.

Frame 0 : x=1, y=(0 * 10) + 1 Frame 1 : x=1, y=(1 * 10) + 1 etc. (if I messed up the math a little, the concept is still sound)

You can reuse the single image to form arbitrary animations by feeding a script to a function which copies the sprites:

animation 1( 1,2,3,4,5,6,7,8) animation 2(2,4,6,8,1,3,5,7)

Is this a WIN over flash sprites? No idea. But you *certainly can* have multiple sets of animations with a single sprite sheet.

There is a game development stack exchange where you might get a true hacker's opinion.

---
Tags: flash, sprites
---