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

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Texture is not loading
« Last post by eXpl0it3r on Today at 02:36:21 pm »
You can't just put an object outside of any scope and expect it to just work. ;)
You need to learn a bit more about scopes and lifetime, plus compilation units.
It's recommended to not use global variables, but use the class scope, if you want to share something across multiple functions.

Maybe you actually wanted to load the texture on the tile class instead of bgtex that lives outside of everything?

Personally, I recommend to use something like a ResourceHolder and pass a reference to where you want to use a texture.
2
General / Texture is not loading
« Last post by floppa_dev2 on Today at 02:16:58 pm »
Hello! I am trying to make a small platformer game but I have a huge problem, the texture isn't loading.
https://github.com/epicfloppadev/floppa/ this is the github name
So I have this code in src/tile.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
class tile
{
public:
    bool activated = 0;
    Vector2f position={0.f,0.f};
    Sprite sprite;
    Texture texture;
};
Texture bgtex;
void loadTiles(tile tiles[][14])
{
    bgtex.loadFromFile("Images/tile.jpg");
    for (int i = 0; i <= 12; i++)
    {
        tiles[6][i].activated = 1;
    }
    for (int i = 0; i <= 7; i++)
    {
        for (int j = 0; j <= 13; j++)
        {
            tiles[i][j].position={float(100*i), float(100*j)};
            tiles[i][j].sprite.setPosition(tiles[i][j].position);
            if (tiles[i][j].activated == 1)
            {
                tiles[i][j].sprite.setTexture(bgtex);
               
            }
        }
    }
}
void display_tile(tile &object, sf::RenderWindow &window)
{
   
    window.draw(object.sprite);
}

this code in main.cpp:

#include "smth.hpp"
#include "grass.cpp"
#include "tile.cpp"
using namespace sf;
bool jumping = 0;
float jump_velocity = 0;
float accelerationV = 0.5;
float speedV = 0;
bool o_g = 0;
int main()
{

    tile tiles[8][14];
    loadTiles(tiles);
    //
    // Music battle;
    // battle.openFromFile("Audio/battle-of-the-dragons-8037.wav");
    // battle.play();
    Object player = {{500, 500}, 0},
           bg{{1000, 1000}, 0};
    if (!player.texture.loadFromFile("Images/big-floppa-player.png") || !bg.texture.loadFromFile("Images/bg.jpg"))
    {
        return -1;
    }
    player.sprite.setScale(0.7, 0.7);
    init_grass();
    bg.sprite.setTexture(bg.texture);
    player.sprite.setTexture(player.texture);
    RenderWindow window(sf::VideoMode(1280, 720), "Super Floppa", Style::Titlebar | Style::Close);
    Clock clock;
    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {

            if (event.type == Event::Closed || Mouse::isButtonPressed(Mouse::Right))
                window.close();
        }
        Time elapsed = clock.restart();
        float dt = elapsed.asSeconds();

        if (Keyboard::isKeyPressed(Keyboard::A))
        {

            speedV += accelerationV;
            if (speedV > maxSpeedV)
                speedV = maxSpeedV;
            player.position += {-speedV, 0.f};
        }
        if (Keyboard::isKeyPressed(Keyboard::D))
        {
            speedV += accelerationV;
            if (speedV > maxSpeedV)
                speedV = maxSpeedV;
            player.position += {speedV, 0.f};
        }
        else
        {
            speedV -= (-1 * bool(speedV < 0)) * accelerationV;
        }
        if (Keyboard::isKeyPressed(Keyboard::Space) && !jumping)
        {
            jumping = 1;
            o_g = 0;
            jump_velocity = sqrt(2 * GRAVITY * JUMP_HEIGHT);
        }
        if (o_g == 0)
        {
            player.position.y -= jump_velocity * dt;
            jump_velocity -= GRAVITY * dt;
        }
        if (touch_grass_lol(player, grass))
        {
            jumping = 0;
            o_g = 1;
            player.position.y = grass.getPosition().y - player.texture.getSize().y * player.sprite.getScale().y;
        }
        if (dt < 1.f / 60.f)
        {
            sleep(sf::seconds(1.f / 60.f - dt));
        }
        std::cout<<tiles[1][1].sprite.getTexture().getSize();

        window.clear();
        //   window.draw(bg.sprite);
        // window.draw(grass);
        for (int i = 0; i <= 6; i++)
        {
            for (int j = 0; j <= 12; j++)
            {
                if (tiles[i][j].activated == 0)
                {

                    display_tile(tiles[i][j], window);
                    // std::cout<<tiles[i][j].position.x<<&#39; &#39;<<tiles[i][j].position.y<<std::endl;
                }
            }
        }
        display_smth(player, window);
        window.display();
    }
    return 0;
}
when I am running the program the texture is not showing but if i modify the player texture to be bgtex(the tiles texture), the texture is showing as normal, what should i change in the loadTiles() function
3
General / Re: Can you integrate allegro into an sfml window?
« Last post by fallahn on Today at 10:56:07 am »
Just tried it with gcc and there were a few typos which needed fixing 😅

