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

Recent Posts

Pages: [1] 2 3 ... 10
1
Hello, I am facing the following error in my project. I've been working on my SFML projects for the past year and everything worked like a charm until in one project I tried linking SFML via a relative path, which ultimately failed. I am now unable to correctly link SFML in any way to ANY project and I get the same errors always. That includes using the full path to SFML, both the old 2.5.1 which worked fine before and the new 2.6.1 which I recently installed, after I started getting the errors. I suppose I must have changed some crucial global CB setting which I can't remember, but why reinstalling the whole thing doesn't help then?

Before rebuilding the project, the error was ".dll files missing" (sfml graphics and window). After rebuilding, it can't find -lsfml-graphics-d and the other two -d files. I'm using the dynamic version of SFML.

The project is prepared exactly as stated in the very starting part of the tutorial.
https://www.sfml-dev.org/tutorials/2.6/start-cb.php

I have searched the forum only to find solutions which require me to do what I already have done (i.e. below).
https://en.sfml-dev.org/forums/index.php?topic=28993.msg179527#msg179527

I haven't found anything helpful in google/SO either.

It's been tens of hours of pointless troubleshooting from my side now and I can't get anything important done, because suddenly my CB/SFML tandem stopped working and is dead. I did reinstall CB, or rather update it to the newest version to try and get it back to work. I did try using the older SFML version I had been using before (2.5.1) and the newer 2.6.1, but neither one works now. Please, please help me get back to work. Normally. I mean, I would like everything to be as it was before, not to put the .dll files in the same folder as the .exe file.

I use the following download for SFML 2.6.1: "GCC 13.1.0 MinGW (DW2) - 32-bit".

I use the newest release of CB (installed from codeblocks-20.03mingw-32bit-setup.exe).

The include lines in the code that I tried:
- #include "SFML/Graphics.hpp"
- #include <SFML/Graphics.hpp>

My system is Windows 10. The project also uses <windows.h> and is an attempt to mixSFML with WinAPI

Relevant screenshots, I hope that all of them, are attached.

Thank you in advance for your time.



2
General / Re: I need help with this
« Last post by kojack on Today at 03:10:16 am »
For ball to ball collision, you can increase the ball radius by the cue ball radius, now the cue ball can be treated as a single point and use raycasts.
But you don't want to actually grow all of the balls by that amount, because they would then collide with each other early, so you need a temporary larger shape.

I'm just guessing on the code off the top of my head, but I think you could do it like this:
Loop over every ball (not including the cue ball)
   Make a temporary b2CircleShape with the same position as the current ball and larger radius
   Do a shape raycast from the cueball position
End of Loop
Make 4 b2EdgeShape for the table sides that are moved inwards by the cue ball radius as eXpl0it3r said
Do shape raycasts against each edge.
Find which of the above raycasts had a hit closest to the cueball

https://box2d.org/documentation/classb2_circle_shape.html#a442e847b9fc3d1344b02b48d490eb0c6


3
Graphics / How to draw object with position relative to another object?
« Last post by smurf on May 24, 2024, 10:53:43 pm »
I'm always solving this problem in a dumb way and I know theres a better way.

Suppose I have a Player class, and also a HitPoint class.
The Player object contains an instance of a HitPoint object.
When I draw the player, I also want to draw the hitpoint bar near his head.
So what I end up doing is in the Player's render method, I pass the player's relative position to the HitPoint's render method. So that I can draw the hitpoint bar at the same location of the player, but 50 pixels higher and 10 to the left.

What I'd like to avoid is somehow having to pass positions around like that. It seems like my render code is FULL of ugly little offset maths like xPos + xPos2 + 35.

Example of the problem:


class Player {
        int xPos;
        int yPos;
        HitPoint hpBar;
        public void Render() {
                DrawThePlayer();
                hpBar.Render(xPos, yPos);
        }
}
class HitPoint{
        public void Render(int x, int y) {
                DrawRect(x-10, y-50....
        }
}
 


So for example I'd prefer to have the HitPoint Render method look more like this


class HitPoint{
        public void Render() {
                DrawRect(0, 0)
        }
}
 

So I'm drwaring the hitpoint bar from (0,0) and not worrying about the Player's  position. Something else will "move" the hitpoint bar to the right place.

4
General / Re: I need help with this
« Last post by eXpl0it3r on May 24, 2024, 10:43:46 pm »
For the table's side, you'd have to provide Box2D a table size minus the radius of the cue ball on each side, then do a line cast. If the line hits the wall, you know that ball would hit the side.

For ball to ball, it's a bit trickier, since balls can hit a different angles. Not sure what options Box2D provides here, but circle to circle collision check is really simple. If the distance of points is smaller than the combined radi of the two circles, you have a collision.
5
General / Re: I need help with this
« Last post by Yosef on May 24, 2024, 07:52:47 pm »
I want to perform a circle cast for the cue ball as the player aims, stopping when it encounters an obstruction like other pool balls or the table's sides. Since Box2D doesn't support circle casting yet, how can I achieve this?
6
General / Re: Can you integrate allegro into an sfml window?
« Last post by eXpl0it3r on May 24, 2024, 08:25:35 am »
Those are OpenGL functions, you'll also have to link OpenGL.
7
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on May 24, 2024, 02:45:11 am »
Thankyou very much. That definitely solved the conflicting declaration issue.
I'm still having two errors.
undefined reference to `_imp__glBindTexture@8&#39;
undefined reference to `_imp__glTexImage2D@36&#39;
 

I guess since it works for you it must be because my SFML version must be incompatible with this. I use sfml 2.4.0.
8
General / Re: I need help with this
« Last post by eXpl0it3r on May 23, 2024, 11:36:42 pm »
I'm not quite sure what you mean with "determine the position of the outline of the cue ball". Do you mean the shortest ray to the border of the cue ball? Wouldn't we also need to know where this is casted from to answer the question?

Maybe there's also an entirely different question hidden underneath. Can you describe what you're trying to solve currently?

Also might be useful if you could provide some code.
9
General / Re: Texture is not loading
« Last post by eXpl0it3r on May 23, 2024, 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.
10
General / Texture is not loading
« Last post by floppa_dev2 on May 23, 2024, 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
Pages: [1] 2 3 ... 10