Questions tagged [c#]

C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.

Filter by
Sorted by
Tagged with
71 votes
10 answers
203k views

In Unity, how do I correctly implement the singleton pattern?

I have seen several videos and tutorials for creating singleton objects in Unity, mainly for a GameManager, that appear to use different approaches to instantiating ...
user avatar
  • 1,369
68 votes
7 answers
7k views

What are typical pitfalls when writing games with a managed Language like C#? [closed]

What pitfalls did you encounter when writing games for the PC with a managed Language like C# and how did you solve them?
user avatar
66 votes
6 answers
19k views

How do bullets work in video games?

I came across this question when I was designing a video game in C#. If we consider games such as Battlefield or Call of Duty, hundreds or even thousands of bullets are flying at the same time. ...
user avatar
  • 773
59 votes
7 answers
10k views

What are the dangers of self-teaching game development? [closed]

I am about to embark upon a journey into game development. Following answers to my last question, I will be using C# and XNA. However, I don't personally know any other game developers and I don't ...
user avatar
  • 1,006
59 votes
1 answer
17k views

Using component based entity system practically

Yesterday, I've read a presentation from GDC Canada about Attribute / Behaviour entity system and I think it's pretty great. However, I'm not sure how to use it practially, not just in theory. First ...
user avatar
  • 703
55 votes
9 answers
19k views

How are deterministic games possible in the face of floating-point non-determinism?

To make a game like an RTS networked, I've seen a number of answers here suggest to make the game completely deterministic; then you only have to transfer the users' actions to each other, and lag ...
user avatar
51 votes
7 answers
10k views

2D Platformer AABB collision problems

I have a problem with AABB collision resolution. I resolve AABB intersection by resolving the X axis first, then the Y axis. This is done to prevent this bug: http://i.stack.imgur.com/NLg4j.png The ...
user avatar
50 votes
4 answers
16k views

How can I completely hide and protect strings from the player in Unity?

I have been using Unity to create a 2D game which will be completely offline (which is the problem), the game-play needs you to enter certain strings at certain levels and Unity compiles to DLLs, ...
user avatar
38 votes
3 answers
33k views

What is the standard C# / Windows Forms game loop?

When writing a game in C# that uses plain-old Windows Forms and some graphics API wrapper like SlimDX or OpenTK, how should the main game loop be structured? A canonical Windows Forms application has ...
user avatar
38 votes
1 answer
3k views

Why is this beat detection code failing to register some beats properly?

I made this SoundAnalyzer class to detect beats in songs: ...
user avatar
  • 626
34 votes
11 answers
81k views

In Pong, how do you calculate the ball's direction when it bounces off the paddle?

I'm trying to wrap my head around this very Hello World-y problem in game development. I've created a TicTacToe game in XNA so I guess the next step would be a Breakout clone. Keep in mind that I ...
user avatar
33 votes
4 answers
5k views

Why does my object move faster at 45° than at 90°?

I have objects in my game that move faster at 45 degrees then at 90 degrees. Each object has: Point (x,y) position Vector2D (x,y) direction Int speed And what I do during an update, is that a new ...
user avatar
  • 465
31 votes
5 answers
7k views

Use an instance or a class for game resources (wood,iron,gold)

So I'm making a game where you can send ships to locations to sell or buy resources like wood, iron, gold, etc. Now I was wondering how the resources should be created in de game. I came up with 2 ...
user avatar
31 votes
3 answers
13k views

How to properly implement message handling in a component based entity system?

I am implementing an entity system variant that has: An Entity class that is little more than an ID that binds components together A bunch of component classes that have no "component logic", only ...
user avatar
  • 431
30 votes
2 answers
69k views

How to correctly draw a line in Unity

I'm working on a game which requires me to draw a few lines from a single point that is more formally said Given point A with coordinates x,y I draw n lines where the i-th line has the coordinates ...
user avatar
30 votes
5 answers
8k views

Simulating pressure in a grid based liquid simulation

I have a 2D grid based water system in my XNA game, we have a method using cellular automata to simulate water falling and spreading. Example of water flowing down a slope: Each tile can contain a ...
user avatar
  • 1,039
29 votes
4 answers
15k views

How can I build a game in Unity with minimum/no use of the visual editor?

I'd like to write a game completely in C#. In my search for an engine, I found Unity3D, but all the tutorials and documentation are speaking about a visual editor and the Unity IDE in which you click ...
user avatar
  • 561
29 votes
1 answer
5k views

What is the standard practice for animating motion -- move character or not move character?

I've downloaded a bunch of (free) 3d warriors with animations. I've noticed for about 25% of them, the 'run' animation physically moves the character forward in the z direction. For the other 75%, the ...
user avatar
29 votes
6 answers
13k views

A way to store potentially infinite 2D map data?

I have a 2D platformer that currently can handle chunks with 100 by 100 tiles, with the chunk coordinates are stored as longs, so this is the only limit of maps (maxlong*maxlong). All entity positions ...
user avatar
  • 393
29 votes
1 answer
17k views

Orienting a model to face a target

I have two objects (target and player), both have Position (Vector3) and Rotation (Quaternion). I want the target to rotate and be facing right at the player. The target, when it shoots something ...
user avatar
  • 455
27 votes
5 answers
32k views

Is C# viable for a real-time game server? [closed]

Most of the question is in the title. Basically, I'm starting to develop a 2D multiplayer action game. The client is (probably) going to be in XNA, and I thought I'd ask here about whether it's a ...
user avatar
  • 1,126
27 votes
8 answers
11k views

How can I avoid tight script coupling in Unity?

Some time ago I started working with Unity and I still struggle with the issue of tightly coupled scripts. How can I structure my code to avoid this problem? For example: I want to have health and ...
user avatar
  • 785
26 votes
3 answers
28k views

What's the difference between UnityEngine.Random and System.Random?

What's the different between this int randomNumber = UnityEngine.Random.Range(0, 10); and this ...
user avatar
25 votes
1 answer
5k views

Why should I always consider creating and using object pools instead of instantiating the new object on the fly?

I have read about this pattern several times (from a best-practices perspective): Memory Allocation: Instead of instantiating the new object on the fly, always consider creating and using object ...
user avatar
25 votes
2 answers
48k views

Difference between unity scripting backend IL2CPP and Mono2x

IL2CPP is a Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. Note - IL2CPP is only available when building for the following ...
user avatar
24 votes
7 answers
2k views

Multithreading 2D gravity calculations

I'm building a space exploration game and I've currently started working on gravity ( In C# with XNA). The gravity still needs tweaking, but before I can do that, I need to address some performance ...
user avatar
  • 405
24 votes
6 answers
19k views

How do dialog trees work?

That is, what is connected to what and how to move between lines of speech when a sub-conversation ends? If you have any examples of a basic dialog tree in C#, please post them.
user avatar
  • 1,379
24 votes
3 answers
13k views

Is there a faster sine function?

I am working on generation 3d perlin noise. The C# Math library seems like overkill for what I need since most of its functions use double percision. I use Math.Sin() in several places to generate the ...
user avatar
  • 243
23 votes
7 answers
7k views

Is C++ being replaced by C# in industry games?

In industry games I mean like Quake, CoD etc.
user avatar
  • 341
23 votes
3 answers
4k views

Best way to store game-wide variables

I have an options screen for things like difficulty, resolution, full-screen, etc., but I'm struggling to find the "best" way to store/obtain these variables at run-time. Currently, I've implemented ...
user avatar
  • 341
23 votes
4 answers
4k views

Momentum and order of update problems in my physics engine

This question is a "follow-up" question from my previous one, regarding collision detection and resolution, which you can find here. If you don't want to read the previous question, here's ...
user avatar
23 votes
2 answers
9k views

How to design context menus based on whatever the object is?

I'm looking for a solution for a "Right Click Options" behaviour. Basically any and every item in a game, when right clicked, can display a set of options based on whatever the object is. Right ...
user avatar
  • 341
23 votes
6 answers
8k views

What designs are there for a component based entity system that are user friendly but still flexible?

I've been interested in the component based entity system for a while, and read countless articles on it (The Insomiac games, the pretty standard Evolve Your Hierarchy, the T-Machine, Chronoclast ... ...
user avatar
22 votes
2 answers
16k views

How do I disable texture filtering for sprite scaling in XNA 4.0?

I have a sprite that I'm trying to scale up in XNA, but XNA is applying some sort of texture filtering that smooths it and makes it look ugly. I'd like it to just do pixel doubling instead of ...
user avatar
  • 537
21 votes
4 answers
12k views

A Simple Method To Create Island Map Mask

I'm searching for a nice and easy way to generate a mask for an island map with C#. Basically I'm using with a random heightmap generated with perlin noise, where the terrain is NOT surrounded by ...
user avatar
  • 533
20 votes
11 answers
5k views

XNA development tutorials [closed]

Can anybody guide me about where can I get the basic starter tutorials for developing using XNA framework?
20 votes
7 answers
7k views

Easiest, most fun way to program 2D games? Flash? XNA? Some other engine? [closed]

this is a post detailing my search for the most enjoyable way for a hobbyist game programmer to sweeten his free time with making a game. My requirements: I looked at Flash first, I made a couple of ...
user avatar
  • 259
20 votes
2 answers
2k views

Making entire scene fade to grayscale

When the player loses all of their lives, I want the entire game screen to go grayscale, but not stop updating immediately. I'd also prefer it fade to grayscale instead of suddenly lose all color. ...
user avatar
  • 657
20 votes
2 answers
3k views

Atmospheric scattering sky from space artifacts

I am in the process of implementing atmospheric scattering of a planets from space. I have been using Sean O'Neil's shaders from http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html as a ...
user avatar
  • 406
19 votes
5 answers
12k views

Calculate random points (pixel) within a circle (image)

I have an image that contains a circles at a specific location, and of a specific diameter. What I need to do is to be able to calculate random points within the circle, and then manipulate the pixels ...
user avatar
  • 193
19 votes
4 answers
26k views

Is C# different in Unity?

Does Unity use a different version of C#, or is it all the same? It looks different from regular C# but there are some regular C# elements in there.
user avatar
19 votes
2 answers
4k views

Can I legally sell an XNA game made with Visual C# Express Edition?

I've dowloaded Visual C# Express Edition and when it starts up it says "for evaluation purposes only." What does this mean? Does this mean I have to buy the full version to legally sell my game I ...
user avatar
19 votes
2 answers
4k views

Best way to gain C++ working experience for a job in games (coming from C#) [closed]

I am a software developer, experienced with C# (5 years experience) alongside a few other languages. My "dream job" is working in video games as a developer. Most jobs require knowledge of C++, ...
user avatar
  • 879
19 votes
1 answer
28k views

What are some known 2D/3D physics engines for XNA? [closed]

I'm looking for a physics engine to use in an XNA project (2D or 3D). Because it's for XNA, it needs to fulfill some requirements: Not necessarily free, but close to it is obviously preferred Managed ...
19 votes
2 answers
7k views

How to blend two cameras when traveling through a portal in Unity3D

Before I get to my question, I know the most obvious solution would be to use the normalized view port rect, however I need more complex shapes than a rectangle, and I've looked in to using the view ...
user avatar
18 votes
2 answers
7k views

"The Object you want to Instantiate is null" But it works, can I ignore the error?

This has never happened to me so I'm a bit confused. GameObject someObject = Instantiate (Resources.Load ("Prefabs/Items/" + someName)) as GameObject; This ...
user avatar
18 votes
10 answers
8k views

Does C# have a future in games development?

I recently learned that the MMO Minecraft is powered by Java from a recent interview on CVG.co.uk on a possible collaboration between two former and now competing colleagues. In the interview he ...
user avatar
18 votes
2 answers
5k views

RTS game unit structure

I want a way to make a lot of different units without having to program stuff like moveTo and Attack actions more than once The way I see it, there are 2 ways I can do this. A single generic Unit ...
user avatar
18 votes
1 answer
58k views

Draw circle around gameobject to indicate radius

I have a tower in my tower defense game im making with an upgradable radius and i would like when the user clicks the tower to show the radius as a circle around the tower My original thought was to ...
user avatar
18 votes
2 answers
20k views

XNA 2d Camera Scrolling - why use matrix transform?

I am making a test game where I want the level to be constantly scrolling. To create this effect I have established a camera class which simply stores a vector2 position and an enum direction. It also ...
user avatar

1
2 3 4 5
158