Exemple #1
0
        /**
         * Sets a new content offset. It ignores max/min offset. It just sets what's given. (just like UIKit's UIScrollView)
         * You can override the animation duration with this method.
         *
         * @param offset new offset
         * @param animation duration
         */

        public void SetContentOffsetInDuration(CCPoint offset, float dt)
        {
            CCMoveTo    scroll = new CCMoveTo(dt, offset);
            CCCallFuncN expire = new CCCallFuncN(StoppedAnimatedScroll);

            container.RunAction(new CCSequence(scroll, expire));
            Schedule(PerformedAnimatedScroll);
        }
Exemple #2
0
		CCSprite AddBanana ()
		{
			var banana = new CCSprite ("Banana");

			double rnd = new Random ().NextDouble ();
			double randomX = (rnd > 0) 
				? rnd * CCDirector.SharedDirector.WinSize.Width - banana.ContentSize.Width / 2 
				: banana.ContentSize.Width / 2;
	
			banana.Position = new CCPoint ((float)randomX, CCDirector.SharedDirector.WinSize.Height - banana.ContentSize.Height / 2);

			AddChild (banana);

			var moveBanana = new CCMoveTo (5.0f, new CCPoint (banana.Position.X, 0));

			banana.RunActions (moveBanana, moveBananaComplete);

			banana.RepeatForever (rotateBanana);

			return banana;
		}
        public override void OnEnter()
        {
            base.OnEnter();

            var s = VisibleBoundsWorldspace.Size;

            var textField = new CCTextField("[click here for input]",
                "fonts/MarkerFelt",
                22,
                CCLabelFormat.SpriteFont);

            textField.BeginEditing += OnBeginEditing;
            textField.EndEditing += OnEndEditing;
            textField.Position = s.Center;

            textField.AutoEdit = true;

            AddChild(textField);

            TrackNode = textField;
            scrollUp = new CCMoveTo(0.5f, VisibleBoundsWorldspace.Top() - new CCPoint(0, s.Height / 4));
            scrollDown = new CCMoveTo(0.5f, textField.Position);

        }
Exemple #4
0
		/**
		* Sets a new content offset. It ignores max/min offset. It just sets what's given. (just like UIKit's UIScrollView)
		* You can override the animation duration with this method.
		*
		* @param offset new offset
		* @param animation duration
		*/

        public void SetContentOffsetInDuration(CCPoint offset, float dt)
        {
            CCMoveTo scroll = new CCMoveTo (dt, offset);
            CCCallFuncN expire = new CCCallFuncN(StoppedAnimatedScroll);
            container.RunAction(new CCSequence(scroll, expire));
            Schedule(PerformedAnimatedScroll);
        }
