protected Switch(Texture2D currentTexture, Texture2D onTexture, Texture2D offTexture, bool isOn, Vector2 texturePosition, Constants.ViewLayer layer, View.OnTapDelegate switchOnTapDelegate) : base(currentTexture, texturePosition, layer) { OnTexture = onTexture; OffTexture = offTexture; IsOn = isOn; EnableTapGesture (HandleTap); SwitchOnTapDelegate = switchOnTapDelegate; }
public View(Vector2 position, int width, int height, Constants.ViewLayer layer, bool visible) { Position = position; Width = width; Height = height; Layer = layer; Visible = visible; ParentView = null; OverlayColor = Color.White; Effects = new List<Effects.Effect> (); RotationRadians = 0f; //CenterOrigin (); Scale = 1.0f; CollisionEnabled = false; IsCollisionResponder = false; Velocity = Vector2.Zero; Acceleration = Vector2.Zero; //PositionTexture = SunfishGame.ActiveScreen.LoadTexture ("Position"); //DrawingPositionTexture = SunfishGame.ActiveScreen.LoadTexture ("DrawingPosition"); }
private void CreateRandomExplosion(View viewThatWasTapped) { int explosionNumber = Randomization.NextInt (1, 4); Rectangle frameRectangle = Rectangle.Empty; SpriteFraming framing = null; switch (explosionNumber) { case 1: frameRectangle = new Rectangle (0, 0, 134, 134); framing = new SpriteFraming (frameRectangle, 12, 25d); break; case 2: frameRectangle = new Rectangle (0, 0, 128, 128); framing = new SpriteFraming (frameRectangle, 10, 25d); break; case 3: frameRectangle = new Rectangle (0, 0, 120, 120); framing = new SpriteFraming (frameRectangle, 10, 25d); break; } framing.Loops = 1; framing.LoopingFinishedBehavior = Constants.SpriteFramingLoopingFinishedBehavior.HideSprite; Texture2D explosionTexture = LoadTexture ("Explosion" + explosionNumber.ToString()); Sprite explosion = new Sprite (explosionTexture, framing); explosion.Position = GetRandomExplosionPosition (); AddChildView (explosion); if (Randomization.NextBool ()) { PlaySoundEffect ("Explosion1"); } else { PlaySoundEffect ("Explosion2"); } }
private void HandleGameCenterButtonTap(View gameCenterButton) { GameCenter.ShowLeaderBoardAndAchievements (); }
protected void AddChild(View view, Constants.ViewContainerLayout layout, int marginX, int marginY) { if (layout == Constants.ViewContainerLayout.Absolute) { view.Position = GetChildAbsolutePosition (view, marginX, marginY); } else if (layout == Constants.ViewContainerLayout.FloatLeft) { view.Position = GetChildFloatLeftPosition (view, marginX, marginY); } else if (layout == Constants.ViewContainerLayout.Stack) { view.Position = GetChildStackPosition (view, marginX, marginY); NextChildYOffset = view.Position.Y + view.Height; } else if (layout == Constants.ViewContainerLayout.StackCentered) { view.Position = GetChildStackCenterHorizontalPosition (view, marginY); NextChildYOffset = view.Position.Y + view.Height; } view.SetParent (this); // this will offset the child by this container's position ChildViews.Add (view); SunfishGame.ActiveScreen.AddChildView (view); ExpandHeightIfNecessary (view); }
/// <summary> /// Set the parent view of this view, which will cause this view to use the Visible, Layer, and Position from to the parent. /// </summary> /// <param name="parentView">Parent view.</param> public void SetParent(View parentView) { ParentView = parentView; }
public static void ScreenTopLeft(View viewToPosition, int leftMargin = 0, int topMargin = 0) { viewToPosition.Position = new Vector2 ((float) leftMargin, (float) topMargin); }
public static void ScreenRightCenter(View viewToPosition, int rightMargin = 0) { float x = (float) (SunfishGame.ScreenHeight - viewToPosition.Width - rightMargin); float y = ((float)SunfishGame.ScreenWidth - (float)viewToPosition.Height) * 0.5f; viewToPosition.Position = new Vector2 (x, y); }
public static void ScreenCenter(View viewToPosition) { float x = ((float)SunfishGame.ScreenHeight - (float)viewToPosition.Width) * 0.5f; float y = ((float)SunfishGame.ScreenWidth - (float)viewToPosition.Height) * 0.5f; viewToPosition.Position = new Vector2 (x, y); }
public static void ScreenBottomLeft(View viewToPosition, int leftMargin = 0, int bottomMargin = 0) { float y = (float) (SunfishGame.ScreenWidth - viewToPosition.Height - bottomMargin); viewToPosition.Position = new Vector2 ((float) leftMargin, y); }
public void AddChild(View view) { AddChild (view, 0, 0); }
private Vector2 GetChildStackPosition(View child, int marginX, int marginY) { return new Vector2 (child.Position.X + marginX, child.Position.Y + marginY + NextChildYOffset); }
private Vector2 GetChildStackCenterHorizontalPosition(View child, int marginY) { return new Vector2 (((float)Width - (float)child.Width) / 2f, child.Position.Y + marginY + NextChildYOffset); }
private Vector2 GetChildFloatLeftPosition(View child, int marginX, int marginY) { float sameRowXOffset = NextChildXOffset + marginX + child.Position.X; if (sameRowXOffset + child.Width > Width) { // Need to start a new row NextChildXOffset = marginX + child.Position.X + child.Width; NextChildYOffset = FloatLeftHeight; return new Vector2 (marginX + child.Position.X, FloatLeftHeight + child.Position.Y + marginY); } else { // The child fits in the current row FloatLeftHeight = Math.Max (FloatLeftHeight, child.Position.Y + marginY + NextChildYOffset + child.Height); NextChildXOffset = sameRowXOffset + child.Width; return new Vector2 (sameRowXOffset, child.Position.Y + marginY + NextChildYOffset); } }
private Vector2 GetChildAbsolutePosition(View child, int marginX, int marginY) { return new Vector2 (child.Position.X + marginX, child.Position.Y + marginY); }
private void ExpandHeightIfNecessary(View childView) { if (ShouldExpandHeight) { int yOffset = (int)Position.Y + Height; int childViewYOffset = (int)childView.Position.Y + childView.Height; if (childViewYOffset > yOffset) { Height = (int)childView.Position.Y + childView.Height - (int)childView.Origin.Y - (int)Position.Y; } } }
private Vector2 GetPinchScaledPosition(View view, GestureSample pinch, float pinchScaleFactor) { Vector2 oldPosition1 = pinch.Position - pinch.Delta; Vector2 oldPosition2 = pinch.Position2 - pinch.Delta2; var newPos1 = pinch.Position - (oldPosition1 - view.Position) * pinchScaleFactor; var newPos2 = pinch.Position2 - (oldPosition2 - view.Position) * pinchScaleFactor; return Vector2.Multiply( Vector2.Add(newPos1, newPos2), 0.5f); }
public static void ScreenBottomCenter(View viewToPosition, int bottomMargin = 0) { float x = ((float)SunfishGame.ScreenHeight - (float)viewToPosition.Width) * 0.5f; float y = (float) (SunfishGame.ScreenWidth - viewToPosition.Height - bottomMargin); viewToPosition.Position = new Vector2 (x, y); }
public void AddChild(View view, int marginX, int marginY) { AddChild (view, Layout, marginX, marginY); }
public static void ScreenBottomRight(View viewToPosition, int rightMargin = 0, int bottomMargin = 0) { float x = (float) (SunfishGame.ScreenHeight - viewToPosition.Width - rightMargin); float y = (float) (SunfishGame.ScreenWidth - viewToPosition.Height - bottomMargin); viewToPosition.Position = new Vector2 (x, y); }
public void Add(View view) { Layers [(int)view.Layer].Add (view); Count++; }
public static void ScreenLeftCenter(View viewToPosition, int leftMargin = 0) { float y = ((float)SunfishGame.ScreenWidth - (float)viewToPosition.Height) * 0.5f; viewToPosition.Position = new Vector2 ((float) leftMargin, y); }
public void RemoveView(View viewToRemove) { List<View> viewLayer = Layers [(int)viewToRemove.Layer]; viewLayer.Remove (viewToRemove); }
public static void ScreenTopCenter(View viewToPosition, int topMargin = 0) { float x = ((float)SunfishGame.ScreenHeight - (float)viewToPosition.Width) * 0.5f; viewToPosition.Position = new Vector2 (x, (float) topMargin); }
public void HandleChildTap(View viewThatWasTapped) { viewThatWasTapped.StartEffect(new Sunfish.Views.Effects.Pulsate(800d, 50, GetRandomColor())); viewThatWasTapped.StartEffect (new Sunfish.Views.Effects.Rotate (0f, (float)Math.PI * 2, 2000d)); }
public static void ScreenTopRight(View viewToPosition, int rightMargin = 0, int topMargin = 0) { float x = (float) (SunfishGame.ScreenHeight - viewToPosition.Width - rightMargin); viewToPosition.Position = new Vector2 (x, (float) topMargin); }
public static Switch CreateOn(Texture2D onTexture, Texture2D offTexture, Constants.ViewLayer layer, View.OnTapDelegate switchOnTapDelegate) { return new Switch (onTexture, onTexture, offTexture, true, new Vector2 (0, 0), layer, switchOnTapDelegate); }
private void HandlePauseTap(View pauseButton) { TestPopup.Show (); }
private void HandleTap(View thisSwitch) { Toggle (true); if (SwitchOnTapDelegate != null) { SwitchOnTapDelegate (this); } }