We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

41

It's not just about speed of execution, but also about simplicity. Although the software rendering used in this example would be a lot slower than using hardware acceleration (i.e. a GPU), drawing a few bitmaps on screen is such a trivial task that you would not notice the performance drop. However, low-level activity like triangle rasterisation, depth sort ...


40

My name is Kevin, and I'm a programmer/designer at Klei. I wrote a bunch of the animation stuff that we used in the Shank series, Mark of the Ninja, and Don't Starve. Our animators work in Flash. We have a concept of a character 'build' which is a set of body-part symbols with multiple views. Depending upon the fidelity of the given game, there are more or ...


25

My question is: why even bother using something like open gl, sfml, sdl when all you have to do is simply allocate some buffer, pass a bitmap and draw it to the screen? Short: Because its fast (OpenGL, DirectX). Long: You may think you can do this all yourself. Draw pixels to a screen. You might write a small library to draw shapes, like quads or ...


24

While you can implement this using SDL_WarpCursor(), I've run into problems with that method on some platforms. I've had real problems with some platforms not reliably performing the WarpCursor() action, particularly when I've been calling it every frame. Also, remember that on many platforms, the cursor is handled at a higher frequency than your app. ...


22

Split this into several layers. At the lowest layer you have raw input events from the OS. SDL keyboard input, mouse input, joystick input, etc. You might have several platforms (SDL is a least-common-denominator lacking several input forms, for instance, which you might later care about). You can abstract these with a very low-level custom event type, ...


19

This is a very broad question, but generally particle system features can be broken down into a few categories. Here are some general ideas for the sorts of things you might want to have. Emission features define how, when, and where particles are emitted. Continuously generate particles at a fixed rate, or generate a cluster all at once when triggered by ...


17

SDL is a library. OpenGL is kinda library. DirectX is a collection of libraries. None of these are engines. Engines are built with some or all of these though. Understand that you are looking at this in a way which won't allow you to fully understand the scope of these technologies. The term library is thrown around a lot, and it does little here to help ...


15

If your frame time is unpredictable (whether or not this is your fault; the OS may be using resources occasionally, etc), capping to a predictable frame rate that is somewhat lower than your achievable framerate will do a lot for predictable latency, which can make the game feel a lot better. Changing how long between when you process input and render ...


13

