Search Results

Search found 1663 results on 67 pages for 'xna'.

Page 23/67 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • Issue with transparent texture on 3D primitive, XNA 4.0

    - by Bevin
    I need to draw a large set of cubes, all with (possibly) unique textures on each side. Some of the textures also have parts of transparency. The cubes that are behind ones with transparent textures should show through the transparent texture. However, it seems that the order in which I draw the cubes decides if the transparency works or not, which is something I want to avoid. Look here: cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"]; Block[] cubes = new Block[4]; cubes[0] = new Block(BlockType.leaves, new Vector3(0, 0, 3)); cubes[1] = new Block(BlockType.dirt, new Vector3(0, 1, 3)); cubes[2] = new Block(BlockType.log, new Vector3(0, 0, 4)); cubes[3] = new Block(BlockType.gold, new Vector3(0, 1, 4)); foreach(Block b in cubes) { b.shape.RenderShape(GraphicsDevice, cubeEffect); } This is the code in the Draw method. It produces this result: As you can see, the textures behind the leaf cube are not visible on the other side. When i reverse index 3 and 0 on in the array, I get this: It is clear that the order of drawing is affecting the cubes. I suspect it may have to do with the blend mode, but I have no idea where to start with that.

    Read the article

  • XNA and Ninject: Syntax for dependency arguments?

    - by Rosarch
    I have a class with a public constructor: public MasterEngine(IInputReader inputReader) { this.inputReader = inputReader; graphicsDeviceManager = new GraphicsDeviceManager(this); Components.Add(new GamerServicesComponent(this)); } How can I inject dependencies like graphicsDeviceManager and new GamerServicesComponent while still supplying the argument this?

    Read the article

  • Using DynamicVertexBuffer in XNA 4.0

    - by Bevin
    I read about DynamicVertexBuffer, and how it's supposed to be better for data that changes often. I have a world built up by cubes, and I need to store the cubes' vertices in this buffer to draw them to the screen. However, not all cubes have vertices (some are air, which is transparent) and not all faces of the cubes need to be drawn either (they are facing each other), so how do I keep track of what vertices are stored where in the buffer? Also, certain faces need to be drawn last, namely the ones with transparency in them (like glass or leaves), and these faces also need to be drawn in a back-to-front order to not mess up the alpha blending. If all of these vertices are stored arbitrarily in this buffer, how do I know what vertices are where? Also, the number of vertices can change, but the DynamicVertexBuffer doesn't seem very dynamic to me, since I can't change it's size at all. Do I have to recreate the buffer every time I need to add or remove faces?

    Read the article

  • XNA AdGameComponent does not draw

    - by Alex Shkor
    I have following code. But AddGameComponent doesn't draw. protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); var li = new LicenseInformation(); IsTrial = li.IsTrial(); if (IsTrial) { AdGameComponent.Initialize(this, AppID); Components.Add(AdGameComponent.Current); CreateAd(); } } private void CreateAd() { bannerAd = AdGameComponent.Current.CreateAd(AdUnitID, new Rectangle(x, y, width, height), true); AdGameComponent.Current.Enabled = true; } I have tried to set DrawOrder to 1000, but ads still doesn't work.

    Read the article

  • XNA 2D/3D Drawing method?

    - by Adir
    What would be a better parctice, writing the drawing method inside the GameObject class or in the Game class? GameObject obj = new GameObject(); obj.Draw(); Or GameObject obj = new GameObject(); DrawGameObject(obj);

    Read the article

  • [XNA] Forming bounding box only around visible sprites

    - by nadalian
    Hi, this site has been really amazing for helping me with game development however I'm unable to find an answer for the following question (nor am I able to solve it on my own). I am trying to do rectangle collision in my game. My idea is to 1) get the original collision bounding rectangle 2) Transform the texture (pos/rot/scale) 3) Factor changes of item into a matrix and then use this matrix to change the original collision bounds of the item. However, my textures contain a lot of transparency, transparency that affect the overall height/width of the texture (I do this to maintain power of two dimensions). My problem: How to create a rectangle that forms dimensions which ignore transparency around the object. A picture is provided below: http://img51.imageshack.us/img51/4772/boundingbox.png

    Read the article

  • Can't modify XNA Vector components

    - by Matt H
    I have a class called Sprite, and ballSprite is an instance of that class. Sprite has a Vector2 property called Position. I'm trying to increment the Vector's X component like so: ballSprite.Position.X++; but it causes this error: Cannot modify the return value of 'WindowsGame1.Sprite.Position' because it is not a variable Is it not possible to set components like this? The tooltip for the X and Y fields says "Get or set ..." so I can't see why this isn't working.

    Read the article

  • read line by line the text file for make map in xna

    - by Mohammadali Najjar khodabakhsh
    i want to read a text file for build map; for example I have this map 0@0000000 0@0000000 0@0000000 000000000 000000000 000000000 000000000 I know I should use this : StreamReader reader = new StreamReader(Application.StartupPath+@"/TestMap.MMAP"); string line = reader.ReadToEnd(); reader.Close(); now for example I want read line 2 char "@". how can i do this? please help me. solve : Thank you (L.B AND user861114) at last my problem solve like this : string[,] item = new string[9, 7]; string[] line = File.ReadAllLines(Application.StartupPath + @"/TestMap.MMAP"); for (int j = 0; j < 7; j++) { for (int i = 0; i < 9; i++) { item[i, j] = line[j].Substring(i, 1); Console.WriteLine(i + " " + j + "=" + item[i, j]); } } thanks alot.

    Read the article

  • Loading material parameteres from FBX in XNA

    - by M_F
    I've got some material parameters stored in the FBX file (DiffuseFactor, ShininessExponent, SpecularFactor and others), but I can't get to them using Effect.Parameters nor BasicEffect (they've got only the basic stuff - like EmmisiveColor or alpha). I know, that I can try to write a Effect-derived class, but is there any other way? A built-in feature or maybe some half-raw parameters stored somewhere?

    Read the article

  • XNA on the TechNet Wiki

    - by Michael B. McLaughlin
    Many months ago I came across an interesting Microsoft website, the TechNet Wiki, when I was looking for information about something that I can’t even remember anymore. I noticed at the time that its section on gaming technologies was sparse and even exchanged a few emails with one of the friendly Microsoft employees who contributes there regularly about some ideas I had for the site. I seem to recall mentioning my intentions to add some articles on XNA when I found the time but between one thing and another it seemed like I was busy from the end of last Summer straight through ‘til now. Yesterday I came across the TechNet Wiki link in my miscellaneous links collection and remembered my intentions many months ago. I decided that adding XNA pages to it would make a nice project to work on while taking breaks from my other projects. So I wrote my first two articles for it: XNA Framework Overview and Content Pipeline Overview. I hope to add more in the coming days and weeks. I’d be delighted if some of my fellow XNA enthusiasts out there joined in, time permitting. Anyone else who’d like to add a page or two on a topic area you’re familiar with, this seems like a great opportunity to contribute to the community and help build a nice knowledge base to benefit all of us who are always interested in learning something new!

    Read the article

  • How can I implement collision detection for these tiles?

    - by Fiona
    I am wondering how this would be possible, if at all. In the image below: http://i.stack.imgur.com/d8cO3.png The light brows tiles are ground, while the dark brown is background, so the player can pass over those tiles. Here's the for loops that draws the level: float scale = 1f; for (row = 0; row < currentLevel.Rows; row++) { for (column = 0; column < currentLevel.Columns; column++) { Tile tile = (Tile)currentLevel.GetTile(row, column); if (tile == null) { continue; } Texture2D texture = tile.Texture; spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Rectangle( (int)(column * currentLevel.CellSize.X * scale), (int)(row * currentLevel.CellSize.Y * scale), (int)(currentLevel.CellSize.X * scale), (int)(currentLevel.CellSize.Y * scale)), Microsoft.Xna.Framework.Color.White); } } Here's what I have so far to determine where to create a Rectangle: Microsoft.Xna.Framework.Rectangle[,,,] groundBounds = new Microsoft.Xna.Framework.Rectangle[?, ?, ?, ?]; int tileSize = 20; int screenSizeInTiles = 30; var tilePositions = new System.Drawing.Point[screenSizeInTiles, screenSizeInTiles]; for (int x = 0; x < screenSizeInTiles; x++) { for (int y = 0; y < screenSizeInTiles; y++) { tilePositions[x, y] = new System.Drawing.Point(x * tileSize, y * tileSize); groundBounds[x, y, tileSize, tileSize] = new Microsoft.Xna.Framework.Rectangle(x, y, 20, 20); } } First off, I'm not sure how to initialize the array groundBounds (I don't know how big to make it). Also, I'm not entirely sure how to go about adding information to groundBounds. I want to add a Rectangle for each tile in the level. Preferably I'd only make a Rectangle for those tiles accessible by the player, and not background tiles, but that's for a different day. FYI, the map was made with a freeware program called Realm Factory.

    Read the article

  • What vertex shader code should be used for a pixel shader used for simple 2D SpriteBatch drawing in XNA?

    - by Michael
    Preface First of all, why is a vertex shader required for a SilverlightEffect (.slfx file) in Silverlight 5? I'm trying to port a simple 2D XNA game to Silverlight 5 RC, and I would like to use a basic pixel shader. This shader works great in XNA for Windows and Xbox, but I can't get it to compile with Silverlight as a SilverlightEffect. The MS blog for the Silverlight Toolkit says that "there is no difference between .slfx and .fx", but apparently this isn't quite true -- or at least SpriteBatch is working some magic for us in "regular XNA", and it isn't in "Silverlight XNA". If I try to directly copy my pixel shader file into a Silverlight project (and change it to the supported "Effect - Silverlight" importer/processor), when I try to compile I see the following error message: Invalid effect file. Unable to find vertex shader in pass "P0" Indeed, there isn't a vertex shader in my pixel shader file. I haven't needed one with my other 2D XNA apps since I'm just doing basic SpriteBatch drawing. I tried adding a vertex shader to my shader file, using Remi Gillig's comment on this Shawn Hargreaves blog post for guidance, but it doesn't quite work. The shader file successfully compiles, and I see some semblance of my game on screen, but it's tiny, twisted, repeated, and all jumbled up. So clearly something's not quite right. The Real Question So that brings me to my real question: Since a vertex shader is required, is there a basic vertex shader function that works for simple 2D SpriteBatch drawing? And if the vertex shader requires world/view/project matricies as parameters, what values am I supposed to use for a 2D game? Can any shader pros help? Thanks!

    Read the article

  • Simple XNA 2D demo: why is my F# version slower than C# version?

    - by Den
    When running this XNA application it should display a rotated rectangle that moves from top-left corner to bottom-right corner. It looks like my F# version is noticeably much slower. It seems that the Draw method skips a lot of frames. I am using VS 2012 RC, XNA 4.0, .NET 4.5, F# 3.0. I am trying to make it as functional as possible. What could be the reason for poor performance? C#: class Program { static void Main(string[] args) { using (var game = new FlockGame()) { game.Run(); } } } public class FlockGame : Game { private GraphicsDeviceManager graphics; private DrawingManager drawingManager; private Vector2 position = Vector2.Zero; public FlockGame() { graphics = new GraphicsDeviceManager(this); } protected override void Initialize() { drawingManager = new DrawingManager(graphics.GraphicsDevice); this.IsFixedTimeStep = false; } protected override void Update(GameTime gameTime) { position = new Vector2(position.X + 50.1f * (float)gameTime.ElapsedGameTime.TotalSeconds, position.Y + 50.1f * (float)gameTime.ElapsedGameTime.TotalSeconds); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { //this.GraphicsDevice.Clear(Color.Lavender) drawingManager.DrawRectangle(position, new Vector2(100.0f, 100.0f), 0.7845f, Color.Red); base.Draw(gameTime); } } public class DrawingManager { private GraphicsDevice GraphicsDevice; private Effect Effect; public DrawingManager(GraphicsDevice graphicsDevice) { GraphicsDevice = graphicsDevice; this.Effect = new BasicEffect(this.GraphicsDevice) { VertexColorEnabled = true, Projection = Matrix.CreateOrthographicOffCenter(0.0f, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f) }; } private VertexPositionColor[] GetRectangleVertices (Vector2 center, Vector2 size, float radians, Color color) { var halfSize = size/2.0f; var topLeft = -halfSize; var bottomRight = halfSize; var topRight = new Vector2(bottomRight.X, topLeft.Y); var bottomLeft = new Vector2(topLeft.X, bottomRight.Y); topLeft = Vector2.Transform(topLeft, Matrix.CreateRotationZ(radians)) + center; topRight = Vector2.Transform(topRight, Matrix.CreateRotationZ(radians)) + center; bottomRight = Vector2.Transform(bottomRight, Matrix.CreateRotationZ(radians)) + center; bottomLeft = Vector2.Transform(bottomLeft, Matrix.CreateRotationZ(radians)) + center; return new VertexPositionColor[] { new VertexPositionColor(new Vector3(topLeft, 0.0f), color), new VertexPositionColor(new Vector3(topRight, 0.0f), color), new VertexPositionColor(new Vector3(topRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color), new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color), new VertexPositionColor(new Vector3(topLeft, 0.0f), color) }; } public void DrawRectangle(Vector2 center, Vector2 size, float radians, Color color) { var vertices = GetRectangleVertices(center, size, radians, color); foreach (var pass in this.Effect.CurrentTechnique.Passes) { pass.Apply(); this.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, vertices.Length/2); } } } F#: namespace Flocking module FlockingProgram = open System open Flocking [<STAThread>] [<EntryPoint>] let Main _ = use g = new FlockGame() g.Run() 0 //------------------------------------------------------------------------------ namespace Flocking open System open System.Diagnostics open Microsoft.Xna.Framework open Microsoft.Xna.Framework.Graphics open Microsoft.Xna.Framework.Input type public FlockGame() as this = inherit Game() let mutable graphics = new GraphicsDeviceManager(this) let mutable drawingManager = null let mutable position = Vector2.Zero override Game.LoadContent() = drawingManager <- new Rendering.DrawingManager(graphics.GraphicsDevice) this.IsFixedTimeStep <- false override Game.Update gameTime = position <- Vector2(position.X + 50.1f * float32 gameTime.ElapsedGameTime.TotalSeconds, position.Y + 50.1f * float32 gameTime.ElapsedGameTime.TotalSeconds) base.Update gameTime override Game.Draw gameTime = //this.GraphicsDevice.Clear(Color.Lavender) Rendering.DrawRectangle(drawingManager, position, Vector2(100.0f, 100.0f), 0.7845f, Color.Red) base.Draw gameTime //------------------------------------------------------------------------------ namespace Flocking open System open System.Collections.Generic open Microsoft.Xna.Framework open Microsoft.Xna.Framework.Graphics open Microsoft.Xna.Framework.Input module Rendering = [<AllowNullLiteral>] type DrawingManager (graphicsDevice : GraphicsDevice) = member this.GraphicsDevice = graphicsDevice member this.Effect = new BasicEffect(this.GraphicsDevice, VertexColorEnabled = true, Projection = Matrix.CreateOrthographicOffCenter(0.0f, float32 this.GraphicsDevice.Viewport.Width, float32 this.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f)) let private GetRectangleVertices (center:Vector2, size:Vector2, radians:float32, color:Color) = let halfSize = size / 2.0f let mutable topLeft = -halfSize let mutable bottomRight = halfSize let mutable topRight = new Vector2(bottomRight.X, topLeft.Y) let mutable bottomLeft = new Vector2(topLeft.X, bottomRight.Y) topLeft <- Vector2.Transform(topLeft, Matrix.CreateRotationZ(radians)) + center topRight <- Vector2.Transform(topRight, Matrix.CreateRotationZ(radians)) + center bottomRight <- Vector2.Transform(bottomRight, Matrix.CreateRotationZ(radians)) + center bottomLeft <- Vector2.Transform(bottomLeft, Matrix.CreateRotationZ(radians)) + center [| new VertexPositionColor(new Vector3(topLeft, 0.0f), color) new VertexPositionColor(new Vector3(topRight, 0.0f), color) new VertexPositionColor(new Vector3(topRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color) new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color) new VertexPositionColor(new Vector3(topLeft, 0.0f), color) |] let DrawRectangle (drawingManager:DrawingManager, center:Vector2, size:Vector2, radians:float32, color:Color) = let vertices = GetRectangleVertices(center, size, radians, color) for pass in drawingManager.Effect.CurrentTechnique.Passes do pass.Apply() drawingManager.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, vertices.Length/2)

    Read the article

  • Microsoft® MVP (Most Valuable Professional) in XNA / DirectX.

    - by uditha
    I got an email form Microsoft saying that i have been selected for MVP in XNA/DirectX category. It was really memorable moment for me.And proud to be a Microsoft MVP. There are now total 44 MVPs for XNA/DirectX. https://mvp.support.microsoft.com/communities/mvp.aspx?product=1&competency=XNA%2fDirectX About MVP Program. https://mvp.support.microsoft.com/gp/aboutmvp My MVP Profile. https://mvp.support.microsoft.com/profile/Uditha Official SEA MVP blog. http://seamvpblogaholic.spaces.live.com/default.aspx

    Read the article

  • Anyone can suggest some Game Frameworks for GNU/Linux? [closed]

    - by dysoco
    So I've been developing a little bit with XNA + C# in Windows, not really much: just some 2D stuff, but I've found that XNA is a really good framework. I'm a GNU/Linux user, and I'm definitely migrating my desktop to Gentoo Linux (I've been using Arch in my laptop for a while now). But, of course, I need a C# + XNA alternative... I'm not really an expert in any language, so I can really pick up anything (except, maybe, Functional ones), I prefer C-Like languages like Java or Ruby, I tried Python but found the Whitespace syntax confusing. I would like to hear some of you'r suggestions, I'm not asking for "the best", but for "some suggestions", so I think this is objective enough. Probably you're going to suggest C++ + SDL, but I would prefer something more "High Level" like XNA, but I'm open to discuss anything. So... any ideas ? Note: I think this questions meets the guidelines for this site, if it doesn't: please not only downvote this question, but comment on what can I do to improve it. Thanks. PS: 2D Games, not 3D

    Read the article

  • Separate collision mesh model?

    - by Menno Gouw
    I want to have another go at 3D within XNA. What I have seen from some other games that they just have a separate very low poly model "cage" around the environment model. However I can not find any reference to this. I have not that much experience with XNA 3D either. Is it possible to have this cage within each of my environmental models already? Lets just say I call the mesh within the .FBX wall and col_wall. How would I call to these different meshes within XNA? The player would just have a tight collision cube around. To make it a bit more efficient I will be making divide the map up by cubes and only calculate collision if the player is in it. Question two: I can't find anywhere to do cube vs mesh collision. Is there a method for this? Or perhaps it is possible to build my collision cage out of cubes in the 3D app and on loading of the models in XNA replace them directly by cubes? So I could just do box to box collision which should be very cheap and still give the player the ability to move over ledges on the static models.

    Read the article

  • Client and Server game update speed

    - by user20686
    I am working on a simple two player networked asteroids game using XNA and the Lidgren networking library. For this set up I have a Lidgren server maintaining what I want to be the true state of the game, and the XNA game is the Lidgren client. The client sends key inputs to the server, and the server process the key inputs against game logic, sending back updates. (This seemed like a better idea then sending local positions to the server.) The client also processes the key inputs on its own, so as to not have any visible lag, and then interpolates between the local position and remote position. Based on what I have been reading this is the correct way to smooth out a networked game. The only thing I don’t get is what value to use as the time deltas. Currently every message the server sends it also sends a delta-time update with it, which is time between the last update. The client then saves this delta time to use for its local position updates, so they can be using roughly the same time deltas to calculate position updates. I know the XNA game update gets called 60 times a second, so I set my server to update the game state at the same speed. This will probably only work as long as the game is working on a fixed time step and will probably cause problems if I want to change that in the future. The server sends updates to clients on another thread, which runs at 10 updates per second to cut down on bandwidth. I do not see noticeable lag in movement and over time if no user input is received the local and remote positions converge on each other as they should. I am also not currently calculating for any latency as I am trying to go one step at a time. So my question is should the XNA client be using its current game time to update the local game state and not being using time deltas sent by the server? If I should be using the clients time delta between updates how do I keep it in-line with how fast the server is updating its game state?

    Read the article

  • Windows Phone 7 Silverlight / XNA development talk

    - by subodhnpushpak
    Hi, I presented on Windows Phone 7 app development using Silverlight. Here are few pics from the event Windows Phone 7 development VIEW SLIDE SHOW DOWNLOAD ALL     I demonstrated the Visual studio, emulator capabilities/ features. An demo on Wp7 app communication with an OData Service, along with a demo on XNA app. There was lot of curious questions; I am listing them here because these keep on popping up again and again: 1. What tools does it takes to develop Wp7 app? Are they free? A typical WP7 app can be developed either using Silverlight or XNA. For developers, Visual Studio 2010 is a good choice as it provides an integrated development environment with lots of useful project templates; which makes the task really easy. For designers, Blend may be used to develop the UI in XAML. Both the tools are FREE (express version) to download and very intuitive to use. 2. What about the learning curve? If you know C#, (or any other programming language), learning curve is really flat. XAML (used for UI) may be new for you, but trust me; its very intuitive. Also you can use Microsoft Blend to generate the UI (XAML) for you. 3. How can I develop /test app without using actual device? How can I be sure my app runs as expected on actual device? The WP7 SDK comes along with an excellent emulator; which you can use for development/ testing on a computer. Later you can just change a setting and deploy the application on WP7. You will require Zune software for deploying the application on phone along with Developers key from WP7 marketplace. You can obtain key from marketplace by filling a form. The whole process for registering  is easy; just follow the steps on the site. 4. Which one should I use? Silverlight or XNA? Use Silverlight for enterprise/ business / utility apps. Use XNA for Games app. While each platform is capable / strong and may be used in conjunction as well; The methodologies used for development in these platforms are very different. XNA works on typical Do..While loop where as Silverlight works on event based methodology. 5. Where are the learning resources? Are they free? There is lots of stuff on WP7. Most of them are free. There is a excellent free book by Charles Petzold to download and http://www.microsoft.com/windowsphone is full of demos /todos / vidoes. All the exciting stuff was captured live and you can view it here; in case you were not able to catch it live!! @ http://livestre.am/AUfx. My talk starts from 3:19:00 timeline in the video!! Is there an app you miss on WP7? Do let me know about it and I may work on it for free !!! Keep discovering. Keep is Simple. WP7. Subodh

    Read the article

  • XNA RenderTarget2D Sample

    - by Michael B. McLaughlin
    I remember being scared of render targets when I first started with XNA. They seemed like weird magic and I didn’t understand them at all. There’s nothing to be frightened of, though, and they are pretty easy to learn how to use. The first thing you need to know is that when you’re drawing in XNA, you aren’t actually drawing to the screen. Instead you’re drawing to this thing called the “back buffer”. Internally, XNA maintains two sections of graphics memory. Each one is exactly the same size as the other and has all the same properties (such as surface format, whether there’s a depth buffer and/or a stencil buffer, and so on). XNA flips between these two sections of memory every update-draw cycle. So while you are drawing to one, it’s busy drawing the other one on the screen. Then the current update-draw cycle ends, it flips, and the section you were just drawing to gets drawn to the screen while the one that was being drawn to the screen before is now the one you’ll be drawing on. This is what’s meant by “double buffering”. If you drew directly to the screen, the player would see all of those draws taking place as they happened and that would look odd and not very good at all. Those two sections of graphics memory are render targets. All a render target is, is a section of graphics memory to which things can be drawn. In addition to the two that XNA maintains automatically, you can also create and set your own using RenderTarget2D and GraphicsDevice.SetRenderTarget. Using render targets lets you do all sorts of neat post-processing effects (like bloom) to make your game look cooler. It also just lets you do things like motion blur and lets you create mirrors in 3D games. There are quite a lot of things that render targets let you do. To go along with this post, I wrote up a simple sample for how to create and use a RenderTarget2D. It’s available under the terms of the Microsoft Public License and is available for download on my website here: http://www.bobtacoindustries.com/developers/utils/RenderTarget2DSample.zip . Other than the ‘using’ statements, every line is commented in detail so that it should (hopefully) be easy to follow along with and understand. If you have any questions, leave a comment here or drop me a line on Twitter. One last note. While creating the sample I came across an interesting quirk. If you start by creating a Windows Game, and then make a copy for Windows Phone 7, the drop-down that lets you choose between drawing to a WP7 device and the WP7 emulator stays grayed-out. To resolve this, you need to right click on the Windows Phone 7 version in the Solution Explorer, and choose “Set as StartUp Project”. The bar will then become active, letting you change the target you which to deploy to. If you want another version to be the one that starts up when you press F5 to start debugging, just go and right-click on that version and choose “Set as StartUp Project” for it once you’ve set the WP7 target (device or emulator) that you want.

    Read the article

  • Drawing simple geometric figures with DrawUserPrimitives?

    - by Navy Seal
    I'm trying to draw a simple triangle based on an array of vertex. I've been searching for a tutorial and I found a simple example on riemers but I couldn't get it to work. I think it was made for XNA 3 and it seems there were some changes to XNA 4? Using this example: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/The_first_triangle.php I get this error: Additional information: The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing. I'm not english so I'm having some trouble to understand everything. For what I understand error is confusing because I'm trying to draw a triangle color based and not texture based and it shouldn't need a texture. Also I saw some articles about dynamic shadows and lights and I would like to know if this is the kind of code used to do it with some tweaks like culling because I'm wondering if its heavy code for performance in real time.

    Read the article

  • Creating a new instance, C#

    - by Dave Voyles
    This sounds like a very n00b question, but bear with me here: I'm trying to access the position of my bat (paddle) in my pong game and use it in my ball class. I'm doing this because I want a particle effect to go off at the point of contact where the ball hits the bat. Each time the ball hits the bat, I receive an error stating that I haven't created an instance of the bat. I understand that I have to (or can use a static class), but I'm not sure of how to do so in this example. I've included both my Bat and Ball classes. namespace Pong { #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; #endregion public class Ball { #region Fields private readonly Random rand; private readonly Texture2D texture; private readonly SoundEffect warp; private double direction; private bool isVisible; private float moveSpeed; private Vector2 position; private Vector2 resetPos; private Rectangle size; private float speed; private bool isResetting; private bool collided; private Vector2 oldPos; private ParticleEngine particleEngine; private ContentManager contentManager; private SpriteBatch spriteBatch; private bool hasHitBat; private AIBat aiBat; private Bat bat; #endregion #region Constructors and Destructors /// <summary> /// Constructor for the ball /// </summary> public Ball(ContentManager contentManager, Vector2 ScreenSize) { moveSpeed = 15f; speed = 0; texture = contentManager.Load<Texture2D>(@"gfx/balls/redBall"); direction = 0; size = new Rectangle(0, 0, texture.Width, texture.Height); resetPos = new Vector2(ScreenSize.X / 2, ScreenSize.Y / 2); position = resetPos; rand = new Random(); isVisible = true; hasHitBat = false; // Everything to do with particles List<Texture2D> textures = new List<Texture2D>(); textures.Add(contentManager.Load<Texture2D>(@"gfx/particle/circle")); textures.Add(contentManager.Load<Texture2D>(@"gfx/particle/star")); textures.Add(contentManager.Load<Texture2D>(@"gfx/particle/diamond")); particleEngine = new ParticleEngine(textures, new Vector2()); } #endregion #region Public Methods and Operators /// <summary> /// Checks for the collision between the bat and the ball. Sends ball in the appropriate /// direction /// </summary> public void BatHit(int block) { if (direction > Math.PI * 1.5f || direction < Math.PI * 0.5f) { hasHitBat = true; particleEngine.EmitterLocation = new Vector2(aiBat.Position.X, aiBat.Position.Y); switch (block) { case 1: direction = MathHelper.ToRadians(200); break; case 2: direction = MathHelper.ToRadians(195); break; case 3: direction = MathHelper.ToRadians(180); break; case 4: direction = MathHelper.ToRadians(180); break; case 5: direction = MathHelper.ToRadians(165); break; } } else { hasHitBat = true; particleEngine.EmitterLocation = new Vector2(bat.Position.X, bat.Position.Y); switch (block) { case 1: direction = MathHelper.ToRadians(310); break; case 2: direction = MathHelper.ToRadians(345); break; case 3: direction = MathHelper.ToRadians(0); break; case 4: direction = MathHelper.ToRadians(15); break; case 5: direction = MathHelper.ToRadians(50); break; } } if (rand.Next(2) == 0) { direction += MathHelper.ToRadians(rand.Next(3)); } else { direction -= MathHelper.ToRadians(rand.Next(3)); } AudioManager.Instance.PlaySoundEffect("hit"); } /// <summary> /// JEP - added method to slow down ball after powerup deactivates /// </summary> public void DecreaseSpeed() { moveSpeed -= 0.6f; } /// <summary> /// Draws the ball on the screen /// </summary> public void Draw(SpriteBatch spriteBatch) { if (isVisible) { spriteBatch.Begin(); spriteBatch.Draw(texture, size, Color.White); spriteBatch.End(); // Draws sprites for particles when contact is made particleEngine.Draw(spriteBatch); } } /// <summary> /// Checks for the current direction of the ball /// </summary> public double GetDirection() { return direction; } /// <summary> /// Checks for the current position of the ball /// </summary> public Vector2 GetPosition() { return position; } /// <summary> /// Checks for the current size of the ball (for the powerups) /// </summary> public Rectangle GetSize() { return size; } /// <summary> /// Grows the size of the ball when the GrowBall powerup is used. /// </summary> public void GrowBall() { size = new Rectangle(0, 0, texture.Width * 2, texture.Height * 2); } /// <summary> /// Was used to increased the speed of the ball after each point is scored. /// No longer used, but am considering implementing again. /// </summary> public void IncreaseSpeed() { moveSpeed += 0.6f; } /// <summary> /// Check for the ball to return normal size after the Powerup has expired /// </summary> public void NormalBallSize() { size = new Rectangle(0, 0, texture.Width, texture.Height); } /// <summary> /// Check for the ball to return normal speed after the Powerup has expired /// </summary> public void NormalSpeed() { moveSpeed += 15f; } /// <summary> /// Checks to see if ball went out of bounds, and triggers warp sfx /// </summary> public void OutOfBounds() { // Checks if the player is still alive or not if (isResetting) { AudioManager.Instance.PlaySoundEffect("warp"); { // Used to stop the the issue where the ball hit sfx kept going off when detecting collison isResetting = false; AudioManager.Instance.Dispose(); } } } /// <summary> /// Speed for the ball when Speedball powerup is activated /// </summary> public void PowerupSpeed() { moveSpeed += 20.0f; } /// <summary> /// Check for where to reset the ball after each point is scored /// </summary> public void Reset(bool left) { if (left) { direction = 0; } else { direction = Math.PI; } // Used to stop the the issue where the ball hit sfx kept going off when detecting collison isResetting = true; position = resetPos; // Resets the ball to the center of the screen isVisible = true; speed = 15f; // Returns the ball back to the default speed, in case the speedBall was active if (rand.Next(2) == 0) { direction += MathHelper.ToRadians(rand.Next(30)); } else { direction -= MathHelper.ToRadians(rand.Next(30)); } } /// <summary> /// Shrinks the ball when the ShrinkBall powerup is activated /// </summary> public void ShrinkBall() { size = new Rectangle(0, 0, texture.Width / 2, texture.Height / 2); } /// <summary> /// Stops the ball each time it is reset. Ex: Between points / rounds /// </summary> public void Stop() { isVisible = true; speed = 0; } /// <summary> /// Updates position of the ball /// </summary> public void UpdatePosition() { size.X = (int)position.X; size.Y = (int)position.Y; oldPos.X = position.X; oldPos.Y = position.Y; position.X += speed * (float)Math.Cos(direction); position.Y += speed * (float)Math.Sin(direction); bool collided = CheckWallHit(); particleEngine.Update(); // Stops the issue where ball was oscillating on the ceiling or floor if (collided) { position.X = oldPos.X + speed * (float)Math.Cos(direction); position.Y = oldPos.Y + speed * (float)Math.Sin(direction); } } #endregion #region Methods /// <summary> /// Checks for collision with the ceiling or floor. 2*Math.pi = 360 degrees /// </summary> private bool CheckWallHit() { while (direction > 2 * Math.PI) { direction -= 2 * Math.PI; return true; } while (direction < 0) { direction += 2 * Math.PI; return true; } if (position.Y <= 0 || (position.Y > resetPos.Y * 2 - size.Height)) { direction = 2 * Math.PI - direction; return true; } return true; } #endregion } } namespace Pong { using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; public class Bat { public Vector2 Position; public float moveSpeed; public Rectangle size; private int points; private int yHeight; private Texture2D leftBat; public float turbo; public float recharge; public float interval; public bool isTurbo; /// <summary> /// Constructor for the bat /// </summary> public Bat(ContentManager contentManager, Vector2 screenSize, bool side) { moveSpeed = 7f; turbo = 15f; recharge = 100f; points = 0; interval = 5f; leftBat = contentManager.Load<Texture2D>(@"gfx/bats/batGrey"); size = new Rectangle(0, 0, leftBat.Width, leftBat.Height); // True means left bat, false means right bat. if (side) Position = new Vector2(30, screenSize.Y / 2 - size.Height / 2); else Position = new Vector2(screenSize.X - 30, screenSize.Y / 2 - size.Height / 2); yHeight = (int)screenSize.Y; } public void IncreaseSpeed() { moveSpeed += .5f; } /// <summary> /// The speed of the bat when Turbo is activated /// </summary> public void Turbo() { moveSpeed += 8.0f; } /// <summary> /// Returns the speed of the bat back to normal after Turbo is deactivated /// </summary> public void DisableTurbo() { moveSpeed = 7.0f; isTurbo = false; } /// <summary> /// Returns the bat to the nrmal size after the Grow/Shrink powerup has expired /// </summary> public void NormalSize() { size = new Rectangle(0, 0, leftBat.Width, leftBat.Height); } /// <summary> /// Checks for the size of the bat /// </summary> public Rectangle GetSize() { return size; } /// <summary> /// Adds point to the player or the AI after scoring. Currently Disabled. /// </summary> public void IncrementPoints() { points++; } /// <summary> /// Checks for the number of points at the moment /// </summary> public int GetPoints() { return points; } /// <summary> /// Sets thedefault starting position for the bats /// </summary> /// <param name="position"></param> public void SetPosition(Vector2 position) { if (position.Y < 0) { position.Y = 0; } if (position.Y > yHeight - size.Height) { position.Y = yHeight - size.Height; } this.Position = position; } /// <summary> /// Checks for the current position of the bat /// </summary> public Vector2 GetPosition() { return Position; } /// <summary> /// Controls the bat moving up the screen /// </summary> public void MoveUp() { SetPosition(Position + new Vector2(0, -moveSpeed)); } /// <summary> /// Controls the bat moving down the screen /// </summary> public void MoveDown() { SetPosition(Position + new Vector2(0, moveSpeed)); } /// <summary> /// Updates the position of the AI bat, in order to track the ball /// </summary> /// <param name="ball"></param> public virtual void UpdatePosition(Ball ball) { size.X = (int)Position.X; size.Y = (int)Position.Y; } /// <summary> /// Resets the bat to the center location after a new game starts /// </summary> public void ResetPosition() { SetPosition(new Vector2(GetPosition().X, yHeight / 2 - size.Height)); } /// <summary> /// Used for the Growbat powerup /// </summary> public void GrowBat() { // Doubles the size of the bat collision size = new Rectangle(0, 0, leftBat.Width * 2, leftBat.Height * 2); } /// <summary> /// Used for the Shrinkbat powerup /// </summary> public void ShrinkBat() { // 1/2 the size of the bat collision size = new Rectangle(0, 0, leftBat.Width / 2, leftBat.Height / 2); } /// <summary> /// Draws the bats /// </summary> public virtual void Draw(SpriteBatch batch) { batch.Draw(leftBat, size, Color.White); } } }

    Read the article

  • Can't load vector font in Nuclex Framework

    - by ProgrammerAtWork
    I've been trying to get this to work for the last 2 hours and I'm not getting what I'm doing wrong... I've added Nuclex.TrueTypeImporter to my references in my content and I've added Nuclex.Fonts & Nuclex.Graphics in my main project. I've put Arial-24-Vector.spritefont & Lindsey.spritefont in the root of my content directory. _spriteFont = Content.Load<SpriteFont>("Lindsey"); // works _testFont = Content.Load<VectorFont>("Arial-24-Vector"); // crashes I get this error on the _testFont line: File contains Microsoft.Xna.Framework.Graphics.SpriteFont but trying to load as Nuclex.Fonts.VectorFont. So I've searched around and by the looks of it it has something to do with the content importer & the content processor. For the content importer I have no new choices, so I leave it as it is, Sprite Font Description - XNA Framework for content processor and I select Vector Font - Nuclex Framework And then I try to run it. _testFont = Content.Load<VectorFont>("Arial-24-Vector"); // crashes again I get the following error Error loading "Arial-24-Vector". It does work if I load a sprite, so it's not a pathing problem. I've checked the samples, they do work, but I think they also use a different version of the XNA framework because in my version the "Content" class starts with a capital letter. I'm at a loss, so I ask here. Edit: Something super weird is going on. I've just added the following two lines to a method inside FreeTypeFontProcessor::FreeTypeFontProcessor( Microsoft::Xna::Framework::Content::Pipeline::Graphics::FontDescription ^fontDescription, FontHinter hinter, just to check if code would even get there: System::Console::WriteLine("I AM HEEREEE"); System::Console::ReadLine(); So, I compile it, put it in my project, I run it and... it works! What the hell?? This is weird because I've downloaded the binaries, they didn't work, I've compiled the binaries myself. didn't work either, but now I make a small change to the code and it works? _. So, now I remove the two lines, compile it again and it works again. Someone care to elaborate what is going on? Probably some weird caching problem!

    Read the article

  • If I use my own normal values, should I turn off winding order culling?

    - by Phil
    I've discovered that I managed to program a series of boxes with indexed vertices in such a way that every other triangle (Half of each face) has a backwards winding order. As a result, XNA is culling half of them. However, my Vertex objects contain normal data that I have explicitly set, and I am going to implement my own backface culling shortly to reduce the size of the VertexBuffer. Should I turn off winding order culling and manage it myself, or should I make sure the winding order is consistent and let XNA handle it?

    Read the article

  • Managed game frameworks with Model loading support [on hold]

    - by codymanix
    Iam looking for an alternative to XNA with support of model loading. Does anybody know when/if there if a MonoGame release is planned which includes its own content pipeline which works without XNA beeing installed? If not, what are the alternatives in managed game development? As far as I know, SlimDX and SharpDX on its own brings no functionality for loading models. Are there any open source libraries that can do that?

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >