Writing C++ in C Weird Behaviors

Hey, has anyone else had weird behaviors, or errors converting c++ expressions inside c inside ray? For example when going through the examples::

player.position = (Vector2) { screenWidth / 2, screenHeight * 7 / 8 };
player.speed = (Vector2) { 8.0f, 0.0f };
player.size = (Vector2) { 100, 24 };

In visual studio I get errors "Expected an expression"

So I decided to use the c++ way, which is initializing my structures first, and assigning them to a obj like so::

Vector2 v1 { screenWidth / 2, screenHeight * 7 / 8 };
Vector2 v2{ 8.0f, 0.0f };
Vector2 v3 { 100, 24 };
player.position =v1;
player.speed = v2;
player.size = v3;

And the errors disappear, but the program dosen't look right, or in my case the blocks challenge, the blocks are not aligning correctly. Is there any other way I can use c++ inside this c code?? Thanks

Comments

  • You should use:
    Vector2 v1 = { screenWidth / 2, screenHeight * 7 / 8 };
    Vector2 v2 = { 8.0f, 0.0f };
    Vector2 v3 = { 100, 24 };
  • edited December 2017
    Wow quick response!. Probably one of the best game libraries I've come across as im learning c++ game development. Thanks Ray!!
Sign In or Register to comment.