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

Pages: [1] 2
1
General / Re: Help making a shape jump
« on: June 17, 2019, 08:45:11 am »
So, basically, you have a boolean value: isInAir.

You're gonna want to set isInAir to true when you press space. Each frame, check wether your boolean is set to true. If that's the case, update the position of the rectangle according to the velocity and gravity:

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
    isInAir = true;
}

if(isInAir)
{
    velocity += gravity * deltaTime;
    rect.move(velocity * deltaTime);
}

(The delta time is the time that the last frame took to execute).

Finally, set your isInAir value to false when a collision with the ground is detected.

if(collisionDetected(rect, ground)) // Your collision detection algorithm
{
     isInAir = false;
}

Keep in mind that this may not be 100% accurate (it lacks things like acceleration and such) but that's the basics anyway.

Also, you may wanna fix your timestep (gafferongames.com/game-physics/fix-your-timestep/%22). It makes the whole physics handling a lot easier. With this technique, no need for any deltaTime values anymore.

2
Graphics / Re: Implementing VAO in SFML/OpenGL with shaders
« on: January 31, 2019, 07:31:33 am »
Hi,

the SFML currently only support until version 120 (#version 120) of glsl. That means that instead of using in and out keywords for the variables, you will have to use the "uniform" keyword, along with the "setUniform" function of an SFML shader.

There are probably good tutorial out there for glsl 120, btw.

Hope I helped!

3
General / Re: SFML cicrle movement
« on: December 23, 2018, 04:02:10 pm »
body.move( -sin(body.getRotation()*3.14159265 / 180)*-3, -cos(body.getRotation()*3.14159265 / 180) * 3);

I don't know what that is but my advice is to read the official tutorials such as:

https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php
Mitop's solution is perfect for the problem he wants to solve. The graphics tutorial page don't show how to do it, simply because the issue isn't related to SFML, but to general mathematics.

4
General / Re: How do I make a text box which only accepts numbers?
« on: December 11, 2018, 10:59:03 pm »


This may shock you but pollEvents() polls events  [emoji14]

Yeah of course, and it is also encapsulated for a reason.

Sent from my SM-G950F using Tapatalk


5
General / Re: How do I make a text box which only accepts numbers?
« on: December 11, 2018, 07:18:36 am »
OK I see your points; but if it were me, just for simplicity's sake, I would just paste this one line of code into pollEvents() function for 0 to 9 and be done with it.

case sf::Keyboard::Num0: case sf::Keyboard::NumPad0: objTextBox.input(0); break;
That is not beautiful. You really should use events in this case, but I guess it's up to you.

6
General / Re: How do I make a text box which only accepts numbers?
« on: December 09, 2018, 10:15:05 pm »


I haven't read everything posted, but wouldn't it make more sense to only accept key input from number keys rather than listening to TextEntered? Send sf::Keyboard::Key as a parameter to your textbox class when keys 0 to 9 are pressed.

To me, it makes more sense to use the Event::TextEntered approach, first because it is easier to implement, and secondly because it has been created for this purpose  unlike sf::Keyboard (I think so at least).

Sent from my SM-G950F using Tapatalk


7
General / Re: How do I make a text box which only accepts numbers?
« on: December 06, 2018, 12:46:45 pm »
I believe you can use std::regex_match (c++11) to check if the caracters entered are digits. The actual pattern would be something as simple as this: "^\d$". You can then check for every key that is typed if it is a digit and not write it if it is not.

8
Hi, unfortunatly, in SFML there isn't any built-in classes you can use for lighting, so you should probably use GLSL shaders. I don't know any tutorials right now, but you should find some if you sesrch a bit. I believe SFML only supports shaders up to the version 1.2 of GLSL (#version 120). Also, it is kind of though to implement shadows without a proper understanding on how lightmaps and shadowmaps work, so inform yourself well.

Alternatively, you can use the Let There Be Light 2 (LTBL2) libraby for SFML that is easy to use and really powerful for handling lighting systems with shadow casting. I hope that helped!

Sent from my SM-G950F using Tapatalk


9
General / Re: Do calculations after window.clear(), is it bad?
« on: February 24, 2017, 02:09:04 pm »
For who that are interested, here's my final code:

main.cpp:

#include <SFML/Graphics.hpp>

#include "Tile.h"

void TileArray(std::vector<Tile>& tilemap, int x, int y)
{
    for(int a = 0; a < tilemap.size(); a++)
    {
        tilemap[a].setPosition(a * x, y);
    }
}

int main()
{
    int screenWidth = 1920; int screenHeight = 1080;

    sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), "Colider");

    ///Textures loading

    sf::Texture ground_001;
    ground_001.loadFromFile("Game_Textures/ground_001.png"); ///Walls

    ///Tiles / Tilemaps

    Tile tile(ground_001, 0, 0, 7, 7);

    std::vector<Tile> tilemap(28, tile);

    TileArray(tilemap, 70, 870);

    ///

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

            ///Clear / Draw / Display

            window.clear(sf::Color::Cyan);

            for(int a = 0; a < tilemap.size(); a++)
            {
                   window.draw(tilemap[a]);
            }

            window.display();
        }

    }

    return 0;
}

