Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 May 2009
Offline Last Active Jan 23 2014 11:26 PM

#4949910 Collision detection, 2d environment with C#

Posted by laztrezort on 16 June 2012 - 04:11 PM

That is pretty difficult to read, there is no way I would want to try and understand all that without a debugger.

This is how I usually tackle these things: get out a piece of graph paper, draw out a simple test case and write down what each variable value should be, then step through the code until there is a discrepancy between the graph paper test case and the watch variables.

#4948958 [C#] Game Saving Problems, Files are too large

Posted by laztrezort on 13 June 2012 - 04:41 PM

I think you need to provide some more information in order to get meaningful replies.

What kind of objects are you saving? What exactly does a single "block" consist of? How are maps being stored in memory? How exactly are you serializing?

#4948952 Newbie: Questions about 2d game development.

Posted by laztrezort on 13 June 2012 - 04:24 PM

Is it normal that I have to do a LOT of coding before I make a game or I need a proper UI to speed up the development?

Yes, games are a LOT of work - both on the coding side, and on the asset creation side. Note that even if you go with the Unity3D route, you will still need to do some coding (just a lot less), and you will still need to make all the assets. Also, Unity is a complex piece of software with it's own learning curve - but there appears to be a lot of support through forums and tutorials. Personally, I prefer working in XNA, but that is because I enjoy the programming side of things, where Unity3D always seemed more targeted for an artist-minded developer - your mileage may vary.

If you've got the basics of XNA and C# down, you could try out FlatRedBall which, last I checked, has some support for higher level game development tools. It is basically a 2d engine built on top of XNA.

There is also something called GameMaker that can be used to quickly create basic 2D games with minimal programming, if that is what you are looking for.

Of course, as you gain experience, coding gets much quicker (less backtracking, less refactoring, less research, and reusing pieces of code you have amassed).

Is there any other 2d engine that I should use instead of XNA (something more ideal for beginners)? If yes please mention some.

Although I have never used it, there is Python + Pygame (and there are likely other libraries for Python as well). I've heard it's "good for beginners", but again I've never gotten into Python much.

My personal opinion is that unless you are getting too discouraged, try and stick with one thing until you feel like you've got a fairly good grasp of it. If it's too hard, lower your goals abit - a completed "simple" project is more motivational than a complex one that never gets done.*

* P.S. for the record, although that is my advice, it is advice that I never seem to be able to practice ;)

#4948371 Virtual Machine/Scripting/Console in XNA using C#

Posted by laztrezort on 11 June 2012 - 08:21 PM

Object[][] args2 = new object[1][] { new object[2] { ref camera.Position, ref camera.Target.Position } }; <----doesnt work.

Whats happening is the position isnt updating to match the true position of the camera. Its staying at whatever the position is at the time of creating the widget....

It's possible I'm still misunderstanding, but here is how I see it:

You want to reference the two Position values - however, Vectors are structs, thus value types, so they are being copied into your new object (just like any other value, such as an int).

What you need to do is copy a reference type that contains and exposes those values. In the above case, "camera" is (probably) a reference, so couldn't you just have your object keep a copy of the camera reference?

In general, when you want to hold on to a reference to a value type, you need to put it inside of a reference type.

#4947951 C# stop waiting on events

Posted by laztrezort on 10 June 2012 - 10:46 AM

I believe what you are looking to do is discussed here: http://blogs.msdn.com/b/shawnhar/archive/2010/12/06/when-winforms-met-game-loop.aspx

It's targeted for XNA + Winforms, but should be applicable in straight Winforms applications that need animation timing as well.

#4947265 Efficient coding in C#

Posted by laztrezort on 07 June 2012 - 09:31 PM

Profile, either the quick and dirty way with timers, or with some profiling tool. This should always be the first step of optimizing. Never assume you know where inefficiences are, even fairly experienced coders can be mistaken.

#4941896 Optimising Sprite Sheets

Posted by laztrezort on 21 May 2012 - 06:33 AM

My experience has been to just trust SpriteBatch to sort all the sticky details out for you - it's been designed and optimized for general cases like this, and typically performs plenty fast.

I don't know the particular details inside SpriteBatch, but as long as all your drawing occurs between a Begin() End(), it likely sends the texture only as often as it has to (once in your case).

If you indeed are seeing a bottleneck in rendering sprites from a texture sheet (which I fine hard to believe on modern hardware), you will have to roll your own effect, AFAIK.

#4941823 What's the best C#(XNA) book/site

Posted by laztrezort on 20 May 2012 - 11:13 PM

