xna

The dream to inherit from a struct in c#

房东的猫 提交于 2019-12-10 13:25:58
问题 There I am making a 2D game in C# XNA 4.0, and run across yet again a petty annoyance of mine; the Rectangle . For those using basic collision, this is almost a necessity. For almost any game object created you need to have a rectangle. Then I go to change the X, check collision, or anything else. And there I begin the never-ending battle of objectName.Rectangle.Whatever . To get around this I of course give the class of objectName properties/methods that access these for me. Then I dared to

How to make an object “scalable” while rendered in a form

只谈情不闲聊 提交于 2019-12-10 12:48:04
问题 I am rendering my game in a Winform in the same way as done in this sample: WinForms Series 1: Graphics Device In my game I have some object, for example a rectangle that I can already put and move, in my game world, once created. My project here is a level-editor. What I want to do is to make every object "sizable" or "scalable" (sorry if this isn't the correct word) in the same way as done in every software we commonly use, I mean: I have a class like: public abstract class GameObject {

How do I swap 2 elements in a list [duplicate]

主宰稳场 提交于 2019-12-10 11:27:57
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Swap two items in List<T> Edit: Maybe this will work for getting the 'b' value? for (int i = 0; i < inventory.Count; i++) { if (inventory[a].ItemRectangle.Intersects(inventory[i].ItemRectangle)) { itemB = inventory[i]; } } Edit: Here's my progress. Item itemA; Item itemB; int a = -1; int b = -1; if (a != -1 && b != -1) { itemA = inventory[a]; itemB = inventory[b]; Swap(ref itemA, ref itemB); inventory[a] = itemA

How to subscribe to double clicks?

拟墨画扇 提交于 2019-12-10 10:57:54
问题 I'm trying to find a way to subscribe to double-click event in XNA, and googling gets me winforms related stuff, which isn't the case, I can't use that. Using Timespan and guessing how long the timeout for double click is on a PC is not very reliable. Default XNA input system also has this little flaw: sometimes a key press or a mouse click gets lost between updates and it would ruin double-click reliability in high load moments of the game. How do I subscribe to double-click events in .net?

webcam calling in xna

元气小坏坏 提交于 2019-12-10 10:55:47
问题 i am new in xna i want to use my webcam and make webcam image as a background texture for 3D models is there a function that calls webcam thanks for suggestions 回答1: If you check out the AForge framework you'll find a sample program that does motion detection on webcam feeds. http://code.google.com/p/aforge/ This framework has a very easy to get webcam feeds. Basically ends up VideoCaptureDevice device = new VideoCaptureDevice(monikor); device.NewFrame += new AForge.Video.NewFrameEventHandler

XNA 2D mouse picking

只谈情不闲聊 提交于 2019-12-10 10:48:01
问题 I'm working on a simple 2D Real time strategy game using XNA. Right now I have reached the point where I need to be able to click on the sprite for a unit or building and be able to reference the object associated with that sprite. From the research I have done over the last three days I have found many references on how to do "Mouse picking" in 3D which does not seem to apply to my situation. I understand that another way to do this is to simply have an array of all "selectable" objects in

How to read in a txt file in XNA 4 for Windows Phone 7?

自作多情 提交于 2019-12-10 10:36:46
问题 I had a look at this previous question however this doesn't seem to work for XNA 4 for a Windows Phone 7 project: XNA Framework Importers I've been trying to use: string line; using (StreamReader sr = new StreamReader("credits.txt")) { while ((line = sr.ReadLine()) != null) { //reads line by line until eof //do whatever you want with the text } } ` but this is throwing a System.MethodAccessException "Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)" Do I need

Synchronizing game sprites over network in XNA

笑着哭i 提交于 2019-12-10 10:29:26
问题 I'm making a two player 3D game, and need to synchronize the location of the remote player. Only one object, the avatar representing the player, needs to be synchronized between the two games. I thought this would be pretty straight forward, but it turns out even in a local network the remote player is moving in a stuttery way when playing on two different machines (two instances of the game on the same machine looks fine). In the current approach one game is the server, while the other acts

get a class without a lot of if statements

和自甴很熟 提交于 2019-12-10 10:18:02
问题 I have a certain amount of classes which inherit from an abstract class: abstract public class baseClass { //logics } public class child1 : baseClass { } public class child2 : baseClass { } now I've got some management class which will have to create one of these classes depending on a enum which will have as value the same name so like this: public enum ClassType { child1, child2 } public class Manager { private List<baseClass> _workers; public void Initialize(ClassType type) { //what logics

Serializing cyclic object references using DataContractSerializer not working

戏子无情 提交于 2019-12-10 10:17:11
问题 I'm building an XNA game and I'm trying to save game/map etc. state completely, and then be able to load and resume from exactly the same state. My game logic consists of fairly complex elements (for serializing) such as references, delegates etc. I've done hours of research and decided that it's the best to use a DataContractSerializer that preserves the object references. (I also got around for delegates but that's another topic) I have no problem serializing and deserializing the state, re