SnprBoB86

Members
  • Content count

    374
  • Joined

  • Last visited

Community Reputation

277 Neutral

About SnprBoB86

  • Rank
    Member
  1. C# feature: Extensions

    Extension methods have always needed to be defined in a static class like your SpriteManager class, but they are typically given an "Extensions" suffix on the name of the class to be extended. For example: "SpriteBatchExtensions" Nick just forgot to point out the static class bit in his tutorial, you should post a comment to him and let him know. Also, I don't agree with Nick that this is appropriate use of extension methods. Instead, I would declare Sprite.Draw with the signature `public void Draw(SpriteBatch batch)` to be used as `someSprite.Draw(spriteBatch)`. Why? Because it's simpler and extension methods don't really buy you anything here. Extension methods are really as syntactical sugar. They are useful for saving typing when you have helper methods that can be identified by the target object and method name (2 things) rather than a namespace (well, a static class name), target object, and method name (3 things). "user@microsoft.com".IsValidEmailAddress() vs EmailAddressHelpers.IsValid("user@microsoft.com") In the Sprite case, you have: spriteBatch.Draw(sprite) vs sprite.Draw(spriteBatch) Why bother with the extension method? It just confuses things! That said, Nick isn't necessarily wrong to suggest the use of extension methods here. It's just not the call I would have made :-)
  2. C# - reference to a variable?

    Quote:Original post by Koobazaur at least when I had ** ppSomething I knew exactly what was going on instead of having to wonder what is referencing what (not to mention extra flexibility). And wtf is up with the lack of template, errr, generic specialization? Seriously... You have nearly the exact same flexibility in C# and you can know "exactly what is going on" with great certainty once you learn the .NET model just as you learned the C++ model. C# can accomplish non-partial generics specialization through inheritance. For example: class SpecializedForBar : Foo<Bar> { //override virtual members of Foo }
  3. C# - reference to a variable?

    public Renderer(ref Bitmap DrawArea, ref cEntityManager EntityManager, ref cTimer Timer) { _DrawArea = DrawArea; //this doesn't do what I want _rEntityManager = EntityManager; _rTimer = Timer; } No, this is incorrect usage of "ref". You are not changing DrawArea, EntityManager, or Timer. Remove the ref keyword from all three and you will find that the code behaves 100% identically. Examine this test code: using System; using System.Collections.Generic; class UsingRef { static void AddTwo(int y) { y += 2; } static void AddTwo(ref int y) { y += 2; } static void AppendTwo(List<int> b) { b.Add(2); b = null; } static void AppendTwo(ref List<int> b) { b.Add(2); b = null; } public static void Main() { int x = 5; List<int> a = new List<int>(); AddTwo(x); Console.WriteLine(x); AddTwo(ref x); Console.WriteLine(x); AppendTwo(a); Console.WriteLine(a == null ? "null" : a.Count.ToString()); AppendTwo(ref a); Console.WriteLine(a == null ? "null" : a.Count.ToString()); Console.ReadLine(); } } Additionally, a nitpicky comment: your capitalization and naming conventions do not match the standard guidelines. Google-up the .net guidelines.
  4. C# - reference to a variable?

    Quote:really dislike the C#'s referencing model ><) That's because you are doing it incorrectly. You do not need any of those "ref" keywords that you included. http://forums.xna.com/thread/40480.aspx http://msdn2.microsoft.com/en-us/library/14akc2c7(VS.80).aspx In short: "ref" means to pass the VARIABLE by reference, not the object it points to. All reference types are, automatically, passed by reference. This means that returning a value is also automatically by reference!
  5. C# - reference to a variable?

    accidental double post
  6. Quote:Original post by LordShade If this situation occurs, it usually marks the time to re-examine your class structure. There are plenty of good reasons, not the least of which is containment with back-references. That is, some class A which has a list of B and each B only has one A, so you should be able to also navigate from the B back to A.
  7. You should try re-posting this question over at creators.xna.com XNA Framework and Game Studio Devs hang out there and provide a lot of official answers!
  8. Type conversion in C#

    Um, what would it mean to convert an "Example" into a bool? If you mean is not null like pointers in C, you can easily do: Example e = ...; if (e == null) or... if (e != null) otherwise, just define a function much like the ToString() if it makes sense to do so: class Example { ... public bool ToBool() { ... } }
  9. [.net] OpenGL in C#?

    Curious: Unless you are planning to target Mono, why not use XNA?
  10. XNA vs. C++ for serious game programming

    Check out http://www.xnaracinggame.com/ Is that serious enough for you? XNA Racing Game runs silky smooth on the Xbox 360 despite being somewhat unoptimized and utilizing only a single thread (XNA allows you to use up to 4 of the 6 hardware threads from the 360's 3 cores). Professionals and hobbyists alike are discovering the magic of XNA. Hobbyists are producing amazing results with limited experience and professionals are building prototypes and casual games in a fraction of the time and at a fraction of the cost of using C++. Jump in: http://creators.xna.com
  11. use BYTE type in HLSL

    I might be wrong (never tried it) but I think you can declare and use a byte4
  12. c# xma Vector2

    new Vector2(210f,100f}, Should be: new Vector2(210f,100f), Notice the closing } should be a ) What other errors are you getting?
  13. c# xma Vector2

    Vector2[] block = new Vector2[] { new Vector2(200f,100f), new Vector2(210f,100f}, new Vector2(210f,110f), new Vector2(210f,120f) }; The whitespace isn't important.
  14. MDX, XNA, DirectX, Oh my!

    Oh, and there is a 1.1 release of XNA coming out very shortly which has many more math functions as well as font support. More information here: http://blogs.msdn.com/xna/archive/2007/03/08/announcing-the-xna-game-studio-express-update.aspx
  15. MDX, XNA, DirectX, Oh my!

    Use the XNA Framework! It obsoletes MDX2 (and indeed, it was born of the same code base)