Jump to content

  • Log In with Google      Sign In   
  • Create Account

Nick Gravelyn

Member Since 14 Aug 2005
Offline Last Active Oct 05 2014 03:38 PM

Posts I've Made

In Topic: Why does Game.Draw() have a GameTime parameter?

21 February 2014 - 11:46 AM

I've used the GameTime passed to Draw for visual effects that don't need synchronizing with the main game. For example, I want a sine-wave based pulsing glow around some object. If I wanted to track time for that in the Update method, I'd need another variable somewhere. Or I can just use GameTime.TotalGameTime and be done with it.


You certainly don't want to mix in critical gameplay-impacting rendering this way, but for any visuals that need some long running time variable, it's a free way to have that handed to your drawing code.

In Topic: [Question] Regarding calculating tile position from GID

14 February 2014 - 12:06 PM

Notice in that thread they're using the width in both the x and y calculations whereas you swapped in the height. I believe that could be causing you issues.

In Topic: xna random number in 2d

26 April 2013 - 11:04 AM

Random r = new Random(DateTime.Now.Millisecond);
Vector2 randomVector = new Vector2(r.Next(0, SCREENWIDTH), r.Next(0, SCREENHEIGHT));

I would make two notes here:


1) The default constructor for Random already handles seeding by time; you don't need to do it yourself.

2) Because of #1, you want to reuse the same Random instance as much as possible. For example if you ran this:


for (int i = 0; i < 100; i++)
   Random r = new Random();
   someVectorList.Add(new Vector2(r.Next(0, ScreenWidth), r.Next(0, ScreenHeight));


You would find that quite a few (if not all) vectors would have the exact same values. This is because each new random instance would have the same seed and therefore generate the same sequence of numbers.


So in general you want to create one Random per method at the least, but most people generally just make one Random instance as a public static member on some type and reuse that everywhere.

In Topic: Finding a cross-platform, easy to use language

12 April 2013 - 01:44 PM

If you don't mind a more ActionScript/JavaScript style syntax, you could look into Haxe: http://haxe.org/. In my limited toying with it, it seems rather nice. They have NME, HaxePunk, and HaxeFlixel for getting going on 2D games. Not sure what 3D support you could find. Haxe is nice in that it cross compiles into other code (C++ for Windows, JavaScript for the web, etc) so there's no runtimes to worry about. Seems like a good idea for someone looking to use the same code across a lot of platforms.

In Topic: C# include?

12 April 2013 - 01:42 PM

You can use #if/#endif in C# for using preprocessor directives.


You can also add files as a link, so you keep the file in a common directory and any number of projects can include the file as a link which means they'll all share the same C# file, but it will be compiled into all the projects. As long as the projects don't reference each other you should be fine (if the projects reference each other, you're likely to get an error for having the same type compiled twice).