I’m making my way through the beginners tutorials for XNA (C#) and have veered off in my own direction once I learned rendering and positioning, having my own game development experience.
I’m trying to make a property VelocityY on my class Ship. I want to be able to increment this value by values that are decimal, ie:
VelocityY += 0.45;
I figured that float was the type required here, but when I try compile I get this error:
Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type.
I’m not really sure what the first part means as I haven’t made use of double as far as I know. VelocityY is declared like this:
public float VelocityY = 0;
I tried using double and even int instead but I still can’t increment by non-whole numbers. Whole numbers work fine.
The type of the literal 0.45 is
double. If you want to make it a float, use the suffixforF, like the compiler error says:Basically, if you don’t specify a suffix for a literal including a decimal point, it’s implicitly
double. You can use a suffix to make it explicit: