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

Recent Posts

Pages: [1] 2 3 ... 10
1
Thanks for this!
Its better than what I had for sure.
I made a small improvement by moving the hitpoint object into the player which makes more sense to me.
Unfortunately something still seems a bit inelegant about it, specifically having to pass the new RenderStates() thing to the draw call. But I guess there is no way to make this implicit.
Anyway thanks again!
2
As the title states, Keyboard::isKeyPressed is not working. To demonstrate this issue, I created a simple project to show that it does not work:

#include <iostream>
#include "SFML/Graphics.hpp"
#include "SFML/Window.hpp"
using namespace std;
using namespace sf;

RenderWindow window(VideoMode(1400, 840), "Game Window");

int main(){
    while(window.isOpen()){
        Event event;
       
        if(Keyboard::isKeyPressed(Keyboard::A)){
            cout << 'e' << endl;
        }
        while (window.pollEvent(event)){
            if (event.type == Event::Closed){
                window.close();
            }
        }
    }
}

Even if I pressed A, nothing gets outputted.

Some additional information, I code in XCode on Mac; however, I can't run SFML directly from XCode. Instead, I downloaded SFML through homebrew and ran the code through Terminal. I don't know if this affects the code (it didn't affect it previously) but I figured I might add it.
3
General / Re: Can you integrate allegro into an sfml window?
« Last post by fallahn on May 26, 2024, 11:43:02 am »
Based on your earlier post I assume you're using Dev C++ in which case check their FAQ: https://bloodshed.net/FAQ#9

Else if you're using CMake use the FindOpenGL command https://cmake.org/cmake/help/latest/module/FindOpenGL.html

Or in Visual Studio add "opengl32.lib" to the library list in the project properties and it'll find the file automatically.
4
SFML development / Re: Font/Text Direction
« Last post by eXpl0it3r on May 26, 2024, 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.
5
Graphics / High DPI on MacBook retina display
« Last post by alpha_kotenok on May 25, 2024, 10:45:18 pm »
When making a window, it seems to be scaled twice (with all the pixels) to match non-retina screens (I suppose). However, I am rendering a lot of relatively small text, which looks blurry. I want to use a native MacBook resolution instead. How can I accomplish that?

NSHighResolutionCapable is on. I also tried something like:
 window->setView(sf::View(sf::FloatRect({0, 0}, {(float)windowSize.x * 2, (float)windowSize.y * 2})));
but virtual pixels still remain 2x2.
6
General / Re: I have a problem with background
« Last post by Hapax on May 25, 2024, 10:25:29 pm »
To move the 'view' up, you can simply move the background down. So, draw the background lower.

You could also use an sf::View to do this; it simplifies things. You move the view 'up' and everything gets drawn lower automatically.

Note that when you 'look up', you don't just move the background down; you will also need to draw more of the background above what you could see before.
7
SFML development / Re: Font/Text Direction
« Last post by Hapax on May 25, 2024, 10:21:50 pm »
Indeed, FRex; that was basically the point I was making - that the small change to expose that value would allow custom text classes to make use of it instead of having to skip sf::Font altogether.

The follow-up suggestion of expanded sf::Text's ability would likely be included in sf::Text's overhaul to accommodate the eventual integration of HarfBuzz, if it's what it seems to be to me.

HarfBuzz, by the way, looks like an great thing to be including in SFML if it's possible. Everything being ASCII/English is often due to the simplicity of its use. Making it simple to use any Unicode - ASCII or not - makes it the same to use or not so might as well, right? ;D
8
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on May 25, 2024, 06:53:59 pm »
I can't find out how to link opengl32.lib. I can't locate that file.
9
Graphics / Re: How to draw object with position relative to another object?
« Last post by eXpl0it3r on May 25, 2024, 12:22:17 pm »
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);
    }
}
10
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.



Pages: [1] 2 3 ... 10