Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by jessefreeman

So I am setting up a few screens for my game. I basically extend ig.Game class for each screen (start, game, gameover) and when I need to I call ig.system.setGame to switch between them. This works great except when I added in a "Press spacebar to continue" option. Right now when I go from my start screen to my game it works but for some reason my "continue" state never gets set to false after I set the new game. So when a game runs if I test for
if(ig.input.state('continue'))

it's always true. Here is an example of my binding and logic for detecting a continue:
init: function() {
        ig.input.bind( ig.KEY.SPACE, 'continue');
    },
    update: function() {
        if(ig.input.state('continue')){
            ig.system.setGame(MyGame);
        }
        this.parent();
    },

I tried calling clearedPressed and even doing unbinding in the Input class but nothing is resetting it. The only way I was able to fix this was by manually clearing the Input actions property like this
update: function() {
        if(ig.input.state('start')){
            ig.input.actions = {};
            ig.system.setGame(MyGame);
        }
        this.parent();
    },

before I switch to a new screen. I find this kind of hacky and wanted to make sure I wasn't missing something? If I don't do this, when the player dies and goes to the game over screen it immediately jumps to the start screen then to the main game since "continue" is always true.

This isn't the end of the world but it appeared to be a bug to me. I expected clearPressed to work but it didn't. Maybe I need to put in some kind of delay before setting the next game? I have noticed a lot of accidental endless looping if I wasn't careful on exactly when I executed something in my code. I also tested this with other buttons like x or c and ran into the same issue.

Any help on this would be appreciated.

1 decade ago by gxxaxx

Sorry, can't help on the clearing input issues.

ig.input.clearPressed(); has worked great for me.

Either I'm just lucky, haven't run into the issue yet, or, it's because I use the loadLevel methodology.

I was wondering what the advantage of loading different games is -- as opposed to staying within the context of one game -- but loading different levels.

1 decade ago by dominic

Input is completely separate from the currently running Game instance, so you shouldn't need to either of those tricks.

I think the issue may be that you're using ig.input.state('continue'), which will return true for as long as you hold down that button - so even after the new Game is started. I.e. you can't press and release the button as fast as Impact is switching to the new game class :)

Try using ig.input.pressed('continue') instead.

1 decade ago by KPDwyer

Hey, just a quick note:

I had this today. it turns out my inputs weren't getting cleared properly because of another entity (totally unrelated) trying to access a non-existent var. (silly me, didn't check the console in chrome).

what happened was ig.input.pressed(mouseLeft) was always true on my screen with this entity in it. when I noticed the other entity (the one with the actual error) was missing, and I fixed it & this problem fixed itself.
Page 1 of 1
« first « previous next › last »