void loadBody(StadiumObject stadiumObject) { StaticBody2D body = new StaticBody2D(); ImageTexture texture = new ImageTexture(); texture.Load(stadiumObject.TexturePath); Sprite sprite = new Sprite(); sprite.Texture = texture; if (stadiumObject.Shape == StadiumObject.Type.RECT) { sprite.Centered = false; } body.AddChild(sprite); float positionX = (float)(stadiumObject.ShapeStruct.Position.X); float positionY = (float)(stadiumObject.ShapeStruct.Position.Y); body.Position = new Godot.Vector2(positionX, positionY); if (stadiumObject.Shape == StadiumObject.Type.RECT) { body = loadRectBody(stadiumObject, body); } else { body = loadCircBody(stadiumObject, body); } AddChild(body); }
StaticBody2D loadRectBody(StadiumObject stadiumObject, StaticBody2D body) { CollisionShape2D collider = new CollisionShape2D(); RectangleShape2D shape = new RectangleShape2D(); RectStruct rectStruct = (RectStruct)stadiumObject.ShapeStruct; shape.Extents = new Godot.Vector2((float)rectStruct.Position.X / 2, (float)rectStruct.Position.Y / 2); collider.Shape = shape; body.AddChild(collider); return(body); }
StaticBody2D loadCircBody(StadiumObject stadiumObject, StaticBody2D body) { CollisionShape2D collider = new CollisionShape2D(); CircleShape2D shape = new CircleShape2D(); CircStruct circStruct = (CircStruct)stadiumObject.ShapeStruct; shape.Radius = (float)circStruct.Size.X / 2; collider.Shape = shape; body.AddChild(collider); ImageTexture texture = new ImageTexture(); texture.Load(stadiumObject.TexturePath); Sprite sprite = new Sprite(); sprite.Texture = texture; body.AddChild(sprite); return(body); }