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 - Alidro

Pages: [1] 2
1
Graphics / Re: creating a decent camera movement
« on: September 18, 2017, 02:13:04 pm »
Thank you, this is really a great camera movement. I really appreciate your effort answering my questions.

2
Graphics / Re: creating a decent camera movement
« on: September 17, 2017, 07:06:08 pm »
OK, i can understand it now, but how do i get "dt" ?

3
Graphics / Re: creating a decent camera movement
« on: September 17, 2017, 02:05:49 pm »
What exactly do you mean with that? I cant really understand your idea.

4
Graphics / Re: creating a decent camera movement
« on: September 17, 2017, 11:40:07 am »
I dont want to just set the camera to the players position because that would be a pain to look at. I want the camera to move just when the player gets to far away from the Center, also i want the camera to accelerate and deccelerate and not to move suddenly.

5
Graphics / creating a decent camera movement
« on: September 16, 2017, 05:31:04 pm »
Hello,
so i've been trying to create a smooth and nice camera with the sf::View in sfml. Currently, i have a camera which moves when the Player leaves a specific area (the Player can move inside a box but if he gets out of it the camera will follow him). It is working as i wished, but its not smooth. The code is:
#include "Camera.h"



Camera::Camera()
{
        view.setSize(384, 216);
        view.setCenter(0, 0);
}

void Camera::Render(RenderWindow &window)
{
        window.setView(view);
}

void Camera::Update(FloatRect object, Vector2f objectVelocity)
{

        if (object.left + object.width > view.getCenter().x + radius)
        {
                if (viewX < objectVelocity.x)
                        viewX = viewX + camSpeed;
        }
        else if (object.left < view.getCenter().x - radius)
        {
                if (viewX > objectVelocity.x)
                        viewX = viewX - camSpeed;
        }
        else
        {
                if (viewX < -camSpeed * 0.9)
                {
                        viewX = viewY + camSpeed * 0.9;
                }
                else if (viewX > camSpeed * 0.9)
                {
                        viewX = viewY - camSpeed * 0.9;
                }
                else
                        viewX = 0;
        }
       
        if (object.top + object.height > view.getCenter().y + radius / 1.5)
        {
                if (viewY < objectVelocity.y)
                        viewY = viewY + camSpeed;
        }
        else if (object.top < view.getCenter().y - radius / 1.5)
        {
                if (viewY > objectVelocity.y)
                        viewY = viewY - camSpeed;
        }
        else
        {
                if (viewY < -camSpeed * 0.9)
                {
                        viewY = viewY + camSpeed * 0.9;
                }
                else  if (viewY > camSpeed * 0.9)
                {
                        viewY = viewY - camSpeed * 0.9;
                }
                else
                        viewY = 0;
        }
        view.move(viewX, viewY);
       
}
in the cpp file and the h file:
#include <SFML\Graphics.hpp>
#include <iostream>

using namespace sf;

class Camera
{
public:
        Camera();
        ~Camera();
        void Render(RenderWindow &window);
        void Update(FloatRect object, Vector2f objectVelocity);
private:
        View view;
        int radius = 60;
        float viewY = 0, viewX = 0;
        float camSpeed = 2;

};

 

The Problem seems to be the camera moving a bit faster than the player, then camera passes the player and slows down, this happening inside a fraction of a second causes the camera to look stuttering. But I dont know how to solve this Problem.

6
Window / Re: How do I use sf::Event in a class
« on: July 18, 2017, 11:28:16 pm »
Thank you, thats all i wanted to know.
Im kind of embarrassed that i didnt get this easy solution by myself but anyway thanks.

7
Window / How do I use sf::Event in a class
« on: July 18, 2017, 07:55:32 pm »
Hello,
I am pretty sure there is a solution easy to find to this if I were better at the C++ in General but  I'm not.
I wanted to create a class, which contains text input. I wanted to do this with sf::Event::TextEntered but i dont know how to use it in a class since i am not able to use my sf::Event there because i declared it in main(). I dont have any code to post here because i have absolutely no idea.
I did not find anything useful for me in the Documentation.

Thank you for every good advice.

8
Network / Re: UdpSocket::send seems to set the ip to 0.0.0.0
« on: May 26, 2017, 10:30:23 am »
Thank you, now it works.

9
Network / UdpSocket::send seems to set the ip to 0.0.0.0
« on: May 25, 2017, 09:34:34 pm »
Hello there!
I just got into the Network module of sfml. i wanted to create a small game so i used UdpSocket.
Sadly i havent been able to send anything properly and after some Investigation i noticed my ip address is set to 0.0.0.0 after i use  .send(). In this case i use , just to test it, the same ip address for both Client and Server. Heres the Code:
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Network.hpp>

