简体   繁体   中英

How to set the physics size of a circle Phaser Arcade mode

Using Phaser I created a game in "Arcade Mode". The game has a snowball, and I need to set the physics size to a sprite that is not like a square (ie a circle). How do I do that?

setSize doesn't have radius property:

setSize(width, height, offsetX, offsetY)

Phaser's Arcade physics system is based upon bounding rectangles. If you want to use the Arcade physics system for your game, then you'll need to represent your snowball as a rectangular object in the system (which doesn't need to be the same size as the sprite; it could be a smaller size within).

If you want to use a circular size then you'll have to look at one of the other physics systems that Phaser supports. In your case P2 is probably what you're looking for.

See the official Phaser example 'Collide Custom Bounds' for an example of using a circle to define bounds in P2.

It effectively involves adding P2 physics to the object, or group the object is in, and then using something like snowball.body.setCircle(16);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM