【问题标题】:Player not moving in Raylib玩家在 Raylib 中不动
【发布时间】:2022-12-16 06:55:22
【问题描述】:

在 Raylib 中,我试图让玩家角色移动,但它没有移动

我尝试过使用不同的函数,例如 KeyPressed()。这是代码(这是用 c++20 编译的):

#include <raylib.h>;

int main(){
    int camX = 0;
    int camY = 0;
    InitWindow(1080, 720, "Arachnacide");
    while(!WindowShouldClose()){
        if(IsKeyDown(KEY_W)){
            camY -= 1;
        }
        if(IsKeyDown(KEY_S)){
            camY += 1;
        }
        if(IsKeyDown(KEY_A)){
            camX += 1;
        }
        if(IsKeyDown(KEY_D)){
            camX -= 1;
        }
        BeginDrawing();
        DrawCircle(540, 360, 25, RED);
        DrawCircle(camX, camY, 25, BLUE);
        EndDrawing();
    }
}

【问题讨论】:

    标签: c++ game-development raylib game-programming


    【解决方案1】:

    每次绘制时记得清除背景。

    BeginDrawing();
    ClearBackground(RAYWHITE); // Substitute with any color you prefer
    
    ...
    
    EndDrawing();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 2023-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多