xna-4.0

Why does changing the graphics setting after doing so in the `LoadContent` method fail?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 10:45:19
问题 If I set the graphics settings in the Initialize method and then in the Update method, like so: protected override void Initialize() { graphics.ApplyChanges(); base.Initialize(); } protected override void Update(GameTime gameTime) { graphics.ApplyChanges(); base.Update(gameTime); } Everything is fine. However, when I move the code to my LoadContent method like so: protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); graphics.ApplyChanges(); } protected

Is there an inexpensive way to transfer colour data from a RenderTarget2D on a per frame basis?

↘锁芯ラ 提交于 2019-12-11 09:52:32
问题 Until recently, our game checked collisions by getting the colour data from a section of the background texture of the scene. This worked very well, but as the design changed, we needed to check against multiple textures and it was decided to render these all to a single RenderTarget2D and check collisions on that. public bool TouchingBlackPixel(GameObject p) { /* Calculate rectangle under the player... SourceX,SourceY: Position of top left corner of rectangle SizeX,SizeY: Aproximated (cast

Calculating in radians the rotation of one point around another

懵懂的女人 提交于 2019-12-11 07:14:03
问题 I have been trying to get this problem resolved for week and have get to come to a solution. What I have is 2 points in a 2d space, what I need to resolve is what the rotation of one is around the other. With luck the attached diagram will help, what I need to be able to calculate is the rotational value of b around a. I have found lots of stuff that points to finding the dot product etc but I am still searching for that golden solution :o( Thanks! 回答1: Vector2 difference = pointB - pointA;

Load Texture2D from Stream with RenderTarget2D, Textures disapear after game window minimizing

Deadly 提交于 2019-12-11 04:59:58
问题 I hava some problem with loading textures from directory. Maybe code first: private Texture2D LoadTextureStream(string filePath) { Texture2D file = null; RenderTarget2D result = null; try { using (System.IO.Stream titleStream = TitleContainer.OpenStream(filePath)) { file = Texture2D.FromStream(GraphicsDevice, titleStream); } } catch { throw new System.IO.FileLoadException("Cannot load '" + filePath + "' file!"); } PresentationParameters pp = GraphicsDevice.PresentationParameters; //Setup a

2D BoundingRectangle rotation in XNA 4.0

梦想与她 提交于 2019-12-11 04:38:11
问题 I'm having trouble working out what I need to do in order to have a 2D BoundingRectangle for a sprite object in my game rotate and update position depending on which way the user wants the sprite to travel. I draw out the sprite with it's rotation and scale values like so: spriteBatch.Draw(texture, position, null, Color.White, rotation, origin, scale, SpriteEffects.None, 1f); My current setup for getting the BoundingRectangle is: public Rectangle BoundingRectangle { get { return new Rectangle

Make a sprite white in XNA 4.0 w/ simple shader (alpha issues)

こ雲淡風輕ζ 提交于 2019-12-11 04:27:56
问题 Using the simple shader at Tint Sprite White and the sample code at Sprite Effects Sample, I've loaded the .fx file for the shader into the sample project and replaced one of the sample effects in one of the Draw() calls to use the whitening effect. What I get is a big white square with the same dimensions as the texture itself. I obviously want only the regions of the texture where the alpha is not 0 to be made white. The shader appears to be working, as I altered the default white color to

Hosting XNA inside WPF - Weird “Phantom” Window issue

情到浓时终转凉″ 提交于 2019-12-11 04:24:32
问题 I'm trying to host an XNA game inside a WPF window using the Windows Forms host control. I've got a weird problem that a "Phantom" window is created when I run the game. It is created exactly at the first call to game's Update method exits. Here is the Update code, the default one from a new XNA project: protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update

xna 4.0 error on loading texture2d

不问归期 提交于 2019-12-11 02:26:00
问题 using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Project { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager

Accessing instantiated object from another class - c#

Deadly 提交于 2019-12-11 02:09:52
问题 I have a Player class , NPC class , BattleManager class , and Game class . Player class stores/gets/sets player stats such as health, stamina, level, experience. NPC is similar, but is for NPCs. Game class instantiates Player class and NPC class . Game glass has two GameStates, battle and non-battle. When the player is in battle, GameState goes to battle, when the battle finishes, it switches to non-battle. What I'm trying to do is have the BattleManager class manage battles between the NPC

how to Hide XNA 4.0?

梦想与她 提交于 2019-12-10 20:09:21
问题 I'm Trying to hide my XNA game window but i don't seem to be able to here's what I've tried so far from what i could get off google. Form frmXNA = (Form)Form.FromHandle(this.Window.Handle); frmXNA.Hide(); I have also tried Form frmXNA = (Form)Form.FromHandle(this.Window.Handle); frmXNA.Visible = false; I figure I'm doing something very simple wrong and once it's pointed out I'll probably laugh at how i didn't see it. Thanks for the help 回答1: add the System.Windows.Form refrence to the project