brynzky Posted July 11, 2017 Share Posted July 11, 2017 Hi, i want to create a combo attack just like in tekken game, basically changing frames when the player press the next key within a specific span of time, i tried the following but still not manage it work. Any help is appreciated. if (this.melee.isDown) { meleeFrameStart = 16;5 meleeFrameEnd = 23; if (this.melee.upDuration(1000)) { if (gokussgod.frame < meleeFrameEnd) { gokussgod.frame = gokussgod.frame++; } else { gokussgod.frame = meleeFrameStart; } } else { gokussgod.frame = meleeFrameStart; } } Link to comment Share on other sites More sharing options...
mattstyles Posted July 12, 2017 Share Posted July 12, 2017 There was another thread on this. My approach to this (which does not involve Phaser, but I'll only outline the theory anyway) is to wrap the keyboard event handler to emit events with a timestamp, when each new keypress comes in it adds the new one to a list of keypresses and removes any that are older than X ms, this way each keyboard event emits stuff like: [{ key: 'E', timestamp: 100 }] and [{ key: '<right>' timestamp: 100 }, { key: '<down>' timestamp: 110 }, { key: '<left>' timestamp: 120 }, { key: '<space>' timestamp: 130 }] I then query against that array of recent keypresses, in the case above: 'HADOUKEN' (well, almost!). I use streams to handle this, which makes things very very easy, pretty much just this function https://github.com/mattstyles/raid/blob/master/packages/raid-streams/src/keys.js#L67. To consume this stream I use something like the following https://github.com/mattstyles/raid/blob/55f21cfa613010e830555e37208bb14ccd3bf65c/examples/mount-screen/index.js#L48 which just makes a string compare against all the recent keypresses, rudimentary but plenty good enough (and fast) for many many use-cases. Link to comment Share on other sites More sharing options...
Recommended Posts