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
1
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.
https://www.sfml-dev.org/tutorials/2.6/graphics-view.php

2
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.


3
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)

4
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:
Quote
/* 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.
https://github.com/liballeg/allegro5/blob/master/addons/video/video.c

5
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.

6
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.


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

8
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.

9
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)

10
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.

11
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:
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
 
The first one is needed for the reading functions. The second one for the writing functions.

12
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.

13
General / Re: Pass int/char array to sf::Uint8 array?
« on: April 21, 2024, 11:30:33 pm »
If we're dealing with 32bit colour (usually are), a char is only a quarter of the colour. But an int can hold an entire colour at once. So right now you are working with quarter pixels instead of whole pixels.

Having
unsigned int* pixels = new unsigned int [1280 * 720];

for (int i = 0; i < 1280 * 720; i++)
    pixels[i] = 0xff0080ff;  // that should be orange on an RGBA 32 bit pixel, which is what SFML uses
Means you are working one pixel at a time, and the for loop code does a quarter of the work.

14
General / Re: Pass int/char array to sf::Uint8 array?
« on: April 21, 2024, 02:23:39 pm »
One thing to be careful of is where that Array is created and which compiler you are using.
Local variables like arrays are created on the stack (whereas things made using "new" are on the heap). Visual Studio C++ only allocates 1MB for the stack by defaultr, but your array is using almost 4MB. So overflowing the stack could cause an issue.

Otherwise it should be fine.

15
General / Re: Pass int/char array to sf::Uint8 array?
« on: April 21, 2024, 03:03:00 am »
If you mean for passing to the texture update method, as long as the size is correct (and the data makes sense) you can pass in any kind of array if you cast the pointer type.
int *pixels = new int[WIDTH * HEIGHT];
texture.update((const std::uint8_t*) pixels);

Pages: [1] 2 3 ... 22