Tag Info

New answers tagged

1

If my assumption that you want your speed to lose 2% of its value every second, then this is a perfect opportunity to use the exponential rate of decay expression, which looks like this: A=Pe^(rt) A is the final amount you want (so, after 1 second, .98(vx)) and P is the initial amount. t is just time, so since you want the velocity to only be 98% of its ...


12

Don't actually stop the game loop when pausing the game. Instead, you have to add bool variable, that is changed to true/false depending if game is paused. If game is paused, you only have to stop updating the game, but you can still keep rendering the current frame including getting updates from input. if(gameIsPaused == false) { // run updates } ...


1

Make it so that pressing P switches to another loop that handles the game state "Paused" and allows to transition back to the original game loop by pressing P again. You can actually put this all into the game loop itself and introduce a state variable, if you want and instead of turning off the loop, the state variable toggles between the execution of the ...


0

I found a solution, just if somebody encounters the same problem some way.. The iteration switches now betweeen 0 -> max and max -> 0 each frame. Now the fish is spreading as it should.


1

First, lets get this out of the way, aiming for 100k user is ridiculous for semester project. Aiming for 100k users playing in one physical server is insane for any game. XNA is not an engine and no where near as high level as Unity. XNA just provides nice set of code, gathered in library with all the necessary "boilerplate code" done. It is DirectX for ...


0

In your EXAMPLE 1, you're gathering all your player input first, and then doing the move as part of logic(). In your EXAMPLE 2, you're moving the player-object as part of gathering the input. EXAMPLE 2 is ok if there's nothing else that influences the player besides the user input. But usually what happens to each game object (including the player) might ...


1

I assume you mean whether you should be doing active polling or listening to events. Active Polling means that you check the state of your input devices on every update. For example, the Logic() (or Update() or Tick()) function of your character could contain: if (input.isPressed(KEY_RIGHT)) { positionX += 10; }. Events on the other hand let you react to ...


0

BufferStrategy will often use VolatileImage for the buffer. Part of the use case of volatile image is that its backing buffer may be lost without warning. This require you to rerender to the volatileImage. What you can do as an optimization is test both contentsLost and contentsRestored inside the inner while loop and repeat the loop using continue if ...


0

(Two ideas here. See bottom for the "simpler" one.) Answering exact question: (Instantiate each time the player reaches right/left edge) Assuming your stages are of similar complexity to those in the video you linked, you can simply give unique GameObject tags to each of the dynamic (can be destroyed/deleted) children in the prefab. Then have a global ...


3

When writing your main loop and updating logic, you've got two basic strategies, which you're probably aware of: fixed time steps and dynamic time steps. Either way your updates will happen at some time. There are basically two ways to write this - both which you identified already: Version 1: while (running) { update(); draw(); } Version 2: ...


3

The typical implementation is Update first, then Render. I guess this is because it reduces input latency. In Update-First you see changes on the current frame (U - update, R - render, F - frame, [wait] - wait for V-Sync): U1->R1->[wait]->F1 => U2->R2->[wait]->F2 In Update-Last you see changes on the next frame (F1 is two [wait] later ...


1

One call to Render() usually equates to many calls to Update() and Render() is usually called about 60 times per second. That usually equates to: void Frame(float elapsedTime) { static float accumulatedElapsedTime = 0; accumulatedElapsedTime += elapsedTime; while (accumulatedElapsedTime >= fixedTimeStep) { Update(fixedTimeStep); ...


3

You can't reliably control the FPS with functions like SDL_Delay, they call the operating sleep function, which tells the operating system "Please don't give me any CPU time for at least N miliseconds", the operating system is then free to decide: At what granularity (i.e., as you said you specify 1ms and it waits for 15ms, it has a granularity of 15ms) ...


0

A mistake that I made this week doing this : while (!quit){ startTime = SDL_GetTicks(); Process Input(); Update Game(); Render(); endTime = SDL_GetTicks(); DeltaTime = endTime - startTime; } I do not know exactly Why, But this did not work at all. the solution @Tordin gave is the best one, and I have seen it in many many many references and ...



Top 50 recent answers are included