I’ve been stuck on this problem for a while now, is it just the use of GameTime instead of an integer of milis or what what?? that’s the only thing i can think of but i haven’t been able to change it yet. If something else is the problem, let me know. thanks.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace CoffinRaiders
{
internal class GraphicsNow: IGraphicsDeviceService
{
public GraphicsDevice GraphicsDevice { get; private set; }
// Not used:
public event EventHandler<EventArgs> DeviceCreated;
public event EventHandler<EventArgs> DeviceDisposing;
public event EventHandler<EventArgs> DeviceReset;
public event EventHandler<EventArgs> DeviceResetting;
public GraphicsNow(GraphicsDevice graphics)
{
this.GraphicsDevice = graphics;
}
}
public class Window : GameWindow
{
public int width;
public int height;
String title;
public override bool AllowUserResizing { get; set; }
public override Rectangle ClientBounds { get;}
public override Point Position { get; set; }
public override DisplayOrientation CurrentOrientation{ get;}
public override IntPtr Handle { get; }
public override string ScreenDeviceName{ get;}
public Window(int width, int height)
{//bool allowUserResizing, Rectangle clientBounds, Point position, DisplayOrientation orientation, IntPtr handle, string screenDeviceName
/*
AllowUserResizing.set(allowUserResizing);
bounds = clientBounds;
currentOrientation = orientation;
Position = position;
deviceName = screenDeviceName;
handle1 = handle;
*/
// this.SetSupportedOrientations(currentOrientation);
this.width = width;
this.height = height;
title = ("CoffinRaiders");
}
public override void BeginScreenDeviceChange(bool willBeFullScreen)
{
throw new NotImplementedException();
}
public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
{
throw new NotImplementedException();
}
protected override void SetSupportedOrientations(DisplayOrientation orientations)
{
throw new NotImplementedException();
}
protected override void SetTitle(string title)
{
this.title = title;
}
}
public class Game1 : Game, IDisposable
{
Texture2D player;
float playerSpeed;
Vector3 playerPosition;
private Window window;
private bool running;
private GameTime time;
private TimeSpan totalTime;
private TimeSpan timeSince;
private GraphicsDeviceManager graphics;
//private SpriteBatch spriteBatch;
private Vector3 cameraTarget;
private Vector3 cameraPosition;
private BasicEffect basicEffect;
private Matrix world;
private Matrix view;
private Matrix projection;
private VertexPositionColor[] triangleVerts;
VertexBuffer vertexBuffer;
public Game1()
{
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
GraphicsDeviceManager graphics = new GraphicsDeviceManager(this);
window = new Window(1920, 1080);
// this.window.AllowUserResizing.set(true);
GraphicsNow graphics1 = new GraphicsNow(graphics.GraphicsDevice);
graphics.PreferredBackBufferWidth = graphics.GraphicsDevice.DisplayMode.Width;
graphics.PreferredBackBufferHeight = graphics.GraphicsDevice.DisplayMode.Height;
graphics.IsFullScreen = true;
graphics.ApplyChanges();
playerPosition = new Vector3(graphics.PreferredBackBufferWidth / 2,
graphics.PreferredBackBufferHeight / 2, 0);
playerSpeed = 100f;
window.Title = "Coffin Raiders";
Content.RootDirectory = "Content";
IsMouseVisible = true;
cameraPosition = new Vector3(window.width / 2, window.height / 2, 0.0f);
cameraTarget = new Vector3(0.0f, 500.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float near = 1.0f; // the near clipping plane distance
float far = 1000f; // the far clipping plane distance
//10, 0 , 10 before
world = Matrix.CreateWorld(cameraTarget, Vector3.Forward, Vector3.Up);
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, GraphicsDevice.DisplayMode.AspectRatio, near, far);
IsFixedTimeStep = true;
basicEffect = new BasicEffect(GraphicsDevice);
basicEffect.Alpha = 1.0f;
basicEffect.VertexColorEnabled = true;
basicEffect.LightingEnabled = false;
vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 3, BufferUsage.WriteOnly);
vertexBuffer.SetData<VertexPositionColor>(triangleVerts);
time = new GameTime();
//LoadContent();
//running = true;
while (running)
{
time = new GameTime(totalTime, timeSince);
Update(time);
Draw(time);
MaxElapsedTime = totalTime - timeSince;
Console.WriteLine("Elapsed Time {0}", MaxElapsedTime.TotalMilliseconds);
// base.Initialize();
}
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
{
running = false;
Exit();
}
// TODO: Add your update logic here
var kstate = Keyboard.GetState();
if (kstate.IsKeyDown(Keys.Up) || kstate.IsKeyDown(Keys.W))
{
playerPosition.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.Down) || kstate.IsKeyDown(Keys.S))
{
playerPosition.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.Left) || kstate.IsKeyDown(Keys.A))
{
playerPosition.X -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.Right) || kstate.IsKeyDown(Keys.D))
{
playerPosition.X += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
base.Draw(gameTime);
}
protected override void LoadContent()
{
player = Content.Load<Texture2D>("player");
Model modelShip = Content.Load<Model>("Ship");
// TODO: use this.Content to load your game content here
}
protected override void Draw(GameTime gameTime)
{
String x = "ship";
Model model = Content.Load<Model>(x); ;
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.SetVertexBuffer(vertexBuffer);
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;
foreach(ModelMesh mesh in model.Meshes)
{
foreach(BasicEffect effect in mesh.Effects)
{
effect.Projection = projection;
effect.View = view;
effect.World = world;
mesh.Draw();
}
}
base.Draw(gameTime);
}
/*
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
mesh.Draw();
}
}
}*/
}
/*
*
* using var game = new CoffinRaiders.Game1();
* game.Run();
*
*
*
*/
class Program
{
static void Main(string[] args)
{
// Window window = new Window(true, new Rectangle(0, 0, 1920, 1080), new Point(0, 0), DisplayOrientation.Default, new IntPtr(0), "ASUS");
Game1 game = new Game1();
//game.Initialize();
}
}
}
I’ve tried changing a number of things but to no avail…i can’t get it to render the screen. And also i’m unsure when the Update and initialize functions get called…do these get called automatically by the program??? or do i have to specify. I seriously can’t find any information about it anywhere.