How to reload the game on Phaser 3? - phaser-framework

How to restart the game when you click on the button?
I tried the following code:
this.scene.stop();
this.scene.start();
The scene reloads, but the preload function does not work again.

Try this code:
this.registry.destroy(); // destroy registry
this.events.off(); // disable all active events
this.scene.restart(); // restart current scene
Also have a look at the Phaser 3 Documentation for more info

Related

FlxButtonPlus not responding to anything inside of game's pause menu

I am using the haxeflixel game framework to create a game and I was making a pause menu. I tried using the default FlxButton but the collision with the mouse never lined up properly. So I tried using FlxButtonPlus because it had some cool hooks but the button will not respond to any inputs. here is my code declaring the button in the pause menu
final unpausebut = new FlxButtonPlus((FlxG.width / 2) - 80,(FlxG.height / 2) - 10,unpause,"unpause",48,16); unpausebut.loadButtonGraphic(buttonNormal,buttonHovered); add(unpausebut);
Here is a picture of the pause menu itself so far.
but the button doesn't seem to respond to anything. I am also getting no errors inside of the terminal. unpause is a function inside of the code that also closes the substate. Can anybody help?

Phaser3 Scenes transitions

I'm new to Phaser3 and before starting a crazy project, I want to know how I should start, switch between scenes. I saw that there are several functions, start, launch, switch, run, resume, pause, etc.
Example, lets say I want to have 2 scenes, a Menu and a Game. I boot on the Menu and I want to go to the Game scene and if I click on a button then come back to the Menu scene.
I've achieved this by calling the start function, but I noticed that the all, init, preload and create functions are called every time and therefore I'm loading all the images, setting all the listener over and over again.
This seems wrong, should I be using the launch or switch functions and pausing and resuming? But how do I hide the previous scene?
Thanks in advance.
This question might be a little too broad, but with Phaser 3 in mind, it still depends upon what purpose your menu serves.
I think most games have a main menu that will generally be called when the game first starts, and then won't be called again.
If this is an in-game menu, where settings can be changed or part of the game can be reset/restarted, then it might not make sense to redirect to a completely different scene.
With Phaser 3's support of multiple scenes - with Dev Log #119 and Dev Log #121 probably being the best current sources of information - another option would be to start a new scene within the current scene to handle this.
However, if this is really just UI, there's nothing to stop you from creating an overlay, instead of spawning an entire scene.
If you're concerned about performance I might think about whether the entire menu needs to be called, or if a simplified menu would work. Also, make sure that you're preloading assets before you're in the menu and main game.
I personally use Boot > Preloader > Splash Screen > Main Menu > Main Game scenes, where the Preloader loads the majority of the assets I'll need. This has the downside of a longer initial load, but the upside of minimal loading after this point.
Scene Transitions
How I handle these in my starter templates is to add the scenes to the Scene Manager when creating the scene. Then I transition by start to the first scene.
this.scene.add(Boot.Name, Boot);
this.scene.add(Preloader.Name, Preloader);
this.scene.add(SplashScreen.Name, SplashScreen);
this.scene.add(MainMenu.Name, MainMenu);
this.scene.start(Boot.Name);
Then I simply keep starting the next scenes as needed.
this.scene.start(Preloader.Name);
For another game that uses multiple scenes I ended up creating the following function (TypeScript) to handle this:
private sleepPreviousParallelScene(sceneToStart: string): Phaser.Scene {
if (this.uiSceneRunning !== sceneToStart) {
// Make sure that we properly handle the initial state, when no scene is set as running yet.
if (this.uiSceneRunning !== "") {
this.scene.get(this.uiSceneRunning).scene.sleep();
}
const newScene = this.scene.get(sceneToStart);
newScene.scene.start();
this.scene.bringToTop(sceneToStart);
this.uiSceneRunning = sceneToStart;
return newScene;
} else {
return this.scene.get(this.uiSceneRunning);
}
}
In the game I was using this for, I was trying to replicate a standard tab interface (like what's see in the Dev Logs above with the file folder-like interface).
Ok, here is the deal. In phaser 3, the start function actually SHUTS DOWN the previous scene as it starts the new one. This is why you see the init, preload ext every time. If however, you 'launch' your scenes instead, then they will not go through the whole shut down, restart sequence. You can move them to the top or bottom, set to receive input or not, etc. HOWEVER, BEWARE! As of phaser 3.16, sleep or pause of a scene does NOT shut down the update. As a result, if you launch a scene, then sleep it, it basically does nothing other than maybe set the flag, saying it's asleep even though it really isn't. So any update processing will continue in any launched scene. You can short circuit the update with a flag of some sort at the beginning, (that's what I've resorted to), but the other gotcha is the camera size. All the scenes must therefore have the same camera size or they will render (even if "sleeping") and mess up your display.
So, bottom line, it's going to be messy until sleep and pause actually work.

How To Navigate From Parent Window To Popup Window using Node js Night Watch

I am implementing facebook login automation on my site using night watch.I am successfully able to opening facebook login window in popup but can't able to access popup window using night watch
please help me
I've been using the following in my tests. You need to explicitly change focus to the pop up window in your script.
.window_handles(function(result) { // Since two windows are open we need to get the window ids
var temp = result.value[1]; //
this.switchWindow(temp); // and switch focus to the new window so that the next command is run against it
}) //
to switch focus back to the the original window you can use the following
.window_handles(function(result) { // Since two windows are open we need to get the window ids
var temp = result.value[0]; //
this.switchWindow(temp); // and switch focus to the new window so that the next command is run against it
}) //

WKWebview does not run javascript(XML HTTP request) with out adding a parent view

I am updating my project from UIWebView to WKWebView. In existing UIWebView approach where UIWebView does't have any parent until it runs javascript and once it has content, it adds a parent to the webview. Content renders fine using UIWebView. I am using the same approach for WKWebView, however WKWebview stuck at loading. Is there any way we can execute javascript on wkwebview without adding parent to the webview. Another interesting thing is it works on simulator not on device. Using localHTTPServer to serve the html, css and images.
Any Suggestions or Tips to solve the above issue.
I have observed similar behavior in my app running socket.io in a headless WKWebView. In my case, the web socket would disconnect all the time and not reconnect.
It seems that since WKWebView runs javascript off-process that it will pause any javascript that is considered idle to save resources (<-IMO). Idle includes not having a parent or the app/device is inactive. So, yes, it seems like you are correct in that it needs a parent view in most cases. I was able to work around this using the following code:
WKWebViewConfiguration* webViewConfig = // set up config
// provide empty frame rect
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfig];
// add to keyWindow to ensure it is 'active'
[UIApplication.sharedApplication.keyWindow addSubview:webView];
This approach at least ensures the javascript runs while the app is active and doesn't effect the UI. If you need to display it later you can remove the webView from the keyWindow after render and reset the frame. And, yes, I also observed that in the simulator this is not an issue (javascript ALWAYS runs, regardless of parent or app state)
Hope this helps!
The accepted solution worked for me some of the time. I tried something else which appears to work for me consistently:
self.keepWebViewActiveTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:#selector(_keepWKWebViewActive:)
userInfo:nil
repeats:YES];
Where _keepWKWebViewActive is:
-(void) _keepWKWebViewActive:(NSTimer*) timer{
if(self.webView) {
[self.webView evaluateJavaScript:#"1+1" completionHandler:nil];
}
}

MonoTouch: How to update a view [duplicate]

I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.
How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?
You could try something along the lines of:
//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);
//snip
void EnteredForeground (NSNotification notification)
{
// do your stuff here
}
Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!

Resources