Jump to content

Collision and Gyro Questions


diegopardo
 Share

Recommended Posts

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

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

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

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

 Share

  • Recently Browsing   0 members

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