I've updated the repo with a version that I've tested on my linux box and added a CMake project for the demo if you'd like to try it.
4
SFML development / Re: Font/Text Direction
« Last post by FRex on Today at 06:26:52 am »
Adding vertical advance in sf::Font would unlock one thing: let users write own text code that does the vertical layout. I think this was the point Hapax made.

Same as now sf::Text has no per letter color, style, etc. but you can write a class that does, all using sf::Font, never dealing with FreeType yourself, or how in general you can make own drawables using vertex arrays or buffers.

Now if you want vertical text, you'd have to use FreeType 100% by yourself, just to get that y from advance that sf::Font doesn't expose (I'm not sure if anything else is missing or if just this one field will allow it).
5
After a bit of experimenting, that solution partially worked. I figured it out so I'm going to mark the thread as solved, but for anyone who runs into this issue:

Resetting the window view is NOT enough to solve this on its own. The flow of code should be something like this:
if (event.type == sf::Event::Resized) {
        window.setView(sf::View(sf::Vector2f(window.getSize().x/2.f,window.getSize().y/2.f), sf::Vector2f(window.getSize().x, window.getSize().y)));
        for (auto& i : sprites) {
            i.setPosition(/*new position */);
        }
       
    }
You must adjust every drawn object/sprite's position after you change the sf::View, otherwise each drawn object is stuck with an arbitrary sf::View based on the time it was drawn before/after the resizing of the window.
6
General discussions / Re: Scroll Wheel
« Last post by eXpl0it3r on May 22, 2024, 10:38:53 pm »
Have you tried the sf::Event::MouseWheelScrolled event? See the tutorial.

Or are you saying that your mouse has more than one scroll wheel?

As for buttons, SFML also supports two extra mouse buttons.
7
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on May 22, 2024, 09:23:06 pm »
I don't think that's the problem.
The header files are not listed in the cmake file.
# Project: Project1
# Makefile created by Dev-C++ 5.11

CPP      = g++.exe
CC       = gcc.exe
WINDRES  = windres.exe
OBJ      = main.o VideoTexture.o
LINKOBJ  = main.o VideoTexture.o
LIBS     = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -L"C:/SFML-2.4.0/lib" -static-libgcc -lsfml-graphics -lsfml-network -lsfml-audio  -lsfml-system -lsfml-window -m32
INCS     = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS  = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"C:/SFML-2.4.0/include"
BIN      = Project1.exe
CXXFLAGS = $(CXXINCS) -m32 -std=c++11
CFLAGS   = $(INCS) -m32 -std=c++11
RM       = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
        ${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
        $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

main.o: main.cpp
        $(CPP) -c main.cpp -o main.o $(CXXFLAGS)

VideoTexture.o: VideoTexture.cpp
        $(CPP) -c VideoTexture.cpp -o VideoTexture.o $(CXXFLAGS)
8
General / I need help with this
« Last post by Yosef on May 22, 2024, 08:03:37 pm »
I'm developing a pool game using SFML and Box2D, and I'm currently facing an issue with creating the cue ball outline when the player aims. I have three rays that are cast: two black ones and one white one. How can I determine the position of the outline of the cue ball using the shortest of these rays as the player aims. I am using the ray cast function of box2d.

I have attached picture of the outline for further reference

9
General discussions / Scroll Wheel
« Last post by clampflower on May 22, 2024, 05:23:19 pm »
Hi All,

Apologies, as I am fairly new to this game.  I have been programming in C++ / SFML for a while now (months) but got stuck on mouse wheels. How do I use SFML to detect which way a vertical mouse wheel has been scrolled? I am using a Logitech mouse that has a pile of buttons and wheels but the main vertical wheel is the one that I want to detect.

I have been playing Forge of Empires and this scroll wheel controls the zoom function of the map, which is great and so I know this is doable. Would very much appreciate any help.

Many thanks

Moon.
10
General / Re: Can you integrate allegro into an sfml window?
« Last post by fallahn on May 22, 2024, 05:22:14 pm »
It depends on you compiler/toolchain setup.

For example Visual Studio lists 2 folders in its source tree "Header Files" and "Source Files". Only the files which are included in the "Source Files" folder are sent for compilation. It's at this point any header files which are #include 'd in the *.cpp files are pulled in by the compiler for compilation. (Well, kinda, they're put in place by the preprocessor just before compilation).

On the other hand *.hpp files listed in the "Header Files" section are ignored, except for when they're explicitly #include 'd in a *.cpp file. If you try adding an *.hpp file to the "Source Files" folder, Visual Studio will try to compile it directly which may or may not be what you want (probably not in most cases, and definitely not in this specific case).

Other toolchain/compiler setups are similar: you list the source files (*.c and *.cpp) you want to compile, followed by the directories containing the header files. That way the compiler will only pull in any header files for compilation as is needed.

So what I mean is - make sure the *.hpp files are not being added to the list of files to be compiled, either by accidentally adding them to the "Source Files" folder in Vidual Studio, or by any other means with a different compiler.
Pages: [1] 2 3 ... 10
anything