Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Making pachinko style demo - have some questions (mostly about collision :))


Binary Moon
 Share

Recommended Posts

Hi - I am working on a small demo, mostly to see what I can do with Phaser :)

 

The game is a really super simple pachinko style thing.

 

I have my background and ball image loaded, and the ball falls down the screen.

 

Now I need to setup collision with the pegs. I was originally thinking about using the built in collision but I am not sure if it's capable? I was planning to create a group of pegs and then collide the ball with the pegs. But I don't know if the collide function does circle to circle collision (or how to specify circle to circle?).

 

Also if possible it'd be great to use a collision proxy and not have peg sprites so that I can keep everything in the background image. Is this doable?

 

Another thing that has me confused is the scale. I'm used to working in Flash where I would set a velocity of 1 and then the object moves at 1 pixel per frame - however that doesn't seem to be the case here. I have to set the velocity to a much larger number to get nice smooth movement. Is there an easy way for me to understand how the velocity works (eg converting from pixels to the phaser measurement)?

Link to comment
Share on other sites

Hi Ben,

 

Last question first:

 

Velocity is effectively given in pixels per second. So a velocity of 100 would travel 100 pixels in a second. A velocity of 1 would travel at 1 pixel every second. Due to the way delta timers work it's not balls-on accurate of course, so expect a tolerance of say +- 10px on a velocity of 100. Also this assumes no collision/drag applied. It's pretty accurate, but you're not going to build any hadron collider simulation off of it, that's for sure :)

 

Collision is all done on AABB at the moment, although I will be adding hitmasks that can use any of the geometry primitives.

 

One approach you could take:

 

Use GeomSprites for pegs, but just set their state to visible false so they don't render. Then the built-in collision system will pick-up the AABB collide, which could call your own function that then uses the GeomSprite circle property to do a circle to circle collision (available in the Collision class). You would have to resolve velocity yourself however.

 

This way you can keep the pegs on the background image, but you'd have to place each GeomSprite where you need it.

Link to comment
Share on other sites

Awesome - thanks Rich. Velocity stuff now makes sense.

 

I understand the bounding box stuff but the bits that are specific to Phaser are a bit over my head at the moment, I think I'll need some proper docs before I can understand it fully :)

 

I changed my mind about the static background and am now adding the pegs through code. I figured I could do the collision manually as well since it's circle to circle and the bouncing is easy to calculate. The problem I have now is I don't understand how the velocity stuff should work. I can do simple gamey physics (gravity, bouncing, momentum etc) myself but I don't know how to translate that into a Phaser gameObject that makes use of delta timing?

 

Sorry for all the questions - I'm sure it'll all be clear once you start the docs :)

Link to comment
Share on other sites

If you're going to calculate the physics yourself then don't use any of the built-in stuff, i.e. don't set velocity/acceleration on the objects - literally just position them via their x/y values. You can access the delta timer via Game.time.delta for use in your own calculations.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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