Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,158,579 members, 7,837,186 topics. Date: Wednesday, 22 May 2024 at 06:25 PM

Switching Between Multiple Screens In A Processing Game - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Switching Between Multiple Screens In A Processing Game (578 Views)

Switching Between Multiple Screens In A Processing Game / Share Your Experience Switching From HTTP To HTTPS / Is There Any Special Benefit Of Switching To HTTPS? (2) (3) (4)

(1) (Reply)

Switching Between Multiple Screens In A Processing Game by FincoApps(m): 1:59am On Aug 24, 2019
In this tutorial, we would be adding a Menu screen and a game over screen to the bouncing ball game that was created in the last tutorial.   So make sure you download the .pde file from the last post.
Here’s what we will be creating:

Since Processing does not give any standard api for switching between scenes, we would need to improvise.   The best way to conveniently transit from screen to screen is to use a variable to hold information about the current screen running.
For this example, we would create a String variable and call it currentScreen.   So go to the very top of the code and type the following:
String currentScreen = “menu”;
The next step is to edit the draw method and make it check the current position of the screen so it can determine what to draw.  ie If the currentScreen variable value is equal to “menu”, then it draws a text, if it is “gameplay”, it plays the game and if the variable value is “game over”, then it shows the Game Over text.   To do this,  change the content of the draw method to:







background(255, 255, 0);

if (currentScreen == "menu"wink {//Checks if the screen is in the Menu
fill(0);//To change the text color from default White to black
textSize(50);
text("Brick Breaker", 120, 110);
text("Press any key to start", 37, 230);
}

else if (currentScreen == "gameplay"wink {
ellipse(ballX, ballY, 20, 20);
fill(0, 0, 0);
rect(mouseX, 380, 80, 20);

if (ballY >= 400)//If the ball has reached the bottom of the screen
{
dirY = -2;//Change ball di... Read more at https://fincoapps.com/switching-between-multiple-screens/

(1) (Reply)

Magento 2 Marketplace Plugin | Magento 2 Marketplace Blog Plugins / Get Verified Paypal Account Now For Just 2k / How Much Do Website Design Services Cost?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.