Blitz3D+ Command Reference

GetChild ( entity,index )

Parameters

entity - entity handle

index - index of the child entity, in the range 1 to CountChildren( entity ) inclusive

Description

Returns a child of an entity by index.

Together with CountChildren this lets you loop over everything attached to an entity - the parts of a loaded model, or all the entities you have parented to a pivot:

For i=1 To CountChildren(entity) : child=GetChild(entity,i) : ... : Next

Only direct children are returned; to reach deeper levels, call GetChild on the children in turn (or use FindChild to search the whole hierarchy by name).

See also: CountChildren, FindChild, GetParent, EntityName.

Example

; GetChild Example
; ----------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,4,-10
RotateEntity camera,18,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A sun with four orbiting child planets
sun=CreateSphere(16)
EntityColor sun,255,220,0

For i=1 To 4
    planet=CreateSphere(8,sun)
    ScaleEntity planet,0.3,0.3,0.3
    PositionEntity planet,Cos(i*90)*(i*1.1+1),0,Sin(i*90)*(i*1.1+1)
Next

index=1

While Not KeyDown(1)

    ; Space selects the next child index
    If KeyHit(57)
        index=index+1
        If index>CountChildren(sun) Then index=1
    EndIf

    ; Turning the sun swings its children around it
    TurnEntity sun,0,1,0

    ; Colour every planet blue, then use GetChild to turn the selected one green
    For i=1 To CountChildren(sun)
        EntityColor GetChild(sun,i),100,100,255
    Next
    EntityColor GetChild(sun,index),0,255,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Space: select next child   Arrow keys: move camera   Esc: exit"
    Text 0,20,"GetChild(sun,"+index+") is the green planet"

    Flip

Wend

End

Index