Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,051 members, 7,814,607 topics. Date: Wednesday, 01 May 2024 at 04:03 PM

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

Nairaland Forum / Science/Technology / Webmasters / Switching Between Multiple Screens In A Processing Game (748 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): 2:00am On Aug 18, 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)

I Want To Buy A Pin Verified Nigerian Adsense Plus Domain / Flutterwave: Africa’s Largest Online Payment Gateway / Get In If You Can Get This Solved For A Fee

(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. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.