; 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