using namespace sf;

int main()
{
        UdpSocket socket;
        IpAddress ip= IpAddress::getLocalAddress();
        Packet packet;
        unsigned short port = 1234;
        RectangleShape player1;
        RectangleShape player2;
        char sc;
        Vector2f player2pos;
        player1.setSize(Vector2f(20, 20));
        player2.setSize(Vector2f(20, 20));
        player1.setFillColor(Color::Blue);
        player2.setFillColor(Color::Red);
        std::cout << "[s] server, [c]client" << std::endl;
        std::cin >> sc;
        if (sc == 'c')
        {
                std::cout << "Server ip address" << std::endl;
                //std::cin >> ip;
                socket.bind(1235);

        }
        if (sc == 's')
        {
                socket.bind(1234);
        }

        bool update = false;
       
        socket.setBlocking(false);

        RenderWindow window(VideoMode(800, 600), "Window");
        while (window.isOpen())
        {
                if (sc == 'c')
                {
                        packet << player1.getPosition().x << player1.getPosition().y;

                        if (socket.send(packet, ip, 1234))
                                std::cout << "client sent data to " << ip.toString() << std::endl;
                        socket.receive(packet, ip, port);
                        packet >> player2pos.x >> player2pos.y;
                }
                if (sc == 's')
                {
                        if (socket.receive(packet, ip, port))
                                std::cout << "recieved data from " << ip.toString()  << std::endl;
                        packet >> player2pos.x >> player2pos.y;
                        packet << player1.getPosition().x << player1.getPosition().y;
                        socket.send(packet, ip, 1235);
                }
                Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == Event::Closed)
                        {
                                window.close();
                        }
                        else if (event.type == Event::GainedFocus)
                        {
                                update = true;
                        }
                        else if (event.type == Event::LostFocus)
                        {
                                update = false;
                        }
                }


                if (update)
                {
                        if (Keyboard::isKeyPressed(Keyboard::A))
                                player1.move(-1.f, 0.f);
                        else if (Keyboard::isKeyPressed(Keyboard::D))
                                player1.move(1.f, 0.f);
                        else if (Keyboard::isKeyPressed(Keyboard::S))
                                player1.move(0.f, 1.f);
                        else if (Keyboard::isKeyPressed(Keyboard::W))
                                player1.move(0.f, -1.f);
                }
                player2.setPosition(player2pos);

                window.clear();
                window.draw(player1);
                window.draw(player2);
                window.display();
        }
        return 0;
}

