Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 Tick() for?  (Read 1074 times)
0 Members and 1 Guest are viewing this topic.
Offline tyeeeee1
« Posted 2013-03-18 16:51:27 »

I've been going through this (https://github.com/matheus23/TinyWorld/blob/master/src/org/matheusdev/screens/Screen.java) game made by mathus23 and have been figuring out what certain things do and how they work as to help me in creating a game. So-far I've figured everything that I've needed to out but there is one thing that I can't and that is the tick() method.

After going through a few of the classes that extend the Screen class and looking at what's happening inside of the tick() method I came to the conclusion that every time the game loop does a loop it is telling all of the classes that use the tick() method to run their tick() methods. After trying this in my own program as to make sure this was what it was really doing it ended up doing nothing. What does the tick() method do?

The game loop on github is (TinyWorld / src / org / matheusdev / GameCanvas.java) and pretty much everything in (TinyWorld / src / org / matheusdev / screens /) uses the tick() method.
Offline KevinWorkman

JGO Wizard


Medals: 75
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #1 - Posted 2013-03-18 16:54:32 »

Without looking at the code, I would guess that the tick() method is called every frame (so 60 times a second, or whatever the fps is). This allows game Objects to update themselves before being rendered.

As for your own program, you're going to have to post some code for us to comment on if you want a more specific answer.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline tyeeeee1
« Reply #2 - Posted 2013-03-18 16:55:45 »

I'm using the exact same Screen.java code as is on github and my game loop is the same as well, here is where I'm trying to test the tick() method.

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  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
package World;

import Functions.KeyboardListener_Old;
import Interface.Screen;
import Player.Player;
import Sprite.Sprite;
import java.awt.Graphics2D;

public class WorldCore extends Screen
{
    private int currentArea;
    private int playerXPosition = 0, playerYPosition = 0;
    private Player player;
    private Sprite sprite;
    private KeyboardListener_Old keyboardListener;
   
    public WorldCore()
    {
       player = new Player();
       sprite = new Sprite();
       keyboardListener = new KeyboardListener_Old();
    }
   
    public void distributeInformation()
    {
        player.setCurrentArea(currentArea);
        sprite.setCurrentArea(currentArea);
    }
   
    //Get methods.
   public int getCurrentArea()
    {
        return currentArea;
    }
   
    //Set methods
   public void setCurrentArea(int x)
    {
        currentArea = x;
    }

    @Override
    public void tick()
    {
        playerXPosition = keyboardListener.getXPosition();
        playerYPosition = keyboardListener.getYPosition();
        System.out.println(playerXPosition+"    "+playerYPosition);
    }

    @Override
    public void render(Graphics2D g)
    {
    }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-03-18 16:58:07 »

The reason I have a #tick() and a #render(...) method is 'speration of game logic and rendering' (<- not really... ).

You're using #tick() completely right. In tick() all the stuff in the game world is recursively updated, using the #tick() method. Then, in the next step, recursively everything is drawn using the #render() method.

What you're missing is the code inside #render(). You have to draw the player at that part.

<edit>
So you'd do something like this:
1  
2  
3  
4  
    @Override
    public void render(Graphics2D g) {
        g.drawRect(playerXPosition-5, playerYPosition-5, 10, 10);
    }

</edit>

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline tyeeeee1
« Reply #4 - Posted 2013-03-18 17:01:28 »

The reason I have a #tick() and a #render(...) method is 'speration of game logic and rendering' (<- not really... ).

You're using #tick() completely right. In tick() all the stuff in the game world is recursively updated, using the #tick() method. Then, in the next step, recursively everything is drawn using the #render() method.

What you're missing is the code inside #render(). You have to draw the player at that part.

The render() method here is just so I can test the tick() method, my actual rendering method is in another class. For some reason, when I run the program, nothing is being printed by the System.out.println(playerXPosition+"     "+playerYPosition); that's what led me to believe that tick() wasn't working.
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2013-03-18 17:02:41 »

The reason I have a #tick() and a #render(...) method is 'speration of game logic and rendering' (<- not really... ).

You're using #tick() completely right. In tick() all the stuff in the game world is recursively updated, using the #tick() method. Then, in the next step, recursively everything is drawn using the #render() method.

What you're missing is the code inside #render(). You have to draw the player at that part.

The render() method here is just so I can test the tick() method, my actual rendering method is in another class. For some reason, when I run the program, nothing is being printed by the System.out.println(playerXPosition+"     "+playerYPosition); that's what led me to believe that tick() wasn't working.

This can't be. Are you sure, you have set the Screen using GameCanvas.setScreen(...) ?

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline tyeeeee1
« Reply #6 - Posted 2013-03-18 17:09:45 »

Just did a ctrl+f search on my classes. It doesn't look like I've used that anywhere; where should it have been?

Edit: I just noticed it being used in your code on github, going through it now.

Edit 2: Managed to get it kinda-sorta working but the screen is having a seizure (Tons of flickering.) The problem is probably with how I wrote the code originally, I'll just keep doing my re-write and see if it gets fixed along the way.

Edit 3: Looked at a few more classes on github, it looks like only one class should be set to screen instead of two classes switching back and forth very rapidly. Looks like the re-write will solve the flickering problem.
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (40 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!