|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.object.CollisionManager
com.golden.gamedev.object.collision.BasicCollisionGroup
public abstract class BasicCollisionGroup
Basic collision check, only check whether a collision occured or not.
This class does not gather any information from the collision.
To get more information from the collision, such as collision side,
use CollisionGroup
instead.
This type of collision check is the best to use for hit and destroy collision.
For example: collision between projectile and enemy ships
Playfield playfield; SpriteGroup PROJECTILE, ENEMY; playfield.addCollisionGroup(PROJECTILE, ENEMY, new BasicCollisionGroup() { public void collided(Sprite s1, Sprite s2) { // after enemy collided with projectile, // the enemy explode (set to non-active) s2.setActive(false); } } );
PlayField.addCollisionGroup(SpriteGroup, SpriteGroup, CollisionManager)
Field Summary | |
---|---|
boolean |
pixelPerfectCollision
Indicates whether this collision detection should use pixel-perfect precision or not. |
protected CollisionRect |
rect1
Default collision shape used as every sprites in group 1 bounding box. |
protected CollisionRect |
rect2
Default collision shape used as every sprites in group 2 bounding box. |
Constructor Summary | |
---|---|
BasicCollisionGroup()
Creates new BasicCollisionGroup . |
Method Summary | |
---|---|
void |
checkCollision()
Checks for collision between all members in group 1 againts all members in group 2. |
abstract void |
collided(Sprite s1,
Sprite s2)
Notified when sprite1 from group 1 collided with
sprite2 from group 2. |
CollisionShape |
getCollisionShape1(Sprite s1)
Returns collision shape (bounding box) of specified sprite from group 1. |
CollisionShape |
getCollisionShape2(Sprite s2)
Returns collision shape (bounding box) of specified sprite from group 2. |
boolean |
isCollide(Sprite s1,
Sprite s2,
CollisionShape shape1,
CollisionShape shape2)
Performs collision check between Sprite s1 and
Sprite s2 , and returns true if the sprites
(shape1 , shape2 ) is collided. |
Methods inherited from class com.golden.gamedev.object.CollisionManager |
---|
getGroup1, getGroup2, getIntersectionRect, isActive, isPixelCollide, setActive, setCollisionGroup |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final CollisionRect rect1
protected final CollisionRect rect2
public boolean pixelPerfectCollision
The usual way to turn on this variable is :
class ThisThatCollision extends BasicCollisionGroup { // class initialization { pixelPerfectCollision = true; } }
Constructor Detail |
---|
public BasicCollisionGroup()
BasicCollisionGroup
.
Method Detail |
---|
public CollisionShape getCollisionShape1(Sprite s1)
In this implementation, the sprite bounding box is set
as large as Sprite
dimension:
public CollisionShape getCollisionRect1(Sprite s1) { rect1.setBounds(s1.getX(), s1.getY(), s1.getWidth(), s1.getHeight()); return rect1; }
s1
- the sprite from group 1 to be check its collision
rect1
,
getCollisionShape2(Sprite)
,
CollisionShape.intersects(CollisionShape)
public CollisionShape getCollisionShape2(Sprite s2)
In this implementation, the sprite bounding box is set
as large as Sprite
dimension:
public CollisionShape getCollisionRect2(Sprite s2) { rect2.setBounds(s2.getX(), s2.getY(), s2.getWidth(), s2.getHeight()); return rect2; }
s2
- the sprite from group 2 to be check its collision
rect2
,
getCollisionShape1(Sprite)
,
CollisionRect.intersects(CollisionShape)
public void checkCollision()
CollisionManager
checkCollision
in class CollisionManager
public boolean isCollide(Sprite s1, Sprite s2, CollisionShape shape1, CollisionShape shape2)
s1
and
Sprite s2
, and returns true if the sprites
(shape1
, shape2
) is collided. Note: this method do not check active state of the sprites.
s1
- sprite from group 1s2
- sprite from group 2shape1
- bounding box of sprite 1shape2
- bounding box of sprite 2
public abstract void collided(Sprite s1, Sprite s2)
sprite1
from group 1 collided with
sprite2
from group 2.
s1
- sprite from group 1s2
- sprite from group 2
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |