Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  what is a Tick????  (Read 493 times)
0 Members and 1 Guest are viewing this topic.
Offline WolfAlvein

JGO n00b
*

Posts: 10



« on: 2012-01-20 19:02:50 »

Hi everyone.

Well iI was wandering what a tick process is I mean I have the source code for minicraft that notch gave to everyone and I was reading his code to see if I can grasp some of the techniques he uses when programing and I came about the tick function, and didn't quite understand it... can anyone illustrate me what a tick is supposed to do??? I don't need the knowledge of what notch was trying to acomplish I just wan't to understand what a tick is....
Offline StonePickaxes

Full Member
**

Posts: 204
Medals: 3


Nathan Kramber


« Reply #1 on: 2012-01-20 19:26:20 »

A "tick" is just updating the game logic.

Rendering is updating the stuff shown on screen.

-Nathan

Check out my website!
Offline WolfAlvein

JGO n00b
*

Posts: 10



« Reply #2 on: 2012-01-20 19:30:59 »

So each time a call a tick function is to update my game logic?
And so I use the Tick function to create my game logic right?
Games published by our own members! Go get 'em!
Offline StonePickaxes

Full Member
**

Posts: 204
Medals: 3


Nathan Kramber


« Reply #3 on: 2012-01-20 21:49:43 »

I would look at this; it'll probably help.

In my own words:

There a few different ways you can have your game cycle through it's updates. You can have a generic while loop that updates the game logic and renders on the same cycle, like so -

1  
2  
3  
4  
5  
while (running)
{
   updateGameLogic();
   render();
}


This is a horrible way to do it. When you do it like this, it is only rendering when it is ticking, which will make the game feel like crap on a slower computer.

Here is a good way to do it: seperate the rendering and ticking out into different methods, and only let it tick after a certain amount of time.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
while (running)
      {  
         long lastTime = System.nanoTime();
         
         while (playing)
         {
            long now = System.nanoTime();
            unprocessed += (now - lastTime) / nsPerTick;
            lastTime = now;
            boolean shouldRender = true;
         
            while (unprocessed >= 1)
            {
               tick();
               unprocessed -= 1;
               shouldRender = true;
            }
           
            Thread.yield();
         
            if (shouldRender)
            {
               frames++;
                   render();
            }
         
            if (System.currentTimeMillis() - lastTimer1 > 1000)
            {
               lastTimer1 += 1000;
               frames = 0;
               ticks = 0;
            }
         }
      }


THAT ^^ is how you should do it. It won't fix stuttering on machines that can't render as fast (the fps won't be as fast) but it will tick as often, since updating the game logic requires few resources.

Hope this helps.

-Nathan

Check out my website!
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.062 seconds with 20 queries.