Every game cycle contains two parts. First is showing animations on screen and second is game state. In animations player moves, shoot, jump, show error messages, show game win or loose messages. In game state it is also calculating the score, time etc in the background.
Animations :- player moves, shoot, jump
Game State :- calculating the score, time
Suppose that we have a image and we need to show the image moving in the screen. Below is the basic code to make guys easily understand that how game works basically.
Base Code :-
Image image, Float imageX, Float imageY;
/** Game loop to update and draw the image **/
startGame() {
while(true) {
updateGame();
drawGame();
}
}
/** Update X and Y axis **/
updateGame() {
imageX++;
imageY++;
}
/** Draw image on updated X and Y axis **/
drawGame() {
Batch.draw(image, imageX, imageY);
}
Here image is the pic/image, imageX is any value in X-axis and imageY is any value in Y-axis. We will call the startGame() method to run the game. In this method a loop is running continuously. First it calls updateGame() method and then drawGame() method.
In updateGame() method we can update our game state. For example update the position of player, calculate the time, calculate the score etc.
In drawGame() method we will show the images, score, time with updated values(which are updated in updateGame method ).
Don't worry about the Batch, we will discuss this in next posts.
So that'ss all the basic of game looping concept.
Animations :- player moves, shoot, jump
Game State :- calculating the score, time
Suppose that we have a image and we need to show the image moving in the screen. Below is the basic code to make guys easily understand that how game works basically.
Base Code :-
Image image, Float imageX, Float imageY;
/** Game loop to update and draw the image **/
startGame() {
while(true) {
updateGame();
drawGame();
}
}
/** Update X and Y axis **/
updateGame() {
imageX++;
imageY++;
}
/** Draw image on updated X and Y axis **/
drawGame() {
Batch.draw(image, imageX, imageY);
}
Here image is the pic/image, imageX is any value in X-axis and imageY is any value in Y-axis. We will call the startGame() method to run the game. In this method a loop is running continuously. First it calls updateGame() method and then drawGame() method.
In updateGame() method we can update our game state. For example update the position of player, calculate the time, calculate the score etc.
In drawGame() method we will show the images, score, time with updated values(which are updated in updateGame method ).
Don't worry about the Batch, we will discuss this in next posts.
So that'ss all the basic of game looping concept.
No comments:
Post a Comment