Questions tagged [c#]
C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.
8,485 questions
79
votes
10
answers
248k
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 ...
70
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?
66
votes
6
answers
21k
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. ...
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 ...
59
votes
1
answer
18k
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 ...
58
votes
9
answers
22k
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 ...
52
votes
7
answers
11k
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: https://i.sstatic.net/NLg4j.png
The ...
49
votes
4
answers
18k
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, ...
41
votes
3
answers
35k
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 ...
39
votes
11
answers
102k
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 ...
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:
...
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 ...
33
votes
4
answers
17k
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 ...
32
votes
3
answers
15k
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 ...
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 ...
31
votes
5
answers
10k
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 ...
30
votes
2
answers
73k
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 ...
30
votes
6
answers
14k
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 ...
30
votes
1
answer
19k
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 ...
29
votes
1
answer
7k
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 ...
28
votes
5
answers
34k
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 ...
27
votes
8
answers
12k
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 ...
26
votes
3
answers
33k
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
...
26
votes
2
answers
54k
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 ...
24
votes
7
answers
3k
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 ...
24
votes
6
answers
23k
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.
24
votes
3
answers
14k
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 ...
24
votes
1
answer
6k
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 ...
23
votes
7
answers
8k
views
Is C++ being replaced by C# in industry games?
In industry games I mean like Quake, CoD etc.
23
votes
4
answers
5k
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 ...
23
votes
3
answers
5k
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 ...
23
votes
2
answers
10k
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 ...
23
votes
6
answers
9k
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 ... ...
21
votes
2
answers
18k
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 ...
21
votes
4
answers
14k
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 ...
20
votes
5
answers
13k
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 ...
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 ...
20
votes
2
answers
3k
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. ...
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 ...
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.
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 ...
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++, ...
19
votes
2
answers
21k
views
Why use matrix transform for 2D camera scrolling?
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 ...
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
8k
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 ...
18
votes
2
answers
9k
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 ...
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 ...
18
votes
6
answers
134k
views
Unity: detect animation's end
I need a way to detect if animation's clip finished playing and then execute a certain code. Here's some script, that I wrote (called in Update):
...
18
votes
5
answers
105k
views
How to read a data from text file in unity
Can anybody help me out with giving the steps needed for reading data from the text file in unity and how can the script be added.