Exemple #5
0
        void HandleTouchesMoved(System.Collections.Generic.List<CCTouch> touches, CCEvent touchEvent)
        {
            //Unfortunatelly framework isn't ready to reflect movement correctly in case we reassing Action each tick
            if (ticks%2==0 )return;

            // we only care about the first touch:
            var locationOnScreen = touches [0].Location;

            CCPoint point = new CCPoint ();
            point.X = locationOnScreen.X;
            point.Y = Math.Min (locationOnScreen.Y, playerMarking.BoundingBoxTransformedToParent.MaxY);
            float duration = playerPlatform.TimeToGet (point);
            CCMoveTo action = new CCMoveTo (duration,point);
            playerPlatform.StopAllActions ();
            playerPlatform.AddAction (action);
        }
        void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
        {
            monkey.StopAllActions ();

            var location = touches [0].LocationOnScreen;
            location = WorldToScreenspace (location);  //Layer.WorldToScreenspace(location);
            float ds = CCPoint.Distance (monkey.Position, location);

            var dt = ds / MONKEY_SPEED;

            var moveMonkey = new CCMoveTo (dt, location);

            //BUG: calling walkRepeat separately as it doesn't run when called in RunActions or CCSpawn
            monkey.RunAction (walkRepeat);
            monkey.RunActions (moveMonkey, walkAnimStop);

            // move the clouds relative to the monkey's movement
            MoveClouds (location.Y - monkey.Position.Y);
        }
        CCSprite AddBanana()
        {
            var spriteSheet = new CCSpriteSheet ("animations/monkey.plist");
            var banana = new CCSprite (spriteSheet.Frames.Find ((x) => x.TextureFilename.StartsWith ("Banana")));

            var p = GetRandomPosition (banana.ContentSize);
            banana.Position = p;
            banana.Scale = 0.5f;

            AddChild (banana);

            var moveBanana = new CCMoveTo (5.0f, new CCPoint (banana.Position.X, 0));
            banana.RunActions (moveBanana, moveBananaComplete);
            banana.RepeatForever (rotateBanana);

            return banana;
        }
		void HandleMoveCircle (CCTouch touch)
		{
			const float timeToTake = 1.5f; // in seconds
			CCFiniteTimeAction coreAction = null;

			// By default all actions will be added directly to the
			// root node - it has values for Position, Scale, and Rotation.
			CCNode nodeToAddTo = drawNodeRoot;

			switch (VariableOptions [currentVariableIndex]) {
			case "Position":
				coreAction = new CCMoveTo(timeToTake, touch.Location);
				break;
			case "Scale":
				var distance = CCPoint.Distance (touch.Location, drawNodeRoot.Position);
				var desiredScale = distance / DefaultCircleRadius;
				coreAction = new CCScaleTo (timeToTake, desiredScale);
				break;
			case "Rotation":
				float differenceY = touch.Location.Y - drawNodeRoot.PositionY;
				float differenceX = touch.Location.X - drawNodeRoot.PositionX;

				float angleInDegrees = -1 * CCMathHelper.ToDegrees (
					(float)Math.Atan2 (differenceY, differenceX));

				coreAction = new CCRotateTo (timeToTake, angleInDegrees);

				break;
			case "LineWidth":
				coreAction = new LineWidthAction (timeToTake, touch.Location.X / 40f);
				// The LineWidthAction is a special action designed to work only on
				// LineNode instances, so we have to set the nodeToAddTo to the lineNode:
				nodeToAddTo = lineNode;
				break;
			}

			CCAction easing = null;
			switch (EasingOptions [currentEasingIndex]) {
			case "CCEaseBack":
				if (currentInOutIndex == 0)
					easing = new CCEaseBackOut (coreAction);
				else if (currentInOutIndex == 1)
					easing = new CCEaseBackIn (coreAction);
				else
					easing = new CCEaseBackInOut (coreAction);

				break;
			case "CCEaseBounce":
				if (currentInOutIndex == 0)
					easing = new CCEaseBounceOut (coreAction);
				else if (currentInOutIndex == 1)
					easing = new CCEaseBounceIn (coreAction);
				else
					easing = new CCEaseBounceInOut (coreAction);

				break;
			case "CCEaseElastic":
				if (currentInOutIndex == 0)
					easing = new CCEaseElasticOut (coreAction);
				else if (currentInOutIndex == 1)
					easing = new CCEaseElasticIn (coreAction);
				else
					easing = new CCEaseElasticInOut (coreAction);

				break;
			case "CCEaseExponential":
				if (currentInOutIndex == 0)
					easing = new CCEaseExponentialOut (coreAction);
				else if (currentInOutIndex == 1)
					easing = new CCEaseExponentialIn (coreAction);
				else
					easing = new CCEaseExponentialInOut (coreAction);

				break;
			case "CCEaseSine":
				if (currentInOutIndex == 0)
					easing = new CCEaseSineOut (coreAction);
				else if (currentInOutIndex == 1)
					easing = new CCEaseSineIn (coreAction);
				else
					easing = new CCEaseSineInOut (coreAction);

				break;
			}

			nodeToAddTo.AddAction (easing ?? coreAction);
		}
Exemple #9
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = Layer.VisibleBoundsWorldspace.Size;

            var layer1 = new CCLayerColor(new CCColor4B(0xFF, 0xFF, 0x00, 0x80));
            layer1.IgnoreAnchorPointForPosition = false;
            layer1.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            layer1.ChildClippingMode = CCClipMode.Bounds;
            AddChild(layer1, 1);

            s = layer1.ContentSize;

            m_pInnerLayer = new CCLayerColor(new CCColor4B(0xFF, 0x00, 0x00, 0x80));
            m_pInnerLayer.IgnoreAnchorPointForPosition = false;
            m_pInnerLayer.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            m_pInnerLayer.ChildClippingMode = CCClipMode.Bounds;
            
            layer1.AddChild(m_pInnerLayer, 1);
            
            //
            // Add two labels using BM label class
            // CCLabelBMFont
            CCLabelBMFont label1 = new CCLabelBMFont("LABEL1", "fonts/konqa32.fnt");
            label1.Position = new CCPoint(m_pInnerLayer.ContentSize.Width, m_pInnerLayer.ContentSize.Height * 0.75f);
            m_pInnerLayer.AddChild(label1);
            
            CCLabelBMFont label2 = new CCLabelBMFont("LABEL2", "fonts/konqa32.fnt");
            label2.Position = new CCPoint(0, m_pInnerLayer.ContentSize.Height * 0.25f);
            m_pInnerLayer.AddChild(label2);


            CCScaleTo scaleTo2 = new CCScaleTo(runTime * 0.25f, 3.0f);
            CCScaleTo scaleTo3 = new CCScaleTo(runTime * 0.25f, 1.0f);

            m_pInnerLayer.RepeatForever(scaleTo2, scaleTo3);


            CCFiniteTimeAction seq = new CCRepeatForever(
                new CCSequence(scaleTo2, scaleTo3)
                );

            m_pInnerLayer.RunAction(seq);

            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var move1 = new CCMoveTo(2, new CCPoint(size.Width / 2, size.Height));
            var move2 = new CCMoveTo(2, new CCPoint(size.Width, size.Height / 2));
            var move3 = new CCMoveTo(2, new CCPoint(size.Width / 2, 0));
            var move4 = new CCMoveTo(2, new CCPoint(0, size.Height / 2));

            layer1.RunAction(new CCRepeatForever(new CCSequence(move1, move2, move3, move4)));
        }
Exemple #10
0
        public override void OnEnter()
        {
            base.OnEnter(); 

            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            CenterSprites(3);

            var actionTo = new CCMoveTo (2, new CCPoint(windowSize.Width - 40, windowSize.Height - 40));
            var actionBy = new CCMoveBy (2, new CCPoint(80, 80));
            var actionByBack = actionBy.Reverse();

            Tamara.RunAction(new CCSequence(actionTo, new CCCallFunc(new Action(() =>
                {
                    if ((Tamara.Position.X != windowSize.Width - 40) || (Tamara.Position.Y != windowSize.Height - 40))
                    {
                        CCLog.Log("ERROR: MoveTo on tamara has failed. Position of tamara = {0}, expected = {1},{2}", Tamara.Position, windowSize.Width - 40, windowSize.Height - 40);
                    }
                }))));
            Grossini.RunAction(new CCSequence(actionBy, actionByBack));
            Kathia.RunAction(new CCSequence(new CCMoveTo(1, new CCPoint(40, 40)), new CCCallFunc(new Action(() =>
                {
                    if (Kathia.Position.X != 40 || Kathia.Position.Y != 40)
                    {
                        CCLog.Log("ERROR: MoveTo on kathia failed. Expected 40,40 but ended at {0}", Kathia.Position);
                    }
                }))));
        }
