public Game(Renderer renderer) { cam = new DefaultCamera(inputManager, 55); renderManager = new RenderManager(renderer, cam, new Action(() => { Render(); })); renderManager.SpriteRenderer = new SpriteRenderer(this); physicsWorld = new PhysicsWorld(new PhysicsDebugDraw(cam)); }
public GUIManager(Game game) { this.inputManager = game.InputManager; this.renderManager = game.RenderManager; this.spriteRenderer = game.RenderManager.SpriteRenderer; game.RootNode.AddChild(guiNode); inputManager.AddMouseEvent(new MouseEvent(InputManager.MouseButton.Left, false, () => { for (int i = 0; i < controls.Count; i++) { if (controls[i] is Clickable) { if (Collides(controls[i], inputManager.GetMouseX() + inputManager.SCREEN_WIDTH / 2, inputManager.GetMouseY() + inputManager.SCREEN_HEIGHT / 2)) { controls[i].hasFocus = true; ((Clickable)controls[i]).LeftClicked(); controls[i].clicked = true; } else { controls[i].hasFocus = false; } } } })); inputManager.AddMouseEvent(new MouseEvent(InputManager.MouseButton.Left, true, () => { for (int i = controls.Count - 1; i > -1; i--) { if (i < controls.Count) { if (controls[i].clicked == true) { ((Clickable)controls[i]).LetGo(); controls[i].clicked = false; } } } })); }
public override void Update(RenderManager renderManager) { base.Update(renderManager); if (isVibrating) { if (vibrateTick < maxVibrateTick) { vibrateTick += 0.1f;// GameTime.getDeltaTime()*2f; SetLocalTranslation( new Vector3f(oldX + (float)System.Math.Sin(vibrateTick * 15f) * 5f, GetLocalTranslation().y, 0)); } else { SetLocalTranslation(new Vector3f(oldX, GetLocalTranslation().y, 0)); isVibrating = false; OnDoneVibrating(); } } else if (!isVibrating) { if (this.layout == Layout.Centered) { if (this.GetParent() != null && (GetParent() is AbstractControl)) { float parentCenterX = ((AbstractControl)GetParent()).width / 2f; float parentCenterY = ((AbstractControl)GetParent()).height / 2f; float halfWidth = this.width / 2f; float halfHeight = this.height / 2f; if (GetLocalTranslation().x != (parentCenterX - halfWidth) || GetLocalTranslation().y != (parentCenterY - halfHeight)) { this.SetLocalTranslation( new Vector3f(parentCenterX - halfWidth, parentCenterY - halfHeight, 0)); } } else if (this.GetParent() == null || !(GetParent() is AbstractControl)) { float halfWidth = this.width / 2f; float halfHeight = this.height / 2f; float halfScreenWidth = InputManager.SCREEN_WIDTH / 2f; float halfScreenHeight = InputManager.SCREEN_HEIGHT / 2f; if (GetLocalTranslation().x != (halfScreenWidth - halfWidth) || GetLocalTranslation().y != (halfScreenHeight - halfHeight)) { this.SetLocalTranslation( new Vector3f(halfScreenWidth - halfWidth, halfScreenHeight - halfHeight, 0)); } } } } UpdateControl(); }