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

Pages: [1]
1
Graphics / Fade in - fade out transition function
« on: August 31, 2018, 02:28:09 pm »
Hello there!
I have a rectangle shape with the size of the window.
I'm trying to create a transition effect that fades in the rectangle and then fades out when the first fade is fully completed.
This whole effect starts when someBool == superiorBool::True and ends when someBool == superiorBool::Unitialized.

void Application::transition()
{
        transitionRectangle.setFillColor(sf::Color(0,0,0, transitionRectangleAlphaChannel)); // transitionRectangleAlphaChannel is initialized as 0 by default

        if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel < 255.f && someBool == superiorBool::True)
        {
                transitionClock.restart();
                transitionRectangleAlphaChannel += 5;
        }
        else if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel > 0.f && someBool == superiorBool::False)
        {
                transitionClock.restart();
                transitionRectangleAlphaChannel -= 5;
        }

        if (someBool == superiorBool::True && transitionRectangleAlphaChannel == 255)
        {
                someBool = superiorBool::False;
        }
        else if (someBool == superiorBool::False && transitionRectangleAlphaChannel == 0)
        {
                someBool = superiorBool::Uninitialized;
        }
 

For some reasons it doesn't work. Any ideas?
Thanks in advance!

2
Window / Re: Minimize the window
« on: August 05, 2018, 03:50:28 pm »
Yes we do.

Does this work? I'm not really familiar with GitHub and I couldn't find a download link.

3
Graphics / Re: Combine 2 sprites into a single one?
« on: July 23, 2018, 07:31:39 pm »
Damn, I was looking like an idiot for a SetFillColor function lol.
Thanks very much!

4
Graphics / Re: Combine 2 sprites into a single one?
« on: July 23, 2018, 11:41:36 am »
I was aware of the white clear color and later I realized that I should change the size too. I've also changed the textures so they are fully opaque. This is what I have right now:
void Player::draw()
{

        texture.clear(sf::Color::Transparent);

        texture.draw(shadow, sf::BlendNone);
        Application::getInstance()->window.draw(body);
        texture.draw(gunShadow, sf::BlendNone);
        Application::getInstance()->window.draw(gun);

        for (size_t i = 0; i < bullets.size(); i++)    
        {
                        Application::getInstance()->window.draw(bullets.at(i).getBody());
        }

        texture.display();

        sf::Sprite sprite(texture.getTexture());
        Application::getInstance()->window.draw(sprite);
}

But it still looks weird :


That's how it looks without BlendNone :


I guess it should work if I would apply a color overlay to the whole texture, without using BlendNone on body and gun textures separately... Is this possible? What should I do next?

5
Graphics / Re: Combine 2 sprites into a single one?
« on: July 23, 2018, 11:04:43 am »
I deleted what I've done after I saw it doesn't work. I recreated it and I think it's a bit better than before.
So, I have a class called Player. I initialized the texture in Player constructor :
if (!texture.create(100, 100))
        std::cout << "error" << std::endl;

And then here is Player draw function :
void Player::draw()
{

        texture.clear(sf::Color::White);

        //Application::getInstance()->window.draw(shadow); <---- that's the draw call I've been using before
        texture.draw(shadow);
        Application::getInstance()->window.draw(body); // draw of the body (not the shadow)
        //Application::getInstance()->window.draw(gunShadow); <--  draw call used before
        texture.draw(gunShadow);
        Application::getInstance()->window.draw(gun);

// Some bullets draw thing, not important
        for (size_t i = 0; i < bullets.size(); i++)    
        {
                        Application::getInstance()->window.draw(bullets.at(i).getBody());
        }

        texture.display();

        sf::Sprite sprite(texture.getTexture());
        Application::getInstance()->window.draw(sprite);
}
 

Right now, it kinda looks like a mask or something, but the problem is obviously still there because I haven't used sf::BlendMode.
That's how it looks :

6
Graphics / Re: Combine 2 sprites into a single one?
« on: July 23, 2018, 10:06:53 am »
This is probably not the only option, but you can draw all the shadows to an sf::RenderTexture without applying alpha blending ("None" blend mode), and then draw your render-texture with alpha blending enabled.

