public AeEntity() { Engine = AeEngine.Singleton(); Transform = new AeTransform(); CollisionHull = new AeAABB(); Components = new List <AeComponent>(); Entities = new List <IAeEntity>(); _privateComponents = new List <AeComponent>() { Transform, CollisionHull }; }
public override void Update(GameTime gameTime) { base.Update(gameTime); BoundingBox.X = (int)Transform.X; BoundingBox.Y = (int)Transform.Y; int verticalOffset = (BoundingBox.Height - _buttonTextControl.TextHeight) / 2; int horizontalOffset = (BoundingBox.Width - _buttonTextControl.TextWidth) / 2; _buttonTextControl.Transform.X = Transform.X + horizontalOffset; _buttonTextControl.Transform.Y = Transform.Y + verticalOffset; var mouse = Engine.Input.Mouse; if (BoundingBox.Contains(mouse.X, mouse.Y) && mouse.LeftClick && _onClick != null) { _onClick(); } else { if (BoundingBox.Contains(mouse.X, mouse.Y)) { IsMouseHovering = true; } else { IsMouseHovering = false; } } var touch = Engine.Input.Touch; var bounds = new AeAABB(); bounds.SetPosition((int)Transform.X, (int)Transform.Y); bounds.SetSize(BoundingBox.Width, BoundingBox.Height); if (touch.IsTouched(bounds)) { _onClick(); } }
public bool IsTouched(AeAABB boundingBox) { //todo position adjustment relative to game/screen resolution int gameResolutionWidth = AeEngine.Singleton().Graphics.GraphicsSettings.GameResolutionWidth; int gameResolutionHeight = AeEngine.Singleton().Graphics.GraphicsSettings.GameResolutionHeight; int screenResolutionWidth = AeEngine.Singleton().Graphics.GraphicsSettings.ScreenResolutionWidth; int screenResolutionHeight = AeEngine.Singleton().Graphics.GraphicsSettings.ScreenResolutionHeight; foreach (var touch in _touchCollection) { float touchModifierX = gameResolutionWidth / (float)screenResolutionWidth; float touchModifierY = gameResolutionHeight / (float)screenResolutionHeight; var position = touch.Position; position.X *= touchModifierX; position.Y *= touchModifierY; if (boundingBox.Overlaps(new Vector2(position.X, position.Y))) { return(true); } } return(false); }