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

Pages: [1] 2
1
SFML projects / Drawable group class
« on: May 17, 2018, 03:26:36 pm »
I made a class that can store classes that is derived from drawables...I made two :
this one just makes it easier to draw multiple objects, it has a function that can make it so it won't draw one of them, or you can just make the group invisible, it is named ObserveGroup

https://github.com/Flaze07/useful-stuff/tree/master/for%20sfml/ObserveGroup

the second one has complete ownership over the objects, just like the ObserveGroup, this one can make one of the objects invisible, or itself invisible :

https://github.com/Flaze07/useful-stuff/tree/master/for%20sfml/OwnGroup

2
Graphics / Is this the right way to use sf::VertexBuffer ?
« on: May 12, 2018, 05:19:35 am »
Static :
#include <array>
#include <SFML/Graphics.hpp>

int main()
{

    const float start = 100;
    const float width = 200;

    sf::RenderWindow win{ sf::VideoMode{ 600, 600 }, "using VertexBuffer" };
    win.setFramerateLimit( 60 );

    sf::VertexBuffer v_buffer{ sf::Quads, sf::VertexBuffer::Static };
    v_buffer.create( 4 );

    std::array< sf::Vertex, 4 > v_arr;
    v_arr.at( 0 ).position = sf::Vector2f{ start, start + width };
    v_arr.at( 1 ).position = sf::Vector2f{ start, start };
    v_arr.at( 2 ).position = sf::Vector2f{ start + width, start };
    v_arr.at( 3 ).position = sf::Vector2f{ start + width, start + width };

    v_arr.at( 0 ).color = sf::Color::Blue;
    v_arr.at( 1 ).color = sf::Color::Red;
    v_arr.at( 2 ).color = sf::Color::Green;
    v_arr.at( 3 ).color = sf::Color::White;

    v_buffer.update( v_arr.data() );

    while( win.isOpen() )
    {
        sf::Event event;
        while( win.pollEvent( event ) )
        {
            if ( event.type == sf::Event::Closed ) win.close();
            if ( ( event.type == sf::Event::KeyPressed ) && ( event.key.code == sf::Keyboard::Escape ) ) win.close();
        }

        win.clear();
        win.draw( v_buffer );
        win.display();
    }
}
 

#include <array>
#include <SFML/Graphics.hpp>

int main()
{

    const float start = 0;
    const float width = 200;

    sf::RenderWindow win{ sf::VideoMode{ 600, 600 }, "using VertexBuffer" };
    win.setFramerateLimit( 60 );

    sf::VertexBuffer v_buffer{ sf::Quads, sf::VertexBuffer::Stream };
    v_buffer.create( 4 );

    std::array< sf::Vertex, 4 > v_arr;
    v_arr.at( 0 ).position = sf::Vector2f{ start, start + width };
    v_arr.at( 1 ).position = sf::Vector2f{ start, start };
    v_arr.at( 2 ).position = sf::Vector2f{ start + width, start };
    v_arr.at( 3 ).position = sf::Vector2f{ start + width, start + width };

    v_arr.at( 0 ).color = sf::Color::Blue;
    v_arr.at( 1 ).color = sf::Color::Red;
    v_arr.at( 2 ).color = sf::Color::Green;
    v_arr.at( 3 ).color = sf::Color::White;

    v_buffer.update( v_arr.data() );

    sf::Vector2f init_position;
    init_position.x = ( v_arr.at( 2 ).position.x + v_arr.at( 1 ).position.x ) / 2;
    init_position.y = ( v_arr.at( 0 ).position.y + v_arr.at( 1 ).position.y ) / 2;

    sf::Vector2f position{ init_position };

    while( win.isOpen() )
    {
        sf::Event event;
        while( win.pollEvent( event ) )
        {
            if ( event.type == sf::Event::Closed ) win.close();
            if ( ( event.type == sf::Event::KeyPressed ) && ( event.key.code == sf::Keyboard::Escape ) ) win.close();
        }

        if ( position.x == static_cast<float>( win.getSize().x  ) )
        {
            position = init_position;

            v_arr.at( 0 ).position.x = init_position.x - ( width / 2 );
            v_arr.at( 1 ).position.x = init_position.x - ( width / 2 );
            v_arr.at( 2 ).position.x = init_position.x + ( width / 2 );
            v_arr.at( 3 ).position.x = init_position.x + ( width / 2 );
        }

        v_arr.at( 0 ).position.x += 1;
        v_arr.at( 1 ).position.x += 1;
        v_arr.at( 2 ).position.x += 1;
        v_arr.at( 3 ).position.x += 1;

        position.x += 1;

        v_buffer.update( v_arr.data() );

        win.clear();
        win.draw( v_buffer );
        win.display();
    }
}
 

3
Audio / Sometimes Audio not loading
« on: May 11, 2018, 04:51:09 pm »
This has been bugging me for a while...sometimes, when I load my application, the sound won't load and by won't load I mean
sf::Sound::loadFromFile() return false;
why does this happen ?, also if code is needed, please tell me

4
Graphics / transforming on each vertex array
« on: May 01, 2018, 11:45:49 am »
for example :
std::vector< sf::RectangleShape > rect;
//stuffs

int i = 0;
for ( auto& a : rect )
{
        ++i;
        rect.setRotation( 90 + i );
}
 

each of the rect will have different rotations.
I know how to apply transform to vertex array, but if I want the vertex array to have different roations, how do I do that ?

sf::VertexArray vert{ sf::Quads, 8 };
//stufs
sf::Transform t;
t.setRotation( 90 );
win.draw( vert, t ) // unable to set rotation for each 4 vertices
 

5
General / building sfml problems
« on: April 29, 2018, 05:33:28 pm »
There is an attachment. Why does CMake says Android ? Shouldn't it say Windows ( Well, I mean, not really, but it shouldn't be saying it needs Android_SDK )

6
General / How do you make .DLLs with CMake ??
« on: April 07, 2018, 11:31:04 am »
Look, I know that CMake is not a compiler (because it says so in the tutorial to "compile" sfml) but, if I cannot make a .dlls how do I use the library that I built with CMake ?
(Also, this is a problem regarding thor, because I need to build it with CMake, with SFML, there is no problem with just using the pre-compiled ones)

Ok, just realized that I can actually use the .cbp to compile it with CodeBlocks, and it kinda works because it suddenly terminates after 1 minute and 18 seconds

NVM, it worked, it created one .dll and another of .dll.a ????

Edit : Nevermind it worked, and I can successfully integrate THOR into my Project, but why is it thorlib.dll.a instead of just .a

7
General / Using Events to check for inputs ?
« on: April 06, 2018, 04:03:24 pm »
Should I use Events to check for inputs to i.e move my character or should I use the other one ??

i.e
Code: [Select]
        sf::Event event;
        while (win.pollEvent(event))
        {
            if (event.type == sf::Event::KeyPressed)
            {
                if (event.key.code == sf::Keyboard::Space) chara.jump();
            }
        }

or

Code: [Select]
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) chara.jump();

which one is better?

8
General / thor related problems, procedure cannot be found in libthor dll
« on: December 26, 2017, 02:26:37 pm »
any suggestion on how to fix this ?

9
General / Multi line text field(box)
« on: September 03, 2017, 06:11:44 pm »
hi, is there such a thing as multi line text field (box) like JTextArea in either sfgui or tgui ?
also, if there is none...how to make one ?

10
General / actions happened too fast ??
« on: July 30, 2017, 04:22:33 pm »
hi, I have a sfml program where it is comprised of pixel...it is a battle of pixel and it moved according to a set speed...but the way it moved when i run it is instantaneously moved...

main.cpp
#include <TGUI/TGUI.hpp>
#include "pixels/pixels.hpp"
#include <iostream>

int main()
{

    const float speed = 0.01;
    sf::RenderWindow win{sf::VideoMode{450, 400}, "pixel vs pixel"};

    Pixels p1{sf::Color::Red, sf::Vector2f{200, 400}, sf::Vector2f{0, 0}, (200 * 400) / 2, speed};
    Pixels p2{sf::Color::Blue, sf::Vector2f{200, 400}, sf::Vector2f{250, 0}, (200 * 400) / 2, speed};

    while (win.isOpen())
    {
        sf::Event event;
        while (win.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) win.close();
        }

        p1.update(p2);
        p2.update(p1);

        win.clear();
        win.draw(p1);
        win.draw(p2);
        win.display();
    }
}

 

Pixels.hpp
class Pixels : public sf::Drawable, public sf::Transformable
{
private :
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        states.transform *= getTransform();
        states.texture = 0;
        target.draw(m_vertices, states);
    }
    sf::VertexArray m_vertices;
    const float speed = 0;
public :
    Pixels(sf::Color color, sf::Vector2f start, sf::Vector2f end, int numbers, float pspeed);
    void update(Pixels& pixels);
    sf::Vector2f& getPoint(size_t index);
    size_t getPointCount();
};
 

pixels.cpp
#include <cstdlib>
#include <ctime>
#include "pixels.hpp"

Pixels::Pixels(sf::Color color, sf::Vector2f start, sf::Vector2f end, int numbers, float pspeed) :
    speed(pspeed)
{
    srand(time(0));
    m_vertices.setPrimitiveType(sf::PrimitiveType::Points);
    m_vertices.resize((size_t) numbers);
    for (size_t i = 0; i < m_vertices.getVertexCount(); ++i)
    {
        m_vertices[i].color = color;
        float temp_x = (rand() % (int) start.x) + (int) end.x;
        rand();
        float temp_y = (rand() % (int) start.y) + (int) end.y;
        m_vertices[i].position = sf::Vector2f{temp_x, temp_y};
    }
}

void Pixels::update(Pixels& pixels)
{
    for (int i = 0; i < m_vertices.getVertexCount(); ++i)
    {
        if (i >= pixels.getPointCount())
        {
            if (getPoint(i).x < pixels.getPoint(pixels.getPointCount() - 1).x)
            {
                m_vertices[i].position = sf::Vector2f{m_vertices[i].position.x + speed, m_vertices[i].position.x};
            }
            else if (getPoint(i).x > pixels.getPoint(pixels.getPointCount() - 1).x)
            {
                m_vertices[i].position = sf::Vector2f{m_vertices[i].position.x - speed, m_vertices[i].position.x};
            }
            if (getPoint(i).y < pixels.getPoint(pixels.getPointCount() - 1).y)
            {
                m_vertices[i].position = sf::Vector2f{m_vertices[i].position.y, m_vertices[i].position.y + speed};
            }
            else if (getPoint(i).y > pixels.getPoint(pixels.getPointCount() - 1).y)
            {
                m_vertices[i].position = sf::Vector2f{m_vertices[i].position.y, m_vertices[i].position.y - speed};
            }
            continue;
        }
        if (getPoint(i).x < pixels.getPoint(i).x)
        {
             m_vertices[i].position = sf::Vector2f{m_vertices[i].position.x + speed, m_vertices[i].position.x};
        }
        else if (getPoint(i).x > pixels.getPoint(i).x)
        {
            m_vertices[i].position = sf::Vector2f{m_vertices[i].position.x - speed, m_vertices[i].position.x};
        }
        if (getPoint(i).y < pixels.getPoint(i).y)
        {
             m_vertices[i].position = sf::Vector2f{m_vertices[i].position.y, m_vertices[i].position.y + speed};
        }
        else if (getPoint(i).y > pixels.getPoint(i).y)
        {
            m_vertices[i].position = sf::Vector2f{m_vertices[i].position.y, m_vertices[i].position.y - speed};
        }
    }
}

sf::Vector2f& Pixels::getPoint(size_t index)
{
    return m_vertices[index].position;
}

size_t Pixels::getPointCount()
{
    return m_vertices.getVertexCount();
}

 

11
Graphics / removing sf::VertexArray from the middle
« on: July 30, 2017, 02:04:53 pm »
is it possible ??

12
Graphics / direction shape faces when rotation is 0
« on: July 14, 2017, 06:11:41 pm »
hi, is the direction of shape (rectangle) upward, left, right, or downward when it has the rotation of zero  ???

13
Graphics / win.pushGLStates and win.popGLStates vs win.resetGLStates
« on: July 10, 2017, 06:09:58 am »
hi so I checked these out because I want to draw with both sfgui and sfml
and with this code nothing is drawn
Code: [Select]
        win.pushGLStates();
        if (option == Option::rectangle)
        {
            win.draw(rect);
        }
        win.popGLStates();
       sfgui.Display(win)

but this one works
Code: [Select]
        win.resetGLStates();
        sfgui.Display(win);
        win.resetGLStates();
        if (option == Option::rectangle)
        {
            win.draw(rect);
        }

full code
https://gist.github.com/Flaze07/7b10a4762523180a0169f49848d648cb

14
General / I dont get sfgui
« on: July 09, 2017, 02:59:33 pm »
I dont get the installation...
it said building it only if you want to
yet in the installation page of the wiki it said to build it..

so...does building it means turning it into .dll ?
if so there's already .dll

 ??? ??? ???

oh and I am using codeblock...so...how do I link it...I know how to make it search for the includes...
but stuff like linking

example :
sfml-graphics

how is that done with sfgui

15
Graphics / mouse button press only once
« on: July 09, 2017, 05:49:18 am »
hi...I think I have asked more than 2 question in this forum since yesterday...
anyways...
I want to have it so my mouse button received input is not received when it is pressed continuously
I know you can do it with event...but the code where the mouse input received is in another file
so I tried this code...
Code: [Select]
     while (1)
    {
        if ( (sf::Mouse::isButtonPressed(sf::Mouse::Left)) && (!pressed) )
        {
            std::cout << "haha" << i++ << " " << pressed << std::endl;
            pressed = true;
            std::cout << pressed;
            continue;
        }
        pressed = false;
    }
even If I pressed the left mouse button...it didn't continue..I wonder why

Pages: [1] 2