/// <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); }
public BoundingBoxViewerGameObject(IGameObject gameObject) { Debug.Assert(gameObject.getBoundingBoxGeometry() != null, "expected gameObject.getBoundingBoxGeometry() != null"); base._xPosition = gameObject.getBoundingBoxGeometry().Bounds.X - gameObject.getXPosition(); base._yPosition = gameObject.getBoundingBoxGeometry().Bounds.Y - gameObject.getYPosition(); base._gameObjectTag = Tags.DEBUG_TAG; Brush boundingBoxBrush = gameObject.isCollidable() ? Brushes.Red : Brushes.Yellow; GeometryDrawing geometryDrawing = new GeometryDrawing(null, new Pen(boundingBoxBrush, 1.0), gameObject.getBoundingBoxGeometry()); DrawingImage boundingBoxDrawingImage = new DrawingImage(geometryDrawing); Image boundingBoxImage = new Image(); boundingBoxImage.Source = boundingBoxDrawingImage; base._image = boundingBoxImage; this.gameObject = gameObject; this.previousCollidableState = gameObject.isCollidable(); }