示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="parentGameObject"></param>
        public void addGameObject(IGameObject gameObject, IGameObject parentGameObject)
        {
            Debug.Assert(gameObject != parentGameObject, "a gameObject cannot be the parent of himself.");

            SceneNode targetSceneNode = SceneNode.getSceneNodeByGameObject(this.sceneNodeTree, parentGameObject);
            Debug.Assert(targetSceneNode != null, "no specified parentGameObject found in SceneNode tree");

            //set position relative to the parent.
            if (parentGameObject != null)
            {
                double xPositionRelativeToParent = parentGameObject.getXPosition() + gameObject.getXPosition();
                double yPositionRelativeToParent = parentGameObject.getYPosition() + gameObject.getYPosition();
                gameObject.setPosition(xPositionRelativeToParent, yPositionRelativeToParent);
            }

            //update the geometry position relative to the gameObject position.
            if (gameObject.getBoundingBoxGeometry() != null)
            {
                gameObject.getBoundingBoxGeometry().Transform = new TranslateTransform(gameObject.getXPosition(), gameObject.getYPosition());
            }

            targetSceneNode.addChild(new SceneNode(gameObject));

            this.registerGameObject(gameObject, this.gameObjectListMapByTag);
        }