I'm having trouble limiting the character's movement to the edge of the screen.
In class Game1
which is my main I can use Window.ClientBounds
, but when I use this function inside class Player1
it gives the error:
'The name' Window 'does not exist in the current context' '.
Code snippet of class Player1
:
public void Update(GameTime gameTime)
{
position += velocity;
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
velocity.Y = -3f;
if (position.Y + texture.Height > (Game as Game1).Window.ClientBounds.Height)
velocity.Y += 3f;
}
...
}
When I use (Game as Game1)
I can use Window.ClientBounds
, but it gives an error that says:
'Microsoft.Xna.Framework.Game' is a 'type' but is used like 'variable'