Jump to content

Preserve input bindings


max-m
 Share

Recommended Posts

Hi folks,

 

is there a way to preserve input bindings on state changes?

 

As far as I know, Phaser copies the following members from the current to the new state:

game, game.add, game.make, game.camera,game.cache, game.input, game.load, game.math,game.sound, game.scale, this, game.stage,game.time, game.tweens, game.world, game.particles,game.rnd, game.physics

'game.input' is one of them.

 

I've built a small JSFiddle to test the behavior, press Space to update, Enter to start state 2.

It logs it's output to the console.

Link to comment
Share on other sites

It doesn't copy them when you change state, all it does is create a new reference. It's still the same sub-systems underneath.

 

However during a state change Input.reset is called, which clears down any bindings that may exist to in-game objects. It's most likely this action you want to avoid?

Link to comment
Share on other sites

Hi,

 

yes, it seems to be that action.

I just want to preserve some input bindings that are of use in all states (currently for debugging).

 

Monkey patching doesn't seem to be usable here (or here), should I instead create a global (in game) function containing the bind-logic and call it in my states during 'init' or 'create'? :)

 

Here's some CoffeeScript of my "global" binds, should be readable even you're not familiar with CoffeeScript - or you could look at the compiled Source here ^^.

game.input.keyboard.addKey(Phaser.Keyboard.F1).onUp.add ->    # reset game    game.state.start 'BootState', @game.input.keyboard.addKey(Phaser.Keyboard.F2).onUp.add ->    console.log 'Resetting saves'    # some more code, @game.input.onDown.add ->	game.scale.startFullScreen no, @# Fix fullscreengame.scale.enterFullScreen.add ->	game.parentStyles = document.getElementById(game.parent).getAttribute 'style', @# Fix fullscreengame.scale.leaveFullScreen.add ->	document.getElementById(game.parent).setAttribute 'style', game.parentStyles	do game.scale.refresh, @

I had to fix the fullscreen mode by that, because I use the 'game.parent' element as target and got some custom CSS to get Firefox to scale the game I want it (not streched fullscreen :))

Link to comment
Share on other sites

I'm trying to resolve a similar issue, is it normal that Input.reset is called when you lost focus or change tab in the browser?

 

We have been talking about that here http://www.html5gamedevs.com/topic/5611-203-possible-keyboard-input-bug/

I suppose that your solution could work for both problems.

 

Yes it's normal. Without it keys and pointers can get 'stuck' in a down state and things can get very weird.

 

However, see the latest commit just made to the dev branch: https://github.com/photonstorm/phaser/commit/a7f6165e3901985c099861da02cc4b86e7c22958

Link to comment
Share on other sites

Hi Richard,

 

Yes it's normal. Without it keys and pointers can get 'stuck' in a down state and things can get very weird.

 

However, see the latest commit just made to the dev branch: https://github.com/photonstorm/phaser/commit/a7f6165e3901985c099861da02cc4b86e7c22958

 

All calls made to InputManager.reset, such as from a State change, are ignored.

So now the bindings persist between states and when adding an handler one should unbind the previous handler, right? :)

Link to comment
Share on other sites

So now the bindings persist between states and when adding an handler one should unbind the previous handler, right? :)

 

No, not between State. That still does a full Input reset. What doesn't do a full reset, which used to, is window focus loss.

 

However what I added was this:

InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
Link to comment
Share on other sites

Thanks to both of you :)

I guess now I'll try to finish up my main menu / save selection and creation screens (this is a nice little exercise to get closer with Phaser ^^) and try to come up with ideas of handling the world (the Tiled-maps should be fine, just need to take a look at locking the camera so only one “screen” or “frame” is visible at a time).

Btw. I'm writing an TLoZ (NES) clone (my first game after an Pong game in Java I wrote 2 years or so ago), 256px by 240px, original art style :D

I'll ask here in the forums if I'm stuck at something :)

Have a nice day.

Maximilian

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...