2. (dumb question) Can C# be used to develop iOS/android games?

I don't know much (if anything) about developing for those platforms, but I do know Unity3D supports them, and C# is one of the scripting languages supported by Unity - so yes.

#4939282 Mouse collision: new Rectangle or move Rectangle?

Posted by laztrezort on 11 May 2012 - 06:58 AM

Doesn't Rectangle have a Contains() method? If so, it would be simpler to use that instead of creating a rectangle of size 1 every time.

#4936960 Checking for texture transparency with resize

Posted by laztrezort on 02 May 2012 - 10:27 PM

There may be an easier way, maybe an XNA guru here will give a better answer, but personally I would try and tackle this by adjusting your sample coordinates (array index) of the original texture by the scale factor. This may be innacurate unless you reproduce the sampling method used by the shader, however (IIRC mip-mapping is enabled by default)

Or, you could render to a rendertarget and query that - this might be slower, but if you aren't scaling the texture every frame it may work fine.

#4934928 Weird simple CSharp math issue.

Posted by laztrezort on 25 April 2012 - 06:44 PM

What are you expecting it to return? Are you thinking that ^ is a power operator (it's not)?

See here for c# operators: http://msdn.microsof...y/6a71f45d.aspx

#4928605 Best approach to loading and saving game data?

Posted by laztrezort on 05 April 2012 - 04:08 PM

I looked into saving data into binary format but I'm not very familiar with it. Is there any way to convert values into binary format through an online application? I get things like ô SOH NUL NUL

Typically whatever language/framework you are programming in will have some sort of binary input/output library or routines available that interface with the operating system, and provide a way to directly read or write binary data to an from a disk file. The specifics of how this is accomplished varies widely, however. What exactly are you trying to do?

#4927864 c#: creating a dynamic textbased inventory for pnc adventure

Posted by laztrezort on 03 April 2012 - 07:53 AM

Don't get intimidated by my (mis)use of the word "database", I use that term only as a concept. In this case, it would just be a List or something similar.

Here is a basic outline of the general idea. Here I am using inheritance, because it is perhaps easier to understand and shorter to write a quick example, but you don't have to. All the data for an item is stored in a single Item object, and more specific item types are sublassed and implement functions for performing actions on them.

abstract class Item
	 public int Location{get;set;}

class LightSource:Item
	public int FuelAmount{get;set;}
	public int Brightness{get;set;}

	 public void TurnOn() {...}
	 public void TurnOff() {...}

class Hat : ITem
	 public void PutOn() {...}
	 public void TakeOff() {...}
List<Item> Database; // here are all of the item blueprints, set this up at runtime or load defaults from
	 	 	 	 	 	 	 // a text/config file
class Container
	List<Item> contents;

When you get to handling actions on items, you will need to check the item type and act appropriately. Again, this is based on the inheritance example above.

void TryTurnOnAction(Item theItem)
	 if(theItem is LightSource)
		  (theItem as LightSource).TurnOn();
		  // tell player that is an innappropriate action

You can also, as you suggested, keep bools for appropriate actions on the item class, instead of checking type and casting - the logic would nearly be the same.

#4927753 Are there any in-depth explanations for Microsoft's GameStateManagement e...

Posted by laztrezort on 02 April 2012 - 09:17 PM

Other than going through the source and example, I don't know of any other examples or explanations off-hand. However, here is a general article about the subject that might be of interest, or provide some background for understanding or rolling your own scenario: http://www.xnadevelopment.com/tutorials/thestateofthings/thestateofthings.shtml

#4927675 c#: creating a dynamic textbased inventory for pnc adventure

Posted by laztrezort on 02 April 2012 - 04:35 PM

Typically, here is how an item system is built:

First you have an Item class, and instance each object that will appear in the game, each of which contains all of the default (starting) data for an object of that type. Keep a collection of these Item objects somewhere, think of this as a minimal "database" of sorts.

If your game item data will never change during the course of play, then this is basically all you need. In your containers, you just keep a list of indexes corresponding to the item in the database (or keys if you are using a dictionary, or just a reference if you are using something like a HashSet).

If your game item data can change during the course of play, which is what your case sounds like, then the database can be considered a collection of item blueprints. Instance the item by copying from the database, and just keep the reference to it in the container.

For the Item class itself, it sounds like you already have a pretty good idea of what it will be. In the past, many games used inheritance as a way to define different items. Lately the trend seems to go more towards aggregation. It sounds like aggregation is more what you had in mind, and will probably be simpler, since inheritance tends to get messy pretty quickly.