GetEntityType ( entity )
Parameters
| entity - entity handle |
Description
|
Returns the collision type of an entity. This is the number assigned with EntityType; entities that were never given one return 0, meaning they take no part in collision checking. Its everyday job is sorting out what you hit: fetch each collider with CollisionEntity, then branch on GetEntityType - coin, enemy, wall - instead of comparing against every entity handle in the game. See also: EntityType, CollisionEntity, EntityCollided, Collisions. |
Example
; GetEntityType Example ; --------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() ; Collision type ids type_player=1 type_crate=2 type_hazard=3 ; NOTE: fixed overhead camera - the arrow keys steer the PLAYER, not the camera camera=CreateCamera() PositionEntity camera,0,13,-13 RotateEntity camera,45,0,0 light=CreateLight() RotateEntity light,60,30,0 floor=CreatePlane() EntityColor floor,70,110,70 ; The player ball is the collision SOURCE, so it needs an ellipsoid radius player=CreateSphere() PositionEntity player,0,1,0 EntityRadius player,1 EntityType player,type_player ; A harmless crate... crate=CreateCube() ScaleEntity crate,1.2,1.2,1.2 PositionEntity crate,-4,1.2,4 EntityColor crate,200,160,60 EntityType crate,type_crate ; ...and a spiky hazard with a different collision type hazard=CreateCone(8) ScaleEntity hazard,1.2,1.2,1.2 PositionEntity hazard,4,1.2,4 EntityColor hazard,255,60,220 EntityType hazard,type_hazard ; The ball collides with both types Collisions type_player,type_crate,2,2 Collisions type_player,type_hazard,2,2 While Not KeyDown(1) ; Arrow keys steer the player ball If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 If KeyDown(203) Then MoveEntity player,-0.1,0,0 If KeyDown(205) Then MoveEntity player,0.1,0,0 ; UpdateWorld performs the collision checks and the slide response UpdateWorld ; What did we bump into? GetEntityType reads back the collision type ; that EntityType assigned, so the game can react differently to each EntityColor player,220,60,60 info$="nothing yet - drive into something" If CountCollisions(player)>0 hit=CollisionEntity(player,1) t=GetEntityType(hit) info$=t If t=type_crate Then info$=info$+" (a harmless crate)" If t=type_hazard info$=info$+" (a HAZARD - the ball flashes!)" EntityColor player,255,255,0 EndIf EndIf RenderWorld Text 0,0,"Arrow keys: drive the ball into the crate and the hazard Esc: exit" Text 0,20,"GetEntityType(touched entity) = "+info$ Flip Wend End
Index