diegopardo Posted June 23, 2014 Share Posted June 23, 2014 Hello! I am new to Phaser and so far are loving this engine. To learn how to develop with the engine I decided to try to recreate a Doodle Jump style game and have come across two questions: The first one: is it possible to disable certain types of collisions but not others? By this I mean, if you recall Doodle Jump, when the sprite touches the bottom of one of the platforms it doesn't interact with it, but when it lands on top of one, then the sprite jumps, so it continues to go up the map. I cannot figure out how to do this. I know that with Phaser I can detect certain types of collisions by using 'touching.down' and 'touching.up', but what i have tried hasn't worked. My second questions is: I want to use the gyro or accelerometer to make the sprite move. I was wondering if someone could point or show me a very simple example of taking information from these sensors to make a sprite move. Thank you. Link to comment Share on other sites More sharing options...
stasuss Posted June 23, 2014 Share Posted June 23, 2014 for gyro see this link: http://tomg.co/gyrojsbut take note that in mobile browser it is impossible to use it. not because it is not supported, but because screen orientation changes. but in hybrid-app it will work fine. Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 This example has the functionality I believe you need; one-way collision: http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=one+way+collision.js&t=one%20way%20collision Link to comment Share on other sites More sharing options...
diegopardo Posted June 23, 2014 Author Share Posted June 23, 2014 Thank you. I was wondering if you knew (and perhaps could show me), exactly how to implement this in the code using Phaser? Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 The example itself is written in Phaser, but the part of importance is the body.checkCollision object. Basically, this determines which directions will trigger collision, so if you want a platform which acts as you describe, you'd do something like this:// disable the platform's left, right and down collision so only objects approaching// from above will collide with itplatform.body.checkCollision = { none: false, any: true, up: true, down: false, left: false, right: false };function update() { game.physics.arcade.collide(player, platform, function() { // anything here will be run whenever the player lands on top of the platform });} Link to comment Share on other sites More sharing options...
diegopardo Posted June 23, 2014 Author Share Posted June 23, 2014 Oh, my bad, your first example worked great! Thank you! I need help implementing the code to get input from the accelerometer or gyro to move a sprite.Could you help me with that? Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 Not off the top of my head - gyro input is somewhat difficult to use due, as previously mentioned, to orientation changes and, more subtly, to working out relative positioning. Saying that, you should be able to get something going just by including the gyro.js script and then including the gyro.startTracking function in your create state, and using the provided properties in there to move a sprite in whatever way you wish. Try experimenting with it. Link to comment Share on other sites More sharing options...
agmcleod Posted June 24, 2014 Share Posted June 24, 2014 I did some pretty basic gyro operations in my game using MelonJS. I implemented a basic set of values to work with and more or less played with the numbers. I wrote the API based off logic here: http://www.html5rocks.com/en/tutorials/device/orientation/#toc-usingDM We have a device.orientation value that only changes on 90 degrees, but it's basically bound to window.orientation. So you can use that to check if it's landscape or portrait. Link to comment Share on other sites More sharing options...
Recommended Posts