示例#1
0
 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;
 }
示例#2
0
文件: View.cs 项目: fordream/Sunfish
 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");
 }
示例#3
0
文件: Home.cs 项目: fordream/Sunfish
        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");
            }
        }
示例#4
0
 private void HandleGameCenterButtonTap(View gameCenterButton)
 {
     GameCenter.ShowLeaderBoardAndAchievements ();
 }
示例#5
0
        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);
        }
示例#6
0
文件: View.cs 项目: fordream/Sunfish
 /// <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;
 }
示例#7
0
 public static void ScreenTopLeft(View viewToPosition, int leftMargin = 0, int topMargin = 0)
 {
     viewToPosition.Position = new Vector2 ((float) leftMargin, (float) topMargin);
 }
示例#8
0
 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);
 }
示例#9
0
 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);
 }
示例#10
0
 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);
 }
示例#11
0
 public void AddChild(View view)
 {
     AddChild (view, 0, 0);
 }
示例#12
0
 private Vector2 GetChildStackPosition(View child, int marginX, int marginY)
 {
     return new Vector2 (child.Position.X + marginX, child.Position.Y + marginY + NextChildYOffset);
 }
示例#13
0
 private Vector2 GetChildStackCenterHorizontalPosition(View child, int marginY)
 {
     return new Vector2 (((float)Width - (float)child.Width) / 2f, child.Position.Y + marginY + NextChildYOffset);
 }
示例#14
0
 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);
     }
 }
示例#15
0
 private Vector2 GetChildAbsolutePosition(View child, int marginX, int marginY)
 {
     return new Vector2 (child.Position.X + marginX, child.Position.Y + marginY);
 }
示例#16
0
 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;
         }
     }
 }
示例#17
0
 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);
 }
示例#18
0
 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);
 }
示例#19
0
 public void AddChild(View view, int marginX, int marginY)
 {
     AddChild (view, Layout, marginX, marginY);
 }
示例#20
0
 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);
 }
示例#21
0
 public void Add(View view)
 {
     Layers [(int)view.Layer].Add (view);
     Count++;
 }
示例#22
0
 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);
 }
示例#23
0
 public void RemoveView(View viewToRemove)
 {
     List<View> viewLayer = Layers [(int)viewToRemove.Layer];
     viewLayer.Remove (viewToRemove);
 }
示例#24
0
 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);
 }
示例#25
0
文件: Home.cs 项目: fordream/Sunfish
 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));
 }
示例#26
0
 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);
 }
示例#27
0
 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);
 }
示例#28
0
文件: Home.cs 项目: fordream/Sunfish
 private void HandlePauseTap(View pauseButton)
 {
     TestPopup.Show ();
 }
示例#29
0
 private void HandleTap(View thisSwitch)
 {
     Toggle (true);
     if (SwitchOnTapDelegate != null) {
         SwitchOnTapDelegate (this);
     }
 }