1

Ive built an app with craftyjs where my playerobject has gravity and the twoway keyboard event making it jump, by clicking UP/W key.

The problem taking it to phonegap and mobile devices is no keyboard :) And how can i trigger that twoway event on screentapping in phonegap?

Jason94
  • 13,320
  • 37
  • 106
  • 184

1 Answers1

2

There has been a recent forum post that resolves your question, so check that out for the complete solution.

In essence you listen to the touch event (that phonegap dispatches) and then you trigger an artificial key event that Twoway will respond to. You can trigger the artificial key event globally:

Crafty.trigger("KeyDown", {key: Crafty.keys.UP_ARROW});

or if you have the reference to the player entity:

playerEntity.trigger("KeyDown", {key: Crafty.keys.UP_ARROW});

I do not know how phonegap dispatches touch events though (the solution in the forum post uses Hammer.js for listening to touch events).

mucaho
  • 2,119
  • 20
  • 35
  • 2
    ah I just realized from your other question that you are the forum poster :) If you have time, answer your own questions on stackoverflow (since you have the answer now), so other people who have the same question can see the solution too. – mucaho Mar 10 '14 at 19:34