10
General / Re: problem with bool, if(), maybe with rendering
« on: March 20, 2017, 05:30:09 pm »
I knew iut was something stupid :(
sorry for this
thanks anyway

11
General / problem with bool, if(), maybe with rendering
« on: March 20, 2017, 04:49:28 pm »
Hello,
i wanted to create a startscreen for my game and i also wanted to include an options screen.
I dont know if this is a good attempt, but it worked until the point i wanted to add the options screen.
Heres the code:
//startscreen class:
#include "Startscreen.h"

Startscreen::Startscreen(RenderWindow &window)
{
        playButtonTexture.loadFromFile("Textures/Spiel1Button v.3.png");
        playButton.buttonSprite.setTexture(playButtonTexture, 1);
        playButton.buttonSprite.setOrigin(playButtonTexture.getSize().x / 2, playButtonTexture.getSize().y / 2);
        playButton.buttonSprite.setPosition(window.getSize().x / 2, window.getSize().y / 2.25);
        playButton.setText("Play");

        optionsButtonTexture.loadFromFile("Textures/Spiel1Button v.3.png");
        optionsButton.buttonSprite.setTexture(optionsButtonTexture, 1);
        optionsButton.buttonSprite.setOrigin(optionsButtonTexture.getSize().x / 2, optionsButtonTexture.getSize().y / 2);
        optionsButton.buttonSprite.setPosition(window.getSize().x / 2, playButton.buttonSprite.getPosition().y + 110);
        optionsButton.setText("Options");

        exitButtonTexture.loadFromFile("Textures/Spiel1Button v.3.png");
        exitButton.buttonSprite.setTexture(exitButtonTexture, 1);
        exitButton.buttonSprite.setOrigin(playButtonTexture.getSize().x / 2, playButtonTexture.getSize().y / 2);
        exitButton.buttonSprite.setPosition(window.getSize().x / 2, optionsButton.buttonSprite.getPosition().y + 110);
        exitButton.setText("Exit");

        resolutionButtonHigherTexture.loadFromFile("Textures/Spiel1Button v.4.png");
        resolutionButtonHigher.buttonSprite.setTexture(resolutionButtonHigherTexture, 1);
        resolutionButtonHigher.buttonSprite.setOrigin(resolutionButtonHigherTexture.getSize().x / 2 , playButtonTexture.getSize().y / 2);
        resolutionButtonHigher.buttonSprite.setPosition(window.getSize().x / 2 + 20, 300);
        resolutionButtonHigher.setText("");

       
        startBackgroundTexture.loadFromFile("Textures/Spiel1Hintergrund ohne Erde schlicht.png");
        startBackground.backgroundSprite.setTexture(startBackgroundTexture, 1);
        startBackground.backgroundSprite.setOrigin(startBackgroundTexture.getSize().x / 2, startBackgroundTexture.getSize().y / 2);
        startBackground.backgroundSprite.setPosition(window.getSize().x / 2, window.getSize().y / 2);


        headline1.setString("S");
        headline1.setOrigin(0, 150);
        headline1.setFont(font.Calibri);
        headline1.setCharacterSize(300);
        headline2.setString("pace");
        headline2.setOrigin(0, 150);
        headline2.setFont(font.Calibri);
        headline2.setCharacterSize(300);

        headline1.setPosition((window.getSize().x / 2) - ((headline1.getGlobalBounds().width + headline2.getGlobalBounds().width) / 1.9 ) , playButton.buttonSprite.getPosition().y - 250);
        headline2.setPosition(headline1.getPosition().x + headline1.getGlobalBounds().width * 1.2, headline1.getPosition().y);


        startActive = true;
        optionsActive = false;

}

void Startscreen::Render(RenderWindow &window)
{
        startBackground.render(window);
        if (startActive == true)
        {
        playButton.render(window);
        exitButton.render(window);
        optionsButton.render(window);
        window.draw(headline1);
        window.draw(headline2);
        }
       
        if (optionsActive)
        {
                resolutionButtonHigher.render(window);
        }
       
       
}

void Startscreen::Update(RenderWindow &window)
{
        if (optionsButton.isPressed(window) || playButton.isPressed(window))
        {
                startActive = false;
        }
        if (startActive)
        {
        playButton.update(window);
        exitButton.update(window);
        optionsButton.update(window);
        }
       
       


        if (exitButton.isPressed(window) == 1)
        {
                window.close();
        }




        if (optionsButton.isPressed(window))
        {
                optionsActive = true;
        }
       
        if (optionsActive = true)
        {
                resolutionButtonHigher.update(window);
        }
}

 
in the main class there are only Startscreen::update and Startscreen:render executed by now.
if i click options or play, as i wanted, the buttons and Text all dissapear, but they are still updated, so if i click for example "exit", the program still quits.
Also the "resolutionButtonHigher" is rendered from the start, and is updated from the start, although "optionsActive" and "startActive" are false by default.
the "button.isPressed" returns 1 if leftclicked, and 0 if not.
of course the "render" just draws the objects to the screen.

I think this has to be some careless mistake, so sorry if i were too idiotic.

12
General / Re: detect a mouseclick on a Sprite
« on: March 15, 2017, 06:22:20 pm »
Thank you. Now i think i know enough to continue.

13
General / Re: detect a mouseclick on a Sprite
« on: March 15, 2017, 05:16:14 pm »
thank you. I didnt know there was something like "auto", what exactly is it and what can be stored in it?

14
General / Re: detect a mouseclick on a Sprite
« on: March 15, 2017, 05:08:05 pm »
Why don't you show us what you already got? :)

It's a pretty easy problem and all these other threads on the forum explain it just fine, so you must have a problem in understanding it somehow.
i solved this with
if (sprite.getPosition().x <= Mouse::getPosition().x + 100 && sprite.getPosition().x >= Mouse::getPosition().x - 100 && sprite.getPosition().y <= Mouse::getPosition().y +100 && sprite.getPosition().y >= Mouse::getPosition -100)
{
//code goes here
}
 
but this only checks a hitbox of 200 + 200, if i want to change the hitbox, i could change the numbers, but it the hitbox does not depend on the actual size of the sprite/texture. i want to use this in a class and have multiple objects of this class, some with an other size than others.


1. Get the position of a click.
2. Get coordinates of a sprite.
3. Check if click position was inside those coordinates.

but wouldnt this only work if i clicked the exact origin?

15
General / detect a mouseclick on a Sprite
« on: March 14, 2017, 07:11:19 pm »
Hello,

although i think there are already posts for this topic, i just couldnt find exactly what i wanted.

So i want to detect if the mouse is colliding with a Sprite. This question may seem idiotic, but i just want an easy way to detect that. I tried to do it with xy positions or with globalbounds of the sprite but it all didnt worked as i wanted.

Pages: [1] 2