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

Pages: [1] 2 3 ... 22
The view controls how the scene is mapped onto the window. But when a window resizes, the view isn't modified. So you'll need to generate a new view. For example:
                                if (event.type == sf::Event::Resized)
                                        sf::Vector2u size = g_window.getSize();
                                        g_window.setView(sf::View(sf::Vector2f(size.x / 2.0f, size.y / 2.0f), sf::Vector2f(size.x, size.y)));

General / Re: I have a problem
« on: May 19, 2024, 09:08:51 am »
The biggest hit here is that you are loading the background jpg from disk every frame. It really should be loaded just once at the beginning then reused, like the hero sprite's texture.

General / Re: Can you integrate allegro into an sfml window?
« on: May 15, 2024, 11:32:16 am »
If you don't need audio, OpenCV is very easy to get working in SFML (1 line of code to load a video, about 5 lines to read a frame into a texture, do that with a timer). I haven't done much with it, I was just testing security camera footage analysis and playback, so the video was already low framerate.

Views are like cameras in other engines. They transform SFML coordinates into window coordinates.
By default it's a 1:1 pixel scale. So coordinates 100,100 in SFML would be pixel 100,100 in the window. But you can change the position, rotation and scale of the view, which lets you pan around and zoom on the scene without messing with what's rendered.

It might be a good idea to also try the program at the same window size on both. Currently the windows one is 1910x1102 and the mac is 3474x2214.
Also the mac screenshot appears to have the right side cut off, the rounded corners of the window aren't visible on the top or bottom right.

Window / Re: Problem handling multiple key stroke
« on: May 13, 2024, 05:25:58 pm »
Yep, sounds like keyboard ghosting / ghost keys.
Microsoft have an webpage demo that can help find ghost keys (basically just highlights keys on screen as you press them): https://www.microsoft.com/applied-sciences/projects/anti-ghosting-demo

Most non gaming keyboards have ghosting, which keys ghost depends on the keyboard hardware.
Some keyboards will have a rating like 4-key rollever which means you are guaranteed to be allowed to press 4 different keys at once before ghosting happens. A keyboard with n-key rollover can handle any number of keys at once.

If we're talking about arcade machines based on a PC, it depends on how the controls are hooked up. One popular device (I've even got one here somewhere) is the I-PAC2. It's a $39 device that lets you wire up 2 arcade joysticks with 8 buttons each (and some extra like player 1 and 2) and emulate a keyboard. No coding needed. The good thing is it has no ghost keys.

One option if you are just testing is to plug in two keyboards at once. Definitely for Windows and maybe for Linux (not sure) keyboards are merged into one system device. So software like SFML sees one keyboard but really it gets the results of both merged together. That would still have ghosting on each keyboard, but not one ghosting the other.

So yeah, this is a keyboard hardware issue, not the fault of the OS, SFML or USB.
(Also very annoying. My sister worked out the keys on my old keyboard that she could press while we were playing Mortal Kombat 3 that would stop my jump and kick keys from registering)

General / Re: Can you integrate allegro into an sfml window?
« on: May 13, 2024, 05:07:34 pm »
I guess it depends on what you require as to whether Allegro is a good idea.
Taking a look at the official Allegro video addon, it only supports Ogg Theora video files and the top of the main source file says:
/* This is just a quick hack. But good enough for our use of displaying
 * a short intro video when our game starts up - so might as well share
 * it.
 * Known bugs:
 * - Only very crude synching. Audio is slightly delayed and some
 *   videos seem to constantly drift off and then the audio gets all
 *   distorted...
 * - Seeking/Pausing doesn't really work.
 * - Memory leaks. Easy to fix but don't have time right now.

Render textures need to have display() called on them after drawing on them for them to update correctly.
So after rendertexture.draw(myText); put a rendertexture.display(); and see if that helps.

Graphics / Re: Align the text perfectly centered inside any shape
« on: May 12, 2024, 11:45:27 am »
Did you also make the text variable a reference?
You need getText() to return a reference and sf::Text text; to be sf::Text& text;
Otherwise text will be a copy of the referenced object.

The same xOffset and yOffset are used by all shapes to move. When one shape reaches the edge it changes the direction, so all shapes change direction since they share the offsets.

You'll need to keep separate xOffset and yOffset for each shape, such as with an std::vector<sf::Vector2f>

General / Re: Is SFML message-driven or event-driven?
« on: April 29, 2024, 04:49:10 pm »
Not really correct.
SFML apps are not specifically event driven. Usually the main application loop will do an inner event loop for some things like resizing the window or doing event based keyboard/mouse stuff, but the events are not used for game state or rendering (and input can also be done without events).
Events only happen when something like a key is pressed or something happens to the window, but a game needs to run continuously, faster than events come in. So it's not like an event based application like Winforms or similar.

General / Re: Smooth character movement with Arrow keys
« on: April 29, 2024, 02:31:05 pm »
The issue with the top post was that immediate key tests were being done only even events came in.

Imagine you press left arrow, hold it for 5 seconds, then release.
Also imaging you are running at 60fps.
There will be one key down event. 5 seconds later there will be a key up event. But for those 5 seconds in between, there are no events.
An immediate key check (sf::Keyboard::isKeyPressed) doesn't tell you when a key goes down or when it goes up, it tells you the current state. If you call it in the main loop, you'd be calling it 60 times a second and it would tell you the current state.
But in the top post it was only being called twice, not every frame, so the movement wasn't happening every frame.

Another way of structuring it would be to use the events only but get them to set a bool to say the key is currently down or not. Then you'd check the bool (instead of the key directly) outside of the events. So a key down event sets the bool to true, key up event sets it to false. You can now check it as often as you want.

(Actually there may be more events coming in from operating system key repeats when a key is held, but it won't be at 60fps)

General / Re: How can I use stbi writing functions?
« on: April 29, 2024, 09:20:04 am »
Basically stbi needs a single instance of some things that can't safely be done in a header. Those defines let it create the objects that it needs.
If you used the stbi headers in for example 5 cpp files, you need to do the defines in just one cpp, the other cpps would do the includes without defines. If you do the defines in more than one cpp, you'll get the multiple definition error.

General / Re: How can I use stbi writing functions?
« on: April 28, 2024, 11:04:39 pm »
In one (and only one) of your cpp files that includes the stbi headers, you need to do some defines before the includes:
The first one is needed for the reading functions. The second one for the writing functions.

Audio / Re: Music not playing even though its loaded.
« on: April 24, 2024, 08:56:45 am »
I tried the same code (both global and local window) and music played fine in both cases. Although I'm using SFML 3 so maybe it doesn't have the issue.
I even tried playing the music without a window and it worked. (I replaced the while open loop with a Sleep(10000)).

But I see some bits of the audio system have changed since SFML 2.5 with how the global audio device is handled.

Pages: [1] 2 3 ... 22