|
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
com.golden.gamedev.object.collision.CollisionGroup
public abstract class CollisionGroup
Basic collision check, with calculation of some collision events, such as collision side, and sprite return position.
Suitable for collision that only need to know the side of the collision, but not need precise sprite return position.
For example collision between projectile and enemy in platform game, the implementation need collision side to determine to which side the enemy should fall.
To get more precise sprite position after collision use
PreciseCollisionGroup
instead.
PlayField.addCollisionGroup(SpriteGroup, SpriteGroup, CollisionManager)
Field Summary | |
---|---|
static int |
BOTTOM_TOP_COLLISION
Indicates the collision side of the collided sprites is the bottom of first sprite againts the top of other sprite. |
protected int |
collisionSide
The collision side of current collision. |
protected double |
collisionX1
The x return coordinate of sprite in group 1 in current collision. |
protected double |
collisionX2
The x return coordinate of sprite in group 2 in current collision. |
protected double |
collisionY1
The y return coordinate of sprite in group 1 in current collision. |
protected double |
collisionY2
The y return coordinate of sprite in group 2 in current collision. |
static int |
LEFT_RIGHT_COLLISION
Indicates the collision side of the collided sprites is the left of first sprite againts the right of other sprite. |
static int |
RIGHT_LEFT_COLLISION
Indicates the collision side of the collided sprites is the right of first sprite againts the left of other sprite. |
protected Sprite |
sprite1
The sprite from group 1 in current collision. |
protected Sprite |
sprite2
The sprite from group 2 in current collision. |
static int |
TOP_BOTTOM_COLLISION
Indicates the collision side of the collided sprites is the top of first sprite againts the bottom of other sprite. |
Fields inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup |
---|
pixelPerfectCollision, rect1, rect2 |
Constructor Summary | |
---|---|
CollisionGroup()
Creates new CollisionGroup . |
Method Summary | |
---|---|
int |
getCollisionSide()
Returns collision side of current collision. |
Sprite |
getSprite1()
Returns the sprite of current collision from group 1. |
Sprite |
getSprite2()
Returns the sprite of current collision 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. |
void |
printCollisionSide()
Prints collision side of current collision to console (for debugging). |
void |
revertPosition1()
Reverts sprite 1 position before the collision occured. |
void |
revertPosition2()
Reverts sprite 2 position before the collision occured. |
Methods inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup |
---|
checkCollision, collided, getCollisionShape1, getCollisionShape2 |
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 |
---|
public static final int LEFT_RIGHT_COLLISION
public static final int RIGHT_LEFT_COLLISION
public static final int TOP_BOTTOM_COLLISION
public static final int BOTTOM_TOP_COLLISION
protected Sprite sprite1
protected Sprite sprite2
protected int collisionSide
protected double collisionX1
x
return coordinate of sprite in group 1 in current collision.
protected double collisionY1
y
return coordinate of sprite in group 1 in current collision.
protected double collisionX2
x
return coordinate of sprite in group 2 in current collision.
protected double collisionY2
y
return coordinate of sprite in group 2 in current collision.
Constructor Detail |
---|
public CollisionGroup()
CollisionGroup
.
Method Detail |
---|
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.
This method is responsible to take care all collision events,
such as the collided sprite
(in this case s1
and s2
),
the collision side,
position where collision actually occured
(collisionX1,
collisionY1).
The collision information is used to return the collided sprite
using revertPosition1()
and revertPosition2()
method.
Therefore if the given information is wrong,
those two methods will behave unpredictable.
Note: this method do not check active state of the sprites.
isCollide
in class BasicCollisionGroup
s1
- sprite from group 1s2
- sprite from group 2shape1
- bounding box of sprite 1shape2
- bounding box of sprite 2
collisionSide
,
sprite1
,
collisionX1
,
collisionY1
,
revertPosition1()
public void revertPosition1()
public void revertPosition2()
public Sprite getSprite1()
public Sprite getSprite2()
public int getCollisionSide()
public void printCollisionSide()
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |