HI everyone, there’s my code for following the player by camera, but when i try to update the camera in game1.cs Update, it crashes with System.NullReferenceException: Object reference not set to an instance of an object. Here’s the code for my Camera.cs, hracX and hracY mean the player’s position.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TerraWorld
{
class Camera
{
public Matrix transform;
Viewport view;
Vector2 centre;
public Camera(Viewport newView)
{
view = newView;
}
public void Update(GameTime gameTime, int hracX, int hracY)
{
centre = new Vector2(hracX + (32 / 2) - 400, hracY + (32 / 2) - 400);
transform = Matrix.CreateScale(new Vector3(1, 1, 0)) *
Matrix.CreateTranslation(new Vector3(-centre.X, -centre.Y, 0));
}
}
}
and here’s how i update the camera kamera.Update(gameTime, hracX, hracY);
,but for unkown reason it doesnt works, on XNA it worked.
Thanks for solution.