Can't render the rock!

Hi all,

I am having a bit of an issue rendering the rock in this video, not sure what I am doing wrong but I feel like I am missing something. Not seeing any errors so feels like a logic thing but not sure where I am going wrong. Any pointers would be appreciated.

main.cpp

#include "raylib.h"
#include "raymath.h"
#include "Character.h"
#include "Prop.h"

int main()
{
    // Window dimensions.
    // int windowDimensions[2];
    // windowDimensions[0] = 384; // window width.
    // windowDimensions[1] = 384; // window height.

    // Alt window dimensions.
    const int windowWidth{384};
    const int windowHeight{384};

    // Draw window via raylib.
    // InitWindow(windowDimensions[0], windowDimensions[1], "RKJ Top Down!");
    // Alt draw window.
    InitWindow(windowWidth, windowHeight, "RKJ Top Down!");

    Texture2D map = LoadTexture("nature_tileset/world_map.png");
    Vector2 mapPos{0.0, 0.0};
    const float mapScale{4.0f};

    Character knight{windowWidth, windowHeight};

    Prop rock{Vector2{0.f, 0.f}, LoadTexture("/nature_tileset/Rock.png")};

    SetTargetFPS(60);
    while (!WindowShouldClose())
    {
        BeginDrawing();
        ClearBackground(WHITE);

        mapPos = Vector2Scale(knight.getWorldPos(), -1.f);

        // Drawing the map.
        DrawTextureEx(map, mapPos, 0.0, mapScale, WHITE);

        rock.Render(knight.getWorldPos());

        knight.tick(GetFrameTime());

        // check map bounds
        if (knight.getWorldPos().x < 0.f ||
            knight.getWorldPos().y < 0.f ||
            knight.getWorldPos().x + windowWidth > map.width * mapScale ||
            knight.getWorldPos().y + windowHeight > map.height * mapScale)
        {
            knight.undoMovement();
        }


        EndDrawing();
    }

    CloseWindow();
}

Prop.h

#include "raylib.h"

class Prop
{
public:
    Prop(Vector2 pos, Texture2D tex);
    void Render(Vector2 knightPos);
private:
    Vector2 worldPos{};
    Texture2D texture{};
    float scale{4.f};
};

Prop.cpp

#include "Prop.h"
#include "raymath.h"

Prop::Prop(Vector2 pos, Texture2D tex):
    worldPos(pos),
    texture(tex)
{

}

void Prop::Render(Vector2 knightPos)
{
    Vector2 screenPos{ Vector2Subtract(worldPos, knightPos) };
    DrawTextureEx(texture, screenPos, 0.f, scale, WHITE);
}

Thank you!

Heya!

I think there is an extra slash in the line
Prop rock{Vector2{0.f, 0.f}, LoadTexture("/nature_tileset/Rock.png")};

Try removing the first slash, and we’ll see if it renders. :slightly_smiling_face:

Looking at the course code, what Hibba42 suggested would be the first thing I’d check. I’d also try a Vector2 value that isn’t 0,0 in the event it’s just being drawn off-screen.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms