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

Author Topic: [C++] Moon and Stairs shift ?  (Read 2587 times)

0 Members and 1 Guest are viewing this topic.

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
[C++] Moon and Stairs shift ?
« on: April 11, 2013, 09:04:19 pm »
Hello :)

How can i shift stars and moons in a scene ?

Example:

The blue thing is the player in two different situations.
Left: there are some stars behind the moon
Right: only the player(the view) moves a bit to the right and i can see more stars


[attachment deleted by admin]

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: [C++] Moon and Stairs shift ?
« Reply #1 on: April 11, 2013, 10:40:09 pm »
If I understood your question correctly, the most simplest way I could think of would be:
Get a big enough sky, then you can simply move everything a bit to the left and more stars will appear from the right.

A nice effect which might give the player some faked depth is parallax scrolling (you basically move the stars at a slower rate than the moon). There are many article about it online and it's very easy to implement.

Of course there are many different ways to achieve this, just be a bit creative and try a few things. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Re: [C++] Moon and Stairs shift ?
« Reply #2 on: April 12, 2013, 06:51:21 pm »
Yes parallax scrolling was the term that i am searching for! But can i make it with a view without moving them around ? i have a free world space ? and its to huge for move all stars separately around ?

i dont understand how :(


#include "Background.h"

Background::Background(b2World *g_world, sf::RenderWindow &g_window ){

        int size = 50;


        for(int i = 0; i != size; i++){

                float rand_size = frandom(2.f,6.f);
                float rand_positionX = frandom(-500.f,500.f);
                float rand_positionY = frandom(-500.f,500.f);

                sf::RectangleShape t_shape;

                t_shape.setSize(sf::Vector2f(rand_size, rand_size));
                t_shape.setFillColor(sf::Color::White);
                t_shape.setPosition(sf::Vector2f(rand_positionX, rand_positionY));

                StarsList.push_back(t_shape);

        }

}
void Background::Update(sf::RenderWindow *g_window){
        sf::View cam = g_window->getDefaultView();
        float speed = 0.0000033f;


        std::list<sf::RectangleShape>::iterator I;
        for(I = StarsList.begin(); I != StarsList.end(); ++I){
                (*I).move((*I).getPosition().x * cam.getCenter().x * speed, (*I).getPosition().y * cam.getCenter().y * speed);
        }
}
void Background::Draw(sf::RenderWindow *g_window){
        std::list<sf::RectangleShape>::iterator I;
        for(I = StarsList.begin(); I != StarsList.end(); ++I){
                g_window->draw((*I));
        }
}
 
« Last Edit: April 12, 2013, 08:46:14 pm by Ptlomej »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: [C++] Moon and Stairs shift ?
« Reply #3 on: April 12, 2013, 11:07:17 pm »
Well you can use two views and move them differently to each other, but then I'd say it's much easier, just to move the moon at a different speed and move everything else with the view or so. For example, you move the whole view 20px to the right and move the moon manually another 10px to the right, thus the background scene has moved 20px while the moon moved actually 30px.
This might work for this specific example, but if you plan on doing this effect for more general cases, you'll have to develop some kind of system that separates the objects that are close and those that are far away.
If every star/planet has its own depth, it would essentially even be possible to make everything move relative to each other. You'd simply have to define some value for the furthest and closest planet/star and then interpolate the values for the different depth.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Re: [C++] Moon and Stairs shift ?
« Reply #4 on: April 12, 2013, 11:55:02 pm »
How can i calculate the new Position ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: [C++] Moon and Stairs shift ?
« Reply #5 on: April 13, 2013, 02:41:26 am »
The new position of what?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything