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

Pages: [1] 2 3 ... 722
1
SFML development / Re: Font/Text Direction
« on: Today at 12:13:40 am »
If you want to PR that change, I'm sure we'd accept it for SFML 3.

My question was more, whether that on its own is really enough/useful if you do want to create your own custom text with vertical layout, or whether one would also need other adjustments.

2
What you can do for relative positioning is set a relative position on the HitPoint, then pass the transform of your player to the HitPoint and a multiply the transform of the HitPoint with the one of the Player, essentially applying all the transformations of the player to the HitPoint.

I also highly recommend to make use of Drawable and Tansformable.
Here's an example, since you seem to use  C#, I've also written in in C#:

using SFML.Graphics;
using SFML.System;
using SFML.Window;

var player = new Player();
player.Position = new Vector2f(75, 150);

var hitPoint = new HitPoint();
hitPoint.Position = new Vector2f(2, -10);

var window = new RenderWindow(new VideoMode(200, 200), "SFML.Net Test");
window.SetFramerateLimit(144);
window.Closed += (_, _) => { window.Close(); };
window.KeyPressed += (_, eventArgs) =>
{
    const int speed = 2;

    var direction = eventArgs.Code switch
    {
        Keyboard.Key.Left => -1,
        Keyboard.Key.Right => 1,
        _ => 0
    };

    player.Position += new Vector2f(direction * speed, 0);
};

while (window.IsOpen)
{
    window.DispatchEvents();
    window.Clear();
    window.Draw(player);
    window.Draw(hitPoint, new RenderStates(player.Transform));
    window.Display();
}

public class Player : Transformable, Drawable
{
    private readonly RectangleShape _shape;

    public Player()
    {
        _shape = new RectangleShape(new Vector2f(20, 20));
        _shape.FillColor = Color.Green;
    }
   
    public void Draw(RenderTarget target, RenderStates states)
    {
        states.Transform *= Transform;
        target.Draw(_shape, states);
    }
}

public class HitPoint : Transformable, Drawable
{
    private readonly RectangleShape _shape;

    public HitPoint()
    {
        _shape = new RectangleShape(new Vector2f(16, 4));
        _shape.FillColor = Color.Red;
    }
   
    public void Draw(RenderTarget target, RenderStates states)
    {
        states.Transform *= Transform;
        target.Draw(_shape, states);
    }
}

3
General / Re: I need help with this
« 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.

4
General / Re: Can you integrate allegro into an sfml window?
« on: May 24, 2024, 08:25:35 am »
Those are OpenGL functions, you'll also have to link OpenGL.

5
General / Re: I need help with this
« 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.

6
General / Re: Texture is not loading
« 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.

7
General discussions / Re: Scroll Wheel
« 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.

8
SFML development / Re: Font/Text Direction
« on: May 22, 2024, 09:52:07 am »
I believe SFML's font would need to adjust a lot more than just providing the horizontal advance when trying to support non-horizontal layouts.

Meaning, I'm not against changing this, just questioning if that's actually helpful.

Also I found this page and the graphics helpful to understand the terminology.



I wonder if that advance is ever used in normal LTR text too or just for column writing systems. FT docs don't say. sf::Text and sf::Font are also a bit iffy for RTL text (technically you can reverse your string before inputting it but that's a bit of a hack to make RTL be just LTR backwards), and has 0 shaping needed for cursive scripts (like HarfBuzz has).
Eventually, we'll be integrating HarfBuzz, but we'd first have to solve the dependency issue.

9
Window / Re: How to 'suspend' fullscreen mode?
« on: May 14, 2024, 08:00:08 am »
What OS and window manager do you use?

SFML doesn't seem to handle alt-tabbing from fullscreen very well, see also https://github.com/SFML/SFML/issues/306

10
Window / Re: Problem handling multiple key stroke
« on: May 13, 2024, 03:50:10 pm »
Your keyboard probably doesn't handle n-key rollover, but has a cheap implementation that will only allow 4-5 keys to be pressed in certain areas of your keyboard.
You're probably receiving some key pressed events, just not necessarily the up and down keys you've configured.

What keyboard do you have?

Try mapping the keys further apart, e.g. WASD for one player and arrow keys for the other.

11
General / Re: Can you integrate allegro into an sfml window?
« on: May 13, 2024, 03:00:16 pm »
Maybe it's possible somehow, but I feel if you have the knowledge to hack those two libraries together, you might as well use a video playback library instead or if you must, port Allegro's addon to SFML.

12
If you use SelbaWard as a library, make sure you're linking it.
If you just want to include the specific files, make sure you've add the *.cpp files to your project.

13
You could just use a vertex array, set the texture position and vertex position.

But this will lead to a potentially unwanted distortion, since the vertex array is made up of two triangles, that are shaped independently.

You may instead want to use Hapax's Elastic Sprite: https://github.com/Hapaxia/SelbaWard/wiki/Elastic-Sprite

14
Graphics / Re: Align the text perfectly centered inside any shape
« on: May 13, 2024, 08:32:39 am »
To center text, you also need to consider its local bounds, for example like this:

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

int main()
{
    auto window = sf::RenderWindow{{800, 600, 32}, "SFML Window"};
    window.setFramerateLimit(60);

    auto font = sf::Font{};
    if (!font.loadFromFile("OpenSans.ttf"))
    {
        std::cerr << "Could not load font\n";
        return -1;
    }

    auto rectangle = sf::RectangleShape{ {300.f, 100.f} };
    rectangle.setOutlineThickness(1.f);
    rectangle.setOutlineColor(sf::Color::Green);
    rectangle.setPosition({ 200.f, 200.f });
    rectangle.setFillColor(sf::Color::Transparent);

    auto text = sf::Text{ "Test 1234", font };
    text.setOrigin(text.getGlobalBounds().getSize() / 2.f + text.getLocalBounds().getPosition());
    text.setPosition(rectangle.getPosition() + (rectangle.getSize() / 2.f));

    auto globalBounds = text.getGlobalBounds();
    auto localBounds = text.getLocalBounds();

    std::cout << "(" << globalBounds.left << ", " << globalBounds.top << ") (" << globalBounds.width << ", " << globalBounds.height << ")\n";
    std::cout << "(" << localBounds.left << ", " << localBounds.top << ") (" << localBounds.width << ", " << localBounds.height << ")\n";

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

        window.clear();
        window.draw(rectangle);
        window.draw(text);
        window.display();
    }
}
 

15
Do you want to cut out this kind of shape from a texture?

Pages: [1] 2 3 ... 722