xna

Is it DrawableGameComponent the wrong tool for creating buttons?

时光毁灭记忆、已成空白 提交于 2019-12-24 21:17:15
问题 I am making a game based on Game State Managment pattern. I made 20 button on a 2nd page that let the user pick the level. LevelButton : TexturedDrawableGameComponent Inside LoadContent() buttons are created and added to GameComponent collection. If I get this right the GameCompoenent is a sort of global collection, so when the user goes back from 4th page to 2nd app will add another 20 buttons. I added a loop that clears all LevelButtons from the collection, but seems this is wrong. Is it

Foreach loop causing lag?

試著忘記壹切 提交于 2019-12-24 16:42:33
问题 In my previous question here. I successfully found out how to read and draw a level each frame from an image. Now that I have inputted a Player class, the player moves really choppy despite the code not doing so. I know this because if I comment the level reading code out, the player moves fine. I think it's the foreach loop doing this. I have no idea and help would be appreciated! Just to save you time from clicking, here's my successful level-reading code. public void readLevel(string path,

Load and save Color value

江枫思渺然 提交于 2019-12-24 16:22:10
问题 I'm trying to load Color value from a textfile with ReadLine. When saved with WriteLine it looks like this [Color: R=53, G=40, B=121, A=255, PackedValue=4286130229]. Color color = Color.Black; stream.WriteLine(color.ToString()); Then I guess it has to be converted somehow, cant figure it out. color ??? stream.ReadLine(); 回答1: If you're using a text storage medium, then go with HTML encoding: Color myColor = Color.FromArgb(255, 255, 50, 25); String strColor = ColorTranslator.ToHtml(myColor); /

Opening files in a form, ThreadStateException was unhandled

╄→гoц情女王★ 提交于 2019-12-24 15:21:00
问题 I have a form name Form1.cs and when I run it, it has an error: ThreadStateException was unhanded. I am trying to open a file from a desired location, then latter on have it so the file will load automatically in a text box on screen. I have heard of this [STAThread] but am confused on how to add it. When I try to use it in the main method it comes up as "not valid on this declaration type". Form1.cs : public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void

ObjectIDGenerator implementation

陌路散爱 提交于 2019-12-24 15:19:59
问题 I was attempting to use ObjectIDGenerator in C# to generate a unique ID during serialization, however, this class is not available in the XBox360 or Windows Phone 7 .NET frameworks (they use a compact version of .NET). I implemented a version using a dictionary of Object to Int64 and was able to get a fully working version up, however, the performance is unsatisfactory. I'm serializing on the order of tens of thousands of objects, and currently this is the greatest bottleneck in save/load

Windows Phone 8 app randomly crashes with error code -2147220717 (0x80040313)

大憨熊 提交于 2019-12-24 14:27:52
问题 I am currently developing a stopwatch and timer app in C#/XAML for Windows Phone 8. While using my app on my phone, I found that it randomly closed out/crashed and that too at different points of use (i.e. I wasn't doing the same thing each time it closed out). While debugging, I found that my app closed out with the following error code in my output window: "The program '[1100] TaskHost.exe' has exited with code -2147220717 (0x80040313)." I am very confused as to why this is happening. I

Windows Phone 7 - How to use TTF in SpriteFont?

让人想犯罪 __ 提交于 2019-12-24 14:16:30
问题 Is there any way to use custom fonts in XNA? 回答1: Sure, you need to import the font to your system. Add the font to the font system catalog or add through control panel. When it is ready (reboot Visual Studio) use the custom template for SpriteFont in Visual studio, which generates an XML file. An exmaple: <?xml version="1.0" encoding="utf-8"?> <!-- This file contains an xml description of a font, and will be read by the XNA Framework Content Pipeline. Follow the comments to customize the

obtaining the tint color from a sprite batch, within a HLSL shader

淺唱寂寞╮ 提交于 2019-12-24 10:54:57
问题 How do I obtain the color tint from a sprite batch from within the HLSL shader? I'm working with xna. Also, what is the theory behind this? I would think that the tint color would just change the actual texture color before passing it to HLSL, but that does not seem to be the case. 回答1: You can look at the source code for the default SpriteBatch shader here. Look at SpriteEffect.fx for details. Specifically the tint colour is passed in COLOR0 to the vertex shader, which is then passed

How to change pitch beyond 1 or -1 in C# + XNA?

夙愿已清 提交于 2019-12-24 10:35:06
问题 I need to be able to have more freedom than just 2 octaves to create the thing I want to, but I can't with XNA. I do realize there probably isn't a way to get the program to accept a larger/smaller value, but is there a way around it? like taking the sound at the lowest pitch, and creating a new one as that so I can lower it more? 来源: https://stackoverflow.com/questions/23115326/how-to-change-pitch-beyond-1-or-1-in-c-sharp-xna

Missile System Math Problem (very few code)

房东的猫 提交于 2019-12-24 09:58:13
问题 I want a Missile to follow a player with following rules: - when the player is at the right side relative to the missile, change the rotation to the right at a fixed rate - else change the rotation to the left at the same rate if (missile.Rotation > 0 && missile.Rotation < Math.PI) { if (angle > missile.Rotation && angle < missile.Rotation + Math.PI) { missile.Rotation += 0.05f; } else { missile.Rotation -= 0.05f; } } else { if (angle < missile.Rotation && angle > missile.Rotation - Math.PI)