Exemple #11
0
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            CenterSprites(3);

            var actionTo = new CCMoveTo(2, new CCPoint(windowSize.Width - 40, windowSize.Height - 40));
            var actionBy = new CCMoveBy(2, new CCPoint(80, 80));
            var actionByBack = actionBy.Reverse();

            Tamara.RunAction(new CCSequence(new CCParallel(actionTo, new CCFadeIn(2)), actionBy, actionByBack));
            Grossini.RunAction(new CCSequence(actionBy, new CCParallel(actionByBack, new CCScaleTo(2, 0.25f))));
            Kathia.RunAction(new CCMoveTo(1, new CCPoint(40, 40)));
        }
        private void AddMonster(float time)
        {
            var selectedMonster = new Random().Next() % _monsters.Count;

            var monster = _monsters[selectedMonster];
            var m = monster.Movement;

            //!IMPORTANT -- Every Sprite in Screen must be an new CCSprite! Each Sprite can only be one time on screen
            var spriteMonster = new CCSprite(monster.MonsterSprite);
            spriteMonster.Scale = _appScale;
            spriteMonster.Tag = monster.Tag;

            //BLOCK 1 - Determine where to spawn the monster along the Y axis
            var winSize = Window.WindowSizeInPixels;
            var minX = (spriteMonster.ContentSize.Width / 2);
            var maxX = winSize.Width - spriteMonster.ContentSize.Width / 2;
            var rangeX = maxX - minX;
            var actualY = (new Random().Next() % rangeX) + minX;

            //BLOCK 2 - Determine speed of the monster
            var minDuration = monster.MinVelocity;
            var maxDuration = monster.MaxVelocity;
            var rangeDuration = maxDuration - minDuration;
            var actualDuration = (new Random().Next() % rangeDuration) + minDuration;

            if(m == 1)
            {
                spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height/2);
                AddChild(spriteMonster);

                var actionMove = new CCMoveTo(actualDuration, new CCPoint(actualY, -spriteMonster.ContentSize.Height/2));
                var actionMoveComplete = new CCCallFuncN (node =>
                    {
                        _monstersOnScreen.Remove(node);
                        node.RemoveFromParent();

                        _lives--;
                        var index = _hearths.Count - 1;
                        RemoveChild(_hearths[index]);
                        _hearths.RemoveAt(index);
                        if(_lives == 0)
                        {
                            Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window));
                        }
                    });

                spriteMonster.RunActions(actionMove, actionMoveComplete);
                _monstersOnScreen.Add(spriteMonster);
            }
            else if(m == 2)
            {
                spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height/2);
                AddChild(spriteMonster);

                var actionMoveComplete = new CCCallFuncN (node =>
                    {
                        _monstersOnScreen.Remove(node);
                        node.RemoveFromParent();

                        _lives--;
                        var index = _hearths.Count - 1;
                        RemoveChild(_hearths[index]);
                        _hearths.RemoveAt(index);
                        if(_lives == 0)
                        {
                            Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window));
                        }
                    });

                var bezierList = new List<CCFiniteTimeAction>();
                var bezier = new CCBezierConfig();
                var splitDuration = actualDuration / 6.0f;
                CCBezierTo bezierAction;

                for(int i = 0; i < 6; i++)
                {
                    if(i % 2 == 0)
                    {
                        bezier.ControlPoint1 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200)));
                        bezier.ControlPoint2 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200)));
                        bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200)));
                        bezierAction = new CCBezierTo(splitDuration, bezier);
                    }
                    else
                    {
                        bezier.ControlPoint1 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200)));
                        bezier.ControlPoint2 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200)));
                        bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200)));
                        bezierAction = new CCBezierTo(splitDuration, bezier);
                    }

                    bezierList.Add(bezierAction);
                }

                bezierList.Add(actionMoveComplete);

                var seq = new CCSequence(bezierList.ToArray());
                spriteMonster.RunAction(seq);

                _monstersOnScreen.Add(spriteMonster);
            }
        }
        void OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent)
        {
            if (touches.Count > 0)
            {
                beganLocation = touches [0].Location;
                LoactionTemp = beganLocation;
                rotateSum = 0;
                isRotated = false;
                if (beganLocation.X < mControledEntity.BoundingBoxTransformedToWorld.Center.X) {
                    touchAtLeft = true;
                } else {
                    touchAtLeft = false;
                }

                if (Math.Abs (LoactionTemp.X - mControledEntity.PositionX) > 100) {
                    var moveby = new CCMoveTo ((float)0.1, new CCPoint (LoactionTemp.X, 50.0f));
                    mControledEntity.RunAction (moveby);
                }
            }
        }
		void ShowPointsWithImagesForValue(int pointValue, CCPoint positionToShowScore)
		{


			CCSprite scoreLabel;

			if (pointValue == 100)
			{

				scoreLabel = new CCSprite("100points");
			}
			else if (pointValue == 500)
			{

				scoreLabel = new CCSprite("500points");
			}
			else if (pointValue == 1000)
			{

				scoreLabel = new CCSprite("1000points");
			}
			else if (pointValue == 5000)
			{

				scoreLabel = new CCSprite("5000points");
			}
			else if (pointValue == 10000)
			{

				scoreLabel = new CCSprite("10000points");
			}
			else
			{ //default

				scoreLabel = new CCSprite("100points");

			}

			AddChild(scoreLabel, Constants.DepthPointScore);
			scoreLabel.Position = positionToShowScore;


			CCMoveTo moveAction = new CCMoveTo(1.0f, new CCPoint(scoreLabel.Position.X, scoreLabel.Position.Y + 25));

			scoreLabel.RunAction(moveAction);

			CCSequence seq = new CCSequence(
							   new CCFadeTo(1.5f, 20),
							   new CCCallFuncN(RemoveThisChild));

			scoreLabel.RunAction(seq);

		}
