Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (430)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
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  
  what is a Tick????  (Read 1140 times)
0 Members and 1 Guest are viewing this topic.
Offline WolfAlvein

Senior Newbie





« Posted 2012-01-21 01: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

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #1 - Posted 2012-01-21 01: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

Senior Newbie





« Reply #2 - Posted 2012-01-21 01: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #3 - Posted 2012-01-21 03: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (217 views)
2014-04-04 12:06:45
Escape Analysis
by Roquen
2014-04-25 11:37:01

Escape Analysis
by Roquen
2014-04-25 10:38:58

Escape Analysis
by Roquen
2014-04-25 10:22:13

List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37
java-gaming.org 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‑gaming.org
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!