Contents
How can I achieve this in SDL2?
Can I achieve this in SDL2. If not what’s the way of doing this. By using SDL_RenderCopy you can do all the zoom in/out or scaling stuff, by using non null values for the srcrect and dstrect parameters. So you just need to create two SDL_Rect and setup them accordingly.
How to handle multiple keypresses at once with SDL?
If you’re using SDL2 then use SDL_GetKeyboardState. Instead of only looking at keydown events, any solution which is going to be caring about multiple keys at once is going to have to be looking at both keydown and keyup events, and keeping track of the state of the keys in question.
How to handle multiple events in SDL2 and C + +?
There are a few ways to handle this problem, but obviously, paramount to every possible solution, is the removal of your destructive SDL_PollEvent while loops every time you want to handle input. The solution most similar to your current implementation would be of this nature:
How to update the movement magnitude in SDL?
You can access this state via: So, each iteration you can update the movements based on the key state. To make the movement smooth you should update the movement magnitude based on the time elapsed between updates. If you’re using SDL2 then use SDL_GetKeyboardState.
What is the camera zoom ratio in SDL?
Personally I used SDL_RenderSetScale since just takes in two floats for the ratio eg SDL_RenderSetScale (renderer, .5f, .5f) for rendering everything half as large. Here’s my personal generic camera function for tracking two players and centering around them: which in action looks like this.
How to change the size of the SDL window?
In the switch, use the flag SDL_WINDOWEVENT_RESIZED if you want only the final size of the window or SDL_WINDOWEVENT_SIZE_CHANGED if you want all the sizes between the first and the final. To finish, update your own camera with the new window width and height. Thanks for contributing an answer to Stack Overflow!
What happens if you zoom in by 2x?
Zooming in by, say, 1.5, will cause the distortion. Zooming in by 2X every time will cause much stronger zooming, so you’ll have to make a decision on which is more important, the lines or the zooming factor. Alternatively, you could change the way the lines are rendered.