Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (715)
Games in Android Showcase (214)
games submitted by our members
Games in WIP (788)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  The "Delta" variable [RELOADED]  (Read 1524 times)
0 Members and 1 Guest are viewing this topic.
Offline Kryel

Senior Newbie

« Posted 2012-08-18 00:37:40 »


Shall we talk a bit more about that delta variable ?
I did understand the concept behind it, but there's still something I don't get.

I'm still using the < app.setTargetFrameRate(60) > easy mode, but I wish I could use the delta someday.

When you use assisted-tools/makers (Game Maker & such), you usually don't have to worry about the time because when you set the FPS to 60, you're pretty sure that a script in there will be called 60 times per second (probably less if lagging, but no more)
That bit is really important for, say, fighting games, when you want to have a character's punch last for exactly 5 frames.
Still, when I try to think on how to achieve this with the delta variable, my mind doesn't seem to be able to resolve this.  Angry

For example, lots of game use something like < posX += velocity * delta >, but I don't see how I can apply something like that for a game when I want to make absolutely sure that each "important" frames are shown.
If a ball were to bounce off a wall, with proper collision code it won't be a problem but isn't there a risk that you "won't see" the ball bouncing off the wall?
To be precise, let's say that we have something like that :

//velocity = 1, T stands here for Time, or a Tick in the game loop actually.
T1: x += velocity; //x - 2
T2: x += velocity; //x - 1
T3: x += velocity; //x reached -> bouncing -> velocity *= -1
T4: x += velocity; //x - 1 (moving away)

It may be my imagination but let say that I put some sort of a pause-shining-effect at T3, isn't there a risk that it might just be ignored since the time elapsed went straight from T2 to T4 due to the delta variable? ... I don't know, I just feel like I'm misunderstanding something about the delta variable here.

Edit : Since my english is bad, here's a little picture of what I'm trying to say :

Note that since it went straight for a position to another due to delta, I somewhat "missed" the time when i want to "pause" the game.
Offline jezek2
« Reply #1 - Posted 2012-08-18 01:23:47 »
Offline Best Username Ever

Junior Devvie

« Reply #2 - Posted 2012-08-18 04:40:18 »

Make sure your physics, rendering, and user input response are all done separately. Prioritize physics so that when there is lag you only lose a few frames instead of delaying game play and messing up the player's timing. Run the physics simulation in discrete (no delta) steps so that the simulation is consistent, predictable, and easier to debug. Record the user's input and wait until the next (physics) update cycle to process it. Save the time the event occurs so that all commands are processed in the right order and in relation to the user's perception of the game state. Render as often as you can in the time you have left, using linear interpolation to smooth the paths of fast moving objects.

If the user can react with objects directly and you want twitch reaction style game play (such as aiming at a moving character) then use the time you recorded as a result of user input to inform the physics engine so it can do similar interpolation such that it can calculate a hit or a miss accurately even if user input came midway through a physics update cycle.

If you have problems with inaccurate graphic rendering interpolation then calculate potential collisions one step ahead of time. Store the start coordinates, the collision coordinates, the collision time, and the end coordinates. Interpolate between the start and middle coordinates if you're rendering before the collision will/might happen or between the middle and end coordinates otherwise. Don't bother with this though unless it seems like things are temporarily flying through walls due to an uninformed graphics interpolation.

Don't rely on effects that last an exact number of frames. There's no guarantee the player will get those frames and if you're talking about a very brief animation then it probably is happening too fast for the user to notice that level of detail. If you still want to provide the visual cue you can jump into the middle of an animation and try to show what you can, replace long shining/glowing/sparkling effects with an easy to render quick flash effect or overlay multiple frames as if you were trying to do motion blurring.

Don't worry about the user not seeing the ball hit a wall. If the physics engine responds correctly and most of the frames show the ball in its correct spot the player will see an "optical illusion" and know the ball hit the wall even if they don't see it at that exact motion. Even if you do happen to render at that exact correct time, there's still a chance the player will blink. And blinking doesn't throw off a person's perception for things like that, even in real life.

You can update at a fairly low rate like 20 ticks per second and a higher frame rate like 60 fps and get a very realistic result. And by saving input times and processing them in the correct order you can still maintain correct responses even if you have multiple players on a single computer or if the user sends a series of commands in the same update cycle. At worst feedback will be delayed the length of your update cycle but everything else will be accurate, including (and most importantly) timing.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

CopyableCougar4 (205 views)
2017-03-24 15:39:42

theagentd (187 views)
2017-03-24 15:32:08

Rule (246 views)
2017-03-19 12:43:22

Rule (229 views)
2017-03-19 12:42:17

Rule (234 views)
2017-03-19 12:36:21

theagentd (253 views)
2017-03-16 05:07:07

theagentd (249 views)
2017-03-15 22:37:06

theagentd (182 views)
2017-03-15 22:32:18

theagentd (176 views)
2017-03-15 22:31:11

ral0r2 (165 views)
2017-03-03 11:52:41
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!