I've looked at the sf::RenderTexture and sf::BlendMode documentation but I couldn't understand how to do it. I've tried something but I've created a buggy and laggy texture.

Could you help me with the code? Both bodyShadow and gunShadow are rectangles directly drawn on the window.

PS: I didn't set shadows transparency using setFillColor function, but using photoshop to add transparency to the texture (if this matters).

7
Graphics / [SOLVED]Combine 2 sprites into a single one?
« on: July 23, 2018, 08:52:42 am »
So, I am facing this problem:


Basically, I have 2 rectangles ( body shadow and gun shadow ), each one having a black texture with 40% opacity that goes up to 80% in the place where they intersect. Is there a way to make the shadows appear as a single shape?

Thanks in advance !

8
Window / Re: Minimize the window
« on: June 20, 2018, 11:52:56 am »
Well, thanks I guess. Are you guys planning to implement something like that btw? :)

9
Window / Minimize the window
« on: June 20, 2018, 11:21:44 am »
Hello guys! I've created a custom titlebar that's fully working EXCEPT the minimize button. I can't minimize the window even if I try to do it from the windows taskbar. Any ideas? I would prefer one that's not Windows-specific but if there is no other solution, I'd be grateful to hear the windows one too! :D



Edit: Wow, that's a big image lol.

10
General / Custom Titlebar
« on: May 18, 2018, 02:40:32 pm »
Is there a way to create a custom titlebar using SFML?

Or at least vanish the actual titlebar (white thing from image below) so I can create a custom one using rectangles?


11
Is it necessary to use delta time if I capped the frame rate? How exactly does the frame rate function work?

12
General / C++ & SFML class vector - showing the wrong texture
« on: May 09, 2018, 04:24:53 pm »
So, my problem is this : I have a class called thing. The class basically creates a rectangle with a texture. When I'm drawing the rectangle on the window without using a vector, all works fine, but when I do, it takes the wrong texture (another texture from the same folder) even tho in the class it says nothing about that texture.

Here is the code :

Main.cpp
#include <SFML/Graphics.hpp>    
#include <iostream>
#include "thing.h"
#include <vector>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "whatever", sf::Style::Close);

    std::vector<thing> things;
    things.emplace_back(thing());

sf::Texture textureanother1;
textureanother1.loadFromFile("textures/another1.png");

sf::Texture textureanother2;
textureanother2.loadFromFile("textures/another2.png");

sf::RectangleShape another1(sf::Vector2f(132.0f, 94.0f));
another1.setTexture(&textureanother1);
another1.setOrigin(66.0f, 94.0f);
another1.setPosition(500.0f, 680.0f);

sf::RectangleShape another2(sf::Vector2f(126.0f, 55.0f));
another2.setTexture(&textureanother2);
another2.setOrigin(63.0f, 55.0f);
another2.setPosition(500.0f, 605.0f);

    while (window.isOpen())
    {
        sf::Event evnt;
        while (window.pollEvent(evnt))
        {
            if (evnt.type == sf::Event::Closed)
            {
                window.close();
            }
            else
            {
                break;
            }
        }

        window.draw(another1);
        window.draw(things.at(0).thingItem);
        window.draw(another2);
        window.display();
    }
    return 0;
}

Thing.h

#pragma once

#include <SFML/Graphics.hpp>

class thing
{
public:
    thing();
    ~thing();

    sf::Texture thingTexture;
    sf::RectangleShape thingItem;
};

Thing.cpp

#include "thing.h"

thing::thing()
{
    thingTexture.loadFromFile("textures/sometexture.png");
    thingItem.setTexture(&thingTexture);
    thingItem.setSize(sf::Vector2f(16.25f, 99.25f));
    thingItem.setOrigin(8.125f, 99.25f);
    thingItem.setPosition(500.0f, 99.25f);

}

thing::~thing() = default;

Again, ALL other rectangles except the one created with the class and a vector work fine. The one created with a class and a vector works fine ONLY when it's used without a vector. What is wrong? There are no errors or warnings.

Instead of that : (which is showed when I use the class thing without a vector)



It shows that : (I used a vector, like in the code)



PS: I changed a bit names and deleted commens so you won't be confused by the strange words.

Pages: [1]