Now for some reason the walls in my game have become see-through and don't load their pixels well. They give the following effect:
Top left has the texture and the rest is all drawn out, as if somebody spilled a bottle of water over some ink. Can someone please help me locate the problem?
Here's the coding:
So this is the class which contains my Wall
Now here I have my wallmanager
Top left has the texture and the rest is all drawn out, as if somebody spilled a bottle of water over some ink. Can someone please help me locate the problem?
Here's the coding:
So this is the class which contains my Wall
Code:
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;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace DoomTargetPractice
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class Wall : Microsoft.Xna.Framework.DrawableGameComponent
{
BasicEffect effect;
VertexPositionTexture[] vertices;
VertexBuffer vertexBuffer;
Vector3 position;
Texture2D texture;
float width;
float height;
float depth;
public Wall(Game game, Texture2D texture, BasicEffect effect, Vector3 position, float width, float height, float depth)
: base(game)
{
this.texture = texture;
this.position = position;
this.height = height;
this.width = width;
this.depth = depth;
this.effect = effect;
CreateVertices();
Initialize();
}
private void CreateVertices()
{
const int bricksize = 4;
Vector2 upleft1;
Vector2 upright1;
Vector2 downleft1;
Vector2 downleft2;
Vector2 upright2;
Vector2 downright2;
Vector3 baseVector1 = position;
Vector3 baseVector2 = new Vector3(position.X, position.Y, position.Z - depth);
Vector3 baseVector3 = new Vector3(position.X + width, position.Y, position.Z - depth);
Vector3 baseVector4 = new Vector3(position.X + width, position.Y, position.Z);
Vector3 topVector1 = new Vector3(position.X, position.Y + height, position.Z);
Vector3 topVector2 = new Vector3(position.X, position.Y + height, position.Z - depth);
Vector3 topVector3 = new Vector3(position.X + width, position.Y + height, position.Z - depth);
Vector3 topVector4 = new Vector3(position.X + width, position.Y + height, position.Z);
// muur bestaat uit 8 driehoeken (8 x 3 = 24 punten)
vertices = new VertexPositionTexture[24];
upleft1 = new Vector2(0, 0);
upright1 = new Vector2(width / bricksize, 0);
downleft1 = new Vector2(0, height / bricksize);
downleft2 = new Vector2(0, (height % bricksize) / bricksize);
upright2 = new Vector2(width / bricksize, ((height % bricksize) - height) / bricksize);
downright2 = new Vector2(width / bricksize, (height % bricksize) / bricksize);
// voorkant
// eerste driehoek
vertices[0] = new VertexPositionTexture(topVector1, upleft1);
vertices[1] = new VertexPositionTexture(topVector4, upright1);
vertices[2] = new VertexPositionTexture(baseVector1, downleft1);
// tweede driehoek
vertices[3] = new VertexPositionTexture(baseVector1, downleft2);
vertices[4] = new VertexPositionTexture(topVector4, upright2);
vertices[5] = new VertexPositionTexture(baseVector4, downright2);
// achterkant
// eerste driehoek
vertices[6] = new VertexPositionTexture(topVector3, upleft1);
vertices[7] = new VertexPositionTexture(topVector2, upright1);
vertices[8] = new VertexPositionTexture(baseVector3, downleft1);
// tweede driehoek
vertices[9] = new VertexPositionTexture(baseVector3, downleft2);
vertices[10] = new VertexPositionTexture(topVector2, upright2);
vertices[11] = new VertexPositionTexture(baseVector2, downright2);
upleft1 = new Vector2(0, 0);
upright1 = new Vector2(depth / bricksize, 0);
downleft1 = new Vector2(0, height / bricksize);
downleft2 = new Vector2(0, (height % bricksize) / bricksize);
upright2 = new Vector2(depth / bricksize, ((height % bricksize) - height) / bricksize);
downright2 = new Vector2(depth / bricksize, (height % bricksize) / bricksize);
// zijkant rechts
// eerste driehoek
vertices[12] = new VertexPositionTexture(topVector4, upleft1);
vertices[13] = new VertexPositionTexture(topVector3, upright1);
vertices[14] = new VertexPositionTexture(baseVector4, downleft1);
// tweede driehoek
vertices[15] = new VertexPositionTexture(baseVector4, downleft2);
vertices[16] = new VertexPositionTexture(topVector3, upright2);
vertices[17] = new VertexPositionTexture(baseVector3, downright2);
// zijkant links
// eerste driehoek
vertices[18] = new VertexPositionTexture(topVector2, upleft1);
vertices[19] = new VertexPositionTexture(topVector1, upright1);
vertices[20] = new VertexPositionTexture(baseVector2, downleft1);
// tweede driehoek
vertices[21] = new VertexPositionTexture(baseVector2, downleft2);
vertices[22] = new VertexPositionTexture(topVector1, upright2);
vertices[23] = new VertexPositionTexture(baseVector1, downright2);
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
base.Initialize();
vertexBuffer = new VertexBuffer(GraphicsDevice,
VertexPositionTexture.SizeInBytes * vertices.Length,
BufferUsage.WriteOnly);
vertexBuffer.SetData<VertexPositionTexture>(vertices, 0, vertices.Length);
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
effect.TextureEnabled = true;
effect.World = Matrix.Identity;
effect.View = Camera.ActiveCamera.View;
effect.Projection = Camera.ActiveCamera.Projection;
effect.Texture = texture;
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
// graphicsDevice vertellen dat we vertices met texture gebruiken
GraphicsDevice.VertexDeclaration = new
VertexDeclaration(GraphicsDevice,
VertexPositionTexture.VertexElements);
GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionTexture.SizeInBytes);
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 8);
pass.End();
}
effect.End();
}
public Boolean IsCollision(BoundingSphere cameraSphere)
{
BoundingBox wallBox = new BoundingBox(new Vector3(position.X, position.Y, position.Z - depth), new Vector3(position.X + width, position.Y + height, position.Z));
if (cameraSphere.Intersects(wallBox))
{
return true;
}
else
{
return false;
}
}
}
}
Now here I have my wallmanager
Code:
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;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace DoomTargetPractice
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class WallManager : Microsoft.Xna.Framework.DrawableGameComponent
{
protected List<Wall> walls;
public WallManager(Game game)
: base(game)
{
walls = new List<Wall>();
}
public void Add(Wall wall)
{
walls.Add(wall);
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
for (int i = 0; i < walls.Count; i++)
{
walls[i].Initialize();
}
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
for (int i = 0; i < walls.Count; i++)
{
walls[i].Update(gameTime);
}
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
for (int i = 0; i < walls.Count; i++)
{
walls[i].Draw(gameTime);
}
}
public Boolean IsCollision(BoundingSphere cameraSphere)
{
foreach (Wall wall in walls)
{
if (wall.IsCollision(cameraSphere))
{
return true;
}
}
return false;
}
}
}







