Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Zuzanno_

Pages: [1]
1
General / How can I make a background repeat infinitely?
« on: January 18, 2023, 08:58:40 pm »
Hi!

I'm currently working on a game and I am trying to make the background repeat infinitely (Tiling) as the character moves towards +X or -X position. Reading the documentation and some older posts in this forum I found the SetRepeated(); function, however, it does not work as I wish it to as it will only work if the texture is smaller than a defined rectangle type, but as this is a background texture I could not make the rectangle infinitely large.

What I'm currently looking for is a way in which I could repeat the texture to the X axis infinitely as the game is supposedly infinite.

The current code that I have for the texture and the background is the following:

//BG
    sf::Texture bgText;
    sf::Sprite bg;
    sf::Vector2u TextureSize;
    sf::Vector2u WindowSize;

 if (!bgText.loadFromFile("Media/Background.jpg"))
    {
        return -1;
    }
    else
    {
        TextureSize = bgText.getSize();
        WindowSize = window.getSize();

        float ScaleX = (float)WindowSize.x / TextureSize.x;
        float ScaleY = (float)WindowSize.y / TextureSize.y;

        bg.setTexture(bgText);
        bg.setScale(ScaleX, ScaleY);
    }
 

I would appreciate any suggestions on how I could do this, many thanks

P.S: I'm doing everything in the main function without making use of any other functions.

Pages: [1]
anything