Jump to content

Geometrical Sprites with Physics


srikarg
 Share

Recommended Posts

Hello everyone,

 

Based on this comment, I realized that Phaser removed support for GeomSprites. However, I'm thinking about making a game in which I just need simple shapes rather than image/spritesheet assets. I thought about using the Graphics object, but realized that I cannot apply physics to the shapes I create using that (as far as I know). Then, I found information about game.debug.render to create circles and rectangles, but ran into the same problem.

 

My question: Is there a way to create a sprite that is just a simple circle, rectangle, or any other basic shape AND has physics properties (like being able to collide with other sprites, drag, etc.). I confirmed this lack of physics properties by checking out the classes for the Rectangle and Circle.

 

Thanks in advance for any help!

Link to comment
Share on other sites

Before 1.1.4 the physics system was just an aabb system, making it impossible to work with circles or rotated rectangles.

 

In 1.1.4 Richard integrated a brand-new SAT system which enables us to work with physics bodies that are circles, rectangles, or any kind of polygon, and also offers the ability to rotate the bodies. (This is awesome, he's been working on it for weeks now :)

 

It's not released yet, but it's very close, have a look at the examples in the dev branch,so you know what's available and you'll perhaps find a workaround using a coloured square and a mask.

Link to comment
Share on other sites

I just gave a read at the new PhysicsArcade.js Richard coded in the 1.1.4

Huge work !

 

So, as far as I understand, you'll soon be able to still create a sprite, then attach it a body. Indenpently the sprite image shape, this body can be a rectangle, a circle or a (convex) polygon.

Because Phaser now (as 1.1.4) uses the SAT.js lib, body physics and collisions will be computed on these new shape possibilties.

 

So you'll easily rotate rectangular, polygonal or circular sprites and collide them.

This is really a big jump ahead in the framework capabilities : colliding only two rectangular rotating sprites was some lack until now... I'll review my french article soon  :)

 

SAT theorem can't compute collisions on non convex polygons. Non convex polygons are to be divided in many convex polygons or another algorithm is to be used (infinite point, etc). Those both methods require extra CPU cost and time.

 

But I guess there is already so much to do with polygon/circle collisions, we will enjoy this new framework capability !

 

I think if we choose some polygon body the SAT will be selected and if we choose some rectangle body, the good old AABB wil be selected so as some games don't require rotations. Some kind of optimization ... Not read about it, but I guess it is the way to do. Waiting for the new API docs and examples.

Link to comment
Share on other sites

What am I doing wrong? Because it seems that i cant get the collision detection working...

collision-fail-details.jpg

 

1. when the player first hits the obstacle polygon - collision detection works ok

2. when player wiggles about a bit - collision detection somehow fails and lets player aabb collision box straight thru

 

ps. tried with different polygons and geometries - same result, except with circle when player object jumped all over the place and registered false collisions.

 

Any thoughts?

Link to comment
Share on other sites

  • 4 weeks later...

Can anyone please link to any documentation on creating basic shapes in Phaser 1.15? I tried searching, but all I've come up with is the SAT.js library that's bundled with the new version of Phaser. Is this the library I use for the shapes? Or is there a wrapper for simple geometric shapes in Phaser?

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...
On 2/6/2014 at 7:03 PM, rich said:

It doesn't have to be attached to a Sprite, no. You could create a SAT.Polygon and check for collision with SAT.Response(yourPoly, yourSprite.body.polygon)

Hi, I think I'm trying to do something similar.  Create a pinball-style paddle which can change colors during the game.  I appreciate any help. I'm a total newbie.  I'll look for examples using SAT. Thank you.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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