Exemple #15
0
        void OnTouchesEnded (List<CCTouch> touches, CCEvent touchEvent)
        {
            base.TouchesEnded (touches, touchEvent);

            var location = touches [0].Location;

            float ds = CCPoint.Distance (monkey.Position, location);

            float dt = ds / MONKEY_SPEED;

            var moveMonkey = new CCMoveTo (dt, location);
            monkey.RunAction (moveMonkey);  

            CCSimpleAudioEngine.SharedEngine.PlayEffect ("Sounds/tap.mp3");
        }
		void ShowPointsWithFontLabelForValue(int pointValue, CCPoint positionToShowScore)
		{

			CCLabelTtf scoreLabel = new CCLabelTtf(string.Format("{0}", pointValue), "MarkerFelt", 22);
			AddChild(scoreLabel, Constants.DepthPointScore);
			scoreLabel.Color = new CCColor3B(255, 255, 255);
			scoreLabel.Position = positionToShowScore;

			CCMoveTo moveAction = new CCMoveTo(1.0f, new CCPoint(scoreLabel.Position.X, scoreLabel.Position.Y + 25));

			scoreLabel.RunAction(moveAction);

			CCSequence seq = new CCSequence(
				new CCFadeTo(1.5f, 20),
				new CCCallFuncN(RemoveThisLabel));

			scoreLabel.RunAction(seq);

		}
		private void HandleMoveCircle(CCTouch touch)
		{
			const float timeToTake = 1.5f; // in seconds
			CCFiniteTimeAction coreAction = null;

			CCNode nodeToAddTo = drawNodeRoot;

			switch (VariableOptions [currentVariableIndex])
			{
			case "Position":
				coreAction = new CCMoveTo(timeToTake, touch.Location);

					break;
			case "Scale":
					var distance = CCPoint.Distance (touch.Location, drawNodeRoot.Position);
					var desiredScale = distance / DefaultCircleRadius;
					coreAction = new CCScaleTo(timeToTake, desiredScale);

					break;
			case "Rotation":
					float differenceY = touch.Location.Y - drawNodeRoot.PositionY;
					float differenceX = touch.Location.X - drawNodeRoot.PositionX;

					float angleInDegrees = -1 * CCMathHelper.ToDegrees(
						(float)System.Math.Atan2(differenceY, differenceX));

					coreAction = new CCRotateTo (timeToTake, angleInDegrees);

					break;
				case "LineWidth":
					coreAction = new LineWidthAction (timeToTake, touch.Location.X / 40.0f);
					nodeToAddTo = lineNode;
					break;
			}

			CCAction easing = null;
			switch (EasingOptions [currentEasingIndex])
			{
				case "<None>":
					// no easing, do nothing, it will be handled below
					break;
				case "CCEaseBack":
					if (currentInOutIndex == 0)
						easing = new CCEaseBackOut (coreAction);
					else if (currentInOutIndex == 1)
						easing = new CCEaseBackIn (coreAction);
					else
						easing = new CCEaseBackInOut (coreAction);

					break;
				case "CCEaseBounce":
					if (currentInOutIndex == 0)
						easing = new CCEaseBounceOut (coreAction);
					else if (currentInOutIndex == 1)
						easing = new CCEaseBounceIn (coreAction);
					else
						easing = new CCEaseBounceInOut (coreAction);

					break;
				case "CCEaseElastic":
					if (currentInOutIndex == 0)
						easing = new CCEaseElasticOut (coreAction);
					else if (currentInOutIndex == 1)
						easing = new CCEaseElasticIn (coreAction);
					else
						easing = new CCEaseElasticInOut (coreAction);

					break;
				case "CCEaseExponential":
					if (currentInOutIndex == 0)
						easing = new CCEaseExponentialOut (coreAction);
					else if (currentInOutIndex == 1)
						easing = new CCEaseExponentialIn (coreAction);
					else
						easing = new CCEaseExponentialInOut (coreAction);

					break;
				case "CCEaseSine":

					if (currentInOutIndex == 0)
						easing = new CCEaseSineOut (coreAction);
					else if (currentInOutIndex == 1)
						easing = new CCEaseSineIn (coreAction);
					else
						easing = new CCEaseSineInOut (coreAction);

					break;
			}

			if (easing != null)
			{
				nodeToAddTo.AddAction (easing);
			}
			else
			{
				nodeToAddTo.AddAction (coreAction);
			}

		}