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.


Messages - Moderatgamer

Pages: [1]
1
General / Re: resolution independant movement?
« on: October 13, 2018, 01:01:19 am »
Thanks I'll need to give the documentation a good read appreciate the help :)

2
General / Re: resolution independant movement?
« on: October 10, 2018, 06:15:34 pm »
Thanks for the reply appreciate it. I have set up a rudimentary frame limiter just capped it at 60 didn't use the built in feature just used a clock and timer to only draw every 60th of a second. I also just started using the view last night which unfortunately didn't help either.

the problem is that when you say move 1 it literally means 1 pixel so when I resize the window 1 pixel is either more or less than the original distance causing the speed variation. Do you know any way to do something similar to resolution scaling where I can set the internal resolution and it will just stretch the image to the window while remaining at the internal resolution?

3
General / resolution independant movement?
« on: October 10, 2018, 01:43:26 am »
Hi all,

please excuse me if this is the wrong place to post such a question, this is my first post. I have recently started to learn c++ with SFML just messing around really and I have hit a problem I can't seem to fix. Basically if I set my movement speed to say for example 1 when I change the window size the game either speeds up or slows down as the move function directly related to pixels. I wonder if anyone has a solution for me to make the speed constant regardless of resolution. I've attached a small part of code that I was using to test endless scrolling background it's very simple I will be padding it out more and incorporating an array of textures that will be semi randomly picked but for now I was just testing. Appreciate any help you can give me.


#include "paralax_background.h"

paralax::paralax(sf::String texture_1_src, sf::String texture_2_src)
{
        if (!texture_1.loadFromFile(texture_1_src))
        {
                // error...
                std::cout << "loading failed" << std::endl;
        }
        back_1.setTexture(texture_1);
        back_1.setOrigin(sf::Vector2f(back_1.getScale().x / 2, back_1.getScale().y / 2));

        if (!texture_2.loadFromFile(texture_2_src))
        {
                // error...
                std::cout << "loading failed" << std::endl;
        }
        back_2.setTexture(texture_2);
        back_2.setOrigin(sf::Vector2f(back_2.getScale().x / 2, back_2.getScale().y / 2));
        back_2.setPosition(1000, 0); // TODO change to windwo width// width of image/ window !!
}

void paralax::scroll(sf::RenderWindow & window) //TODO make for loop that loops through array of backgrounds
{
       
        speed = 0.2f;


                back_1.move(-speed, 0);

                if (back_1.getPosition().x <= -1000) {
                        back_1.setPosition(0 + back_1.getLocalBounds().width , 0);
                        //back_2.setPosition(back_2.getLocalBounds().width * 2, 0);
                }

                back_2.move(-speed, 0);

                if (back_2.getPosition().x <= -1000) {
                        back_2.setPosition(0 + back_2.getLocalBounds().width, 0);
                }
       
}

void paralax::Draw(sf::RenderWindow & window)
{

        window.draw(back_1);
        window.draw(back_2);

}

 

Pages: [1]
anything