Tile.h:

#ifndef TILE_H
#define TILE_H

#include <SFML/Graphics.hpp>

class Tile : public sf::Sprite
{
    int xpos, ypos, scx, scy;
    sf::Texture t;

    public:
        Tile(sf::Texture, int, int, int, int);

        Tile();
};

#endif // TILE_H

Tile.cpp:

#include "Tile.h"

Tile::Tile(sf::Texture texture, int x, int y, int scalex, int scaley)
{
    t = texture;
    xpos = x; ypos = y; scx = scalex; scy = scaley;

    this->setTexture(t);
    this->setPosition(xpos, ypos);
    this->setScale(scx, scy);
}

Tile::Tile()
{

}

As you can see, I removed the TileArray class, and I replaced it by a function.

10
General / Re: Do calculations after window.clear(), is it bad?
« on: February 24, 2017, 01:41:46 pm »
Thanks a lot, sir Laurent, I'll take care of what you said.

11
General / [SOLVED ]Do calculations after window.clear(), is it bad?
« on: February 24, 2017, 01:29:40 pm »
Hi,

so I did a small code for do a sort of tilemap, that uses an std::vector of a class that inherits of sf::Sprite. So basically, a

std::vector<sf::Sprite> tilemap(i, sf::Sprite(sprite));

But I have to draw this tilemap in the constructor, where other operations are done. So I am basically doing this:

 window.clear(sf::Color::Cyan);

    std::vector<Tile> tilemap(i, Tile(tile));

    for(int a = 0; a < tilemap.size(); a++)
    {
        tilemap[a].setPosition(a * xpos, ypos);
    }

    for(int a = 0; a < tilemap.size(); a++)
    {
        window.draw(tilemap[a]);
    }

     window.draw(hero);

     window.display();

This is my till class, that inherits of sf::Sprite.

Tile::Tile(sf::Texture texture, int x, int y, int scalex, int scaley)
{
    t = texture;
    xpos = x; ypos = y; scx = scalex; scy = scaley;

    this->setTexture(t);
    this->setPosition(xpos, ypos);
    this->setScale(scx, scy);
}

Tile::Tile()
{

}

So my question is, is it bad, to do things beetween window.clear and window.display, or that doesn't matter? Will that impact the framerate of the program?

Thanks

Ah, I have of course done a class for do the vector and all, TileArray:

#include "TileArray.h"

TileArray::TileArray(int I, int x, int y, Tile &tile, sf::RenderWindow &window)
{
    i = I;
    xpos = x; ypos = y;

    std::vector<Tile> tilemap(i, Tile(tile));

    for(int a = 0; a < tilemap.size(); a++)
    {
        tilemap[a].setPosition(a * xpos, ypos);
    }

    for(int a = 0; a < tilemap.size(); a++)
    {
        window.draw(tilemap[a]);
    }
}

12
General / Re: SFML 2.4 bugged?
« on: November 26, 2016, 12:50:37 pm »
My dlls are the good ones in the right place, because with the 2.2 version it works (if I replace the 2.4 dlls with those of the 2.2 of course). I'm using windows 7, not linux, sorry!

13
General / Re: SFML 2.4 bugged?
« on: November 20, 2016, 10:40:44 pm »
I tried the version 2.4.1, with this code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

It's directly taken from the learn page of this site. I use Code::Blocks with the dynamic version of the sfml. There was no compile errors, but instead of having a green CircleShape, the window was blank. In the console, it was written this message: "Failed to open window's context" that usually appears in multi threading or something like that. And the message was written over and over, at each frame.

14
General / SFML 2.4 bugged?
« on: November 20, 2016, 12:53:04 pm »
Hello everyone. I saw that sfml 2.4 was released a few days ago, so I decided to try it out. I installed it and copied/pasted the example code of the sfml tutorial to see if it works. But the console said that he failed to open window's context or something like that. So I thought that maybe, it was my installation of the new sfml that was wrong. I installed the sfml 2.2 again to test, but with the old version, it works perfecty. Am I just stupid, or is it a real problem?

15
General / Re: [Solved] sf::Event in Button class
« on: August 04, 2016, 12:53:10 pm »
Ok, Hapax, thanks!

Pages: [1] 2
anything