Here's my code:
#include "raylib.h"
#include "raymath.h"
#include <iostream>
#include "rlgl.h"
#define SCREEN_WIDTH 600
#define SCREEN_HEIGHT 600
#define SPACESHIP_WIDTH 221
#define SPACESHIP_HEIGHT 289
Texture2D spaceship;
int main() {
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "New Game");
SetWindowMinSize(320, 240);
SetTargetFPS(60);
spaceship = LoadTexture("/home/thanos/Downloads/ship.png");
Rectangle source = (Rectangle){0,0, SPACESHIP_WIDTH, SPACESHIP_HEIGHT};
Rectangle destination = (Rectangle){SCREEN_WIDTH/2, SCREEN_HEIGHT/2, source.width/2, source.height/2};
Vector2 spaceshipPosition = (Vector2){destination.width/2, destination.height/2};
float spaceshipRotation = 15.0f;
while(!WindowShouldClose()){
Vector2 mouse = GetMousePosition();
BeginDrawing();
ClearBackground(LIGHTGRAY);
DrawTexturePro(spaceship, source, destination, spaceshipPosition, spaceshipRotation * GetTime(), WHITE);
DrawLineV((Vector2){300, 300}, spaceshipPosition, BLACK);
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 400, 25, 20, RED);
DrawText(TextFormat("[Ship position] X: [%i] Y: [%i]", (int)spaceshipPosition.x, (int)spaceshipPosition.y), 400, 40, 20, RED);
EndMode2D();
EndDrawing();
}
CloseWindow();
return 0;
}
I have also drawn a line from the center of the window to the spaceship location, and as you can see it's also not working as expected. There are 2 possibilities:
- Either the code to show the coordinates of the mouse and the texture is wrong.
- Or something is wrong with the actual png of the texture. I can upload the spaceship.png too if needed, but it's 221x289 pixels.

spaceshipPositionis not named correctly. It is in fact the origin of the sprite local to the sprite. Your actual center of the spaceship is at {destination.x - source.x, destination.y - source.y}, which should indeed be {300, 300}.This is plain to see in the implementation of this function: