Switch between worlds / White Screen


(I'll tell you what I want, what I really really want) #1

Quick question guys, I want the player to be able to go from the menu (Menu.as which is a world) to the actual game after pressing SPACE, or whatever, and

		if (Input.check(Key.SPACE));
		{
			FP.world = new GameWorld();
		}

doesn’t really work. Don’t kill me if it’s an obvious problem.


(Ultima2876) #2

That looks fine enough to me. Why doesn’t it work? What does it do?


(I'll tell you what I want, what I really really want) #3

When I debug the bad boy he just opens the white window instead of showing either menu or gameworld. I get this a lot btw. No actual messages with errors, just whiteness in flash player viewer.

EDIT: Maybe the problem lies in the placement:

I put right about here in my Main.as

	public function Main()
	{
		super(640, 480, 60);
		FP.world = new MenuWorld;
		
		
		if (Input.check(Key.SPACE));
		{
			FP.world = new GameWorld();
		}

(Ultima2876) #4

Yeah, you don’t want that. What that does is as soon as the program starts, it initializes and sets the world to a new MenuWorld. Then it immediately goes on to check if Space is pressed (which it won’t be because this is the initialization function), so it does nothing more.

I’m not sure why you’re just getting a blank screen, however. That usually happens when Java is not installed properly or is having a tantrum for some reason or another, causing your game to not compile properly.

Anyway, the solution would be to move the input check block into your MenuWorld’s update() function. You want to check for the space key each frame in your MenuWorld, then when it is pressed, advance onto the next world.


(I'll tell you what I want, what I really really want) #5

Now, when I place it in:

	override public function update():void 
	{
		if (Input.check(Key.SPACE));
		{
			FP.world = new GameWorld();
		}
		super.update();
		
	}

of my Menu.as there’s just a 0.1 sec flash of my Menu and then it’s the GameWorld already.


(I'll tell you what I want, what I really really want) #6

Right, there’s definitely something weird going one with my FlashDevelop. Now this popped out

And when I try to something as simple as adding the text to the Menu.as white screen attacks again.

	public function MenuWorld() 
	{
		super();
		add(new Text("Press Space to play"));
	}


(Ultima2876) #7

If statements shouldn’t have a ; after them. ; means ‘end of statement’ - since you have brackets { } with your if you don’t want that - the following line effectively says ‘if space bar is pressed… end if and do nothing’:

if (Input.check(Key.SPACE)); //don't want this, this does nothing
{
  //this code will get executed every time, it's effectively outside of the if statement
}

if (Input.check(Key.SPACE)) //that's better
{
  //this obeys the if as expected :D
}

So the code you have with the ; after the if effectively ignores the if and changes world every time.

As for the blank screen, that definitely sounds like a Java problem. Uninstall FlashDevelop, Install the 32-bit Java Runtime from http://www.java.com/en/download/manual.jsp, then reinstall FlashDevelop. And yeah, you definitely want the 32-bit version of Java; FlashDevelop doesn’t work correctly with the 64-bit version, so save some headaches and get the 32-bit version even if you have a 64-bit OS! :slight_smile:


(I'll tell you what I want, what I really really want) #8

WHOOOAAA! It works! Thank you, @Ultima2876, you are truly a wizard of flashpunk.


(I'll tell you what I want, what I really really want) #9

Unfortunately, not solved :frowning:

I try to add something as simple as

		Tekst = new Text("Press Enter to play");

where Tekst is just a variable name, and the white screen pops up again. I feel helpless. And I did install the Java.


(Jonathan Stoler) #10

Are you forgetting a super.update() or super.render() in a overridden update() or render() function?


(Linck) #11

and about the text, I don’t know if you’re already doing this, but you need to add the text to your world. Would be something like this.

public class MenuWorld extends World{

	private var tekst:Text;

	public function MenuWorld() {
		tekst = new Text("Press Enter to play");
		this.add(tekst); //this needs to be called or the text won't appear	
	
	}

}

(Jonathan Stoler) #12

Just want to chime in and say that since Text inherits from Graphic, you’ll want to use addGraphic() rather than regular add() (which is for Entities)


(Jacob Albano) #13

I’ll chime in too: Another cause for a white screen could be an infinite loop before the game is finished initializing. Make sure you aren’t calling a function from itself infinitely, or allowing a loop to run without stopping.

“Waiting for Flashdevelop to connect to the debugger” isn’t an error; in fact, if you don’t see that it’s a sign that something isn’t set up right. It should happen every time.