I'm a newbie...please be kind. I am new to coding and starting out by creating a very simple platform game.
So far all has gone well but I need to keep my Player within the bounds of the screen and struggling with the code.
Player.Left and Player.Top are working fine but I cannot figure out how to stop him flying off the right edge.
Here is my code
if (Player.Left < 1 || Player.Left + Player.Width > ClientSize.Width - 2)
{
Player.Left = -Player.Left;
}
if (Player.Top < 1 || Player.Top + Player.Height > ClientSize.Height - 2)
{
Player.Top = -Player.Top;
}
if (Player.Right > 1 || Player.Right + Player.Width > ClientSize.Width - 2)
{
Player.Right = -Player.Right;
}
I keep getting the error on Player.Right Property or indexer 'property' cannot be assigned to -- it is read only
I've searched everywhere and tried all sorts of different ways to code this but I cannot get it to work. Have I done something really stupid and obvious?