void Main::processInput() { Uint8* keystate = SDL_GetKeyState(NULL); //continuous-response keys if(keystate[SDLK_LEFT]) { } if(keystate[SDLK_RIGHT]) { } if(keystate[SDLK_UP]) { } if(keystate[SDLK_DOWN]) { } //single-hit keys, mouse, and other general SDL events (eg. windowing) while(...


13

Your iteration through your objects and removing them is incorrect for (i = 0; i < bullets.size(); i++) { if (!bullets[i].is_on_screen(screen)) bullets.erase(bullets.begin() + i); } Let's say you have 5 bullets. First iteration: Remove bullet at index 0. Now bullets.size() is 4 Second iteration: Remove bullet at index 1. Now bullets.size() is 3 ...


12

Since asked by the thread starter, I elaborate on event managers. I think this is a good way to handle input in a game. An event manager is a global class which allows to both register callback functions to keys and to fire off those callbacks. The event manager stores registered functions in a private list grouped by their key. Each time a key gets fired, ...


12

You will end up using a lot less CPU (multi taskers will thank you) and people on mobile devices will appreciate this, too.


12

When reading the code-example provided by SDL on the SDL_GetPerformanceFrequency I could easily find out how you could calculate a deltatime using these functions. It should basically come down to this for you: Uint64 NOW = SDL_GetPerformanceCounter(); Uint64 LAST = 0; double deltaTime = 0; while (somebool) { LAST = NOW; NOW = ...


11

An SDL_KEYDOWN event is only sent when the key is first pressed. You will receive an SDL_KEYUP event when it's released. You'll want to handle moving in code which gets called every frame, not in response to an event. Inside Avatar::handle_input, you'll instead want to set variables to tell you whether each key is up or down, and update those variables as ...


11

What he does is called software rendering, what OpenGL does is called GPU rendering What's the difference between them? Speed and memory. Rasterization (filling out triangles on screen) takes some time. If you do it on the CPU, you essentially take that time away from game logic, especially if it's not optimized well. And doesn't matter, how small the ...


10

The solution is SDL_SetRelativeMouseMode. How can I have missed that.


10

You should use SDL_Image API, it has one simple function that loads everything: SDL_Surface *IMG_Load(const char *file); More precisely, it loads ICO(Icon)/CUR(Cursor)/BMP, PNM (PPM/PGM/PBM), XPM, LBM(IFF ILBM), PCX, GIF, JPEG, PNG, TGA, TIFF, and XV thumbnail formats. It also has individual format functions such as IMG_isPNG and IMG_LoadPNG_RW. This lib ...


10

You should never, ever, ever, ever, ever use Sleep to control framerate. This has been gone over before and I'll refer you to the other question for discussion of the reasons why. One thing not mentioned there is that at the typical modern refresh rate of 60Hz, and with the typical 1 millisecond granularity of Sleep calls, it's actually impossible to Sleep ...


10

SDL2 doesn't need any functionality to be added for either of those items. Texture batching You yourself can sort the sprites by texture used. The SDL backends can already do draw call batching if they wish to (nothing requires that the Copy command be executed immediately; the only requirement is that it be executed by the time any side effects are ...


9

I have never seen much resources on this subject either, but the best one I've found is probably the: Final Fantasy VII Enemy Mechanics FAQ It provides insight into the enemies AI such as this: AI: Setup { TempVar:TurnsUntilGrenade = 3 TempVar:GrenadeAmmo = 4 } AI: Main { If (Stage == 0) Then { If (TempVar:TurnsUntilGrenade == 0) Then ...


9

You could use the TMX map format used by the Tiled editor (as well as several other map editors). Even if you don't use Tiled yourself, the TMX format supports all the functionality you mentioned and it has several existing loaders/parsers for a variety of languages. It's also very easy to understand the format and extend it for your own game.


9

On tile based GPUs (commonly seen in mobile hardware) it is beneficial to clear the renderer, as it allows the GPU to dispose of the existing cached frame data. Here's a quote from OpenGL Insights, dealing with the benefits of clearing the framebuffer on a tile based renderer: "On a tile-based architecture, avoiding clears can be disasterous for ...


9

Yes, it's possible. No its not a dumb idea. In fact many of the older racing games did something similar. Super Mario Kart is one example. The rendering uses 2d sprites in 3d space instead of polygons, but the physics engine is all 2d.


8

If you're having slowdowns and glitches with SDL software rendering in a 2D game, chances are very slim that OpenGL is going to do anything for you. SDL can run 2D games quickly on a Pentium II or even lower spec machine. In other words, there are problems inherent to how you are making your draw calls. I've had no problems with speed in SDL rendering, and I'...


8

You could have a single public method in your Game class to serve as an entry point (e.g. a method called Run()). Then the only thing you'd need to do inside main() to get everything up and running would be to call that method - nothing more. The Run() method could start by initializing all subsystems and then proceed to enter the main game loop. It should ...


8

If you just want to avoid the singletons you could create instances of every game state you need in your initialization code. Then add these to a map inside the CGameEngine class - for example: game.AddGameState("Intro", new CIntroState()); game.AddGameState("Menu", new CMenuState()); ... You could than add a method to the CGameEngine to retrieve the game ...


8

I usually implement a state-machine similar to this: StateMachine + changeState(State) + getCurrentState() + update() State + enter(StateMachine) + update(StateMachine) + exit() When a state becomes the active state, the StateMachine calls the enter method. The StateMachine continiously calls update on the active state. When the state ...


8

SDL isn't a 3D graphics engine. As is stated in its homepage: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. That "3D hardware via OpenGL" basically means that SDL contains some helper functions to ease cross-...


8

A singleton for your main engine class is perfectly normal. It's even quite acceptable to have one singleton for each of your game's major systems, like graphics and input. I personally prefer a single Engine singleton with all systems as members of that object, but really there's very little difference. A singleton can just be a static global object, ...


8

Do you think it would be a good idea to have each part of the screen (game session) handled by different thread? When it comes to rendering: No! OpenGL and multithreading don't mix well. It's best practice to keep all OpenGL operations to one single thread.


Only top voted, non community-wiki answers of a minimum length are eligible