Example #1
0
        public Test5()
        {
            CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
            sp2 = new CCSprite(TestResource.s_pPathSister2);

            sp1.Position = (new CCPoint(100, 160));
            sp2.Position = (new CCPoint(380, 160));

			var rot = new CCRotateBy (2, 360);
            var rot_back = rot.Reverse();

			var forever = new CCRepeatForever (rot, rot_back) { Tag = 101 };

			// Since Actions are immutable to set the tag differently we need to 
			// create a new action.  Notice that the same actions can be used in
			// this case instead of copying them as well.
			forever2 = new CCRepeatForever (rot, rot_back) { Tag = 102 };
            
            AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);
            AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);

            RemoveChild(sp2, true);
            AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);

            // Sprite 1 should run and run
            // Sprite 2 should stop
            sp1.RunAction(forever);
            sp2.RunAction(forever2);

            // Experiment with removing sp2 and re-adding it after cleanup to reproduce an error in child management
			//ScheduleOnce(Stage2OfTest, 2.0f);
			Schedule(addAndRemove, 2.0f);
        }
        public void InitializeBear()
        {
            var spriteSheet = new CCSpriteSheet("animations/AnimBear.plist");
            var walkAnimation = new CCAnimation(spriteSheet.Frames, 0.1f);
            bearAction = new CCRepeatForever(new CCAnimate(walkAnimation));

            bearSprite = new CCSprite(spriteSheet.Frames.First()) { Name = "Bear" };
        }
Example #3
0
        public CCLayerMultiplex(CCAction inAction, CCAction outAction, params CCLayer[] layers) 
            : this()
        {
            InAction = inAction;
            OutAction = outAction;

            foreach(CCLayer layer in layers)
            {
                AddLayer(layer);
            }
        }
        public SpriteBatchNodeColorOpacity()
        {
            // Small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
            sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite3 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121));
            sprite4 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121));

            sprite5 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
            sprite6 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite7 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121));
            sprite8 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121));


            CCFiniteTimeAction action = new CCFadeIn  (2);
            CCFiniteTimeAction action_back = (CCFiniteTimeAction)action.Reverse();
            fade = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(action, action_back)));

            CCFiniteTimeAction tintred = new CCTintBy (2, 0, -255, -255);
            CCFiniteTimeAction tintred_back = (CCFiniteTimeAction)tintred.Reverse();
            red = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintred, tintred_back)));

            CCFiniteTimeAction tintgreen = new CCTintBy (2, -255, 0, -255);
            CCFiniteTimeAction tintgreen_back = (CCFiniteTimeAction)tintgreen.Reverse();
            green = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintgreen, tintgreen_back)));

            CCFiniteTimeAction tintblue = new CCTintBy (2, -255, -255, 0);
            CCFiniteTimeAction tintblue_back = (CCFiniteTimeAction)tintblue.Reverse();
            blue = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintblue, tintblue_back)));

            batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1);
            batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2);
            batch.AddChild(sprite3, 0, (int)kTagSprite.kTagSprite3);
            batch.AddChild(sprite4, 0, (int)kTagSprite.kTagSprite4);
            batch.AddChild(sprite5, 0, (int)kTagSprite.kTagSprite5);
            batch.AddChild(sprite6, 0, (int)kTagSprite.kTagSprite6);
            batch.AddChild(sprite7, 0, (int)kTagSprite.kTagSprite7);
            batch.AddChild(sprite8, 0, (int)kTagSprite.kTagSprite8);
        }
Example #5
0
        public SpriteColorOpacity()
        {
            sprite1 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121));
            sprite2 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite3 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 2, 121 * 1, 85, 121));
            sprite4 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 3, 121 * 1, 85, 121));

            sprite5 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121));
            sprite6 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite7 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 2, 121 * 1, 85, 121));
            sprite8 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 3, 121 * 1, 85, 121));

            AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1);
            AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2);
            AddChild(sprite3, 0, (int)kTagSprite.kTagSprite3);
            AddChild(sprite4, 0, (int)kTagSprite.kTagSprite4);
            AddChild(sprite5, 0, (int)kTagSprite.kTagSprite5);
            AddChild(sprite6, 0, (int)kTagSprite.kTagSprite6);
            AddChild(sprite7, 0, (int)kTagSprite.kTagSprite7);
            AddChild(sprite8, 0, (int)kTagSprite.kTagSprite8);


            CCFiniteTimeAction action = new CCFadeIn  (2);
            CCFiniteTimeAction action_back = (CCFiniteTimeAction)action.Reverse();
            fade = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(action, action_back)));

            CCFiniteTimeAction tintred = new CCTintBy (2, 0, -255, -255);
            CCFiniteTimeAction tintred_back = (CCFiniteTimeAction)tintred.Reverse();
            red = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintred, tintred_back)));

            CCFiniteTimeAction tintgreen = new CCTintBy (2, -255, 0, -255);
            CCFiniteTimeAction tintgreen_back = (CCFiniteTimeAction)tintgreen.Reverse();
            green = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintgreen, tintgreen_back)));

            CCFiniteTimeAction tintblue = new CCTintBy (2, -255, -255, 0);
            CCFiniteTimeAction tintblue_back = (CCFiniteTimeAction)tintblue.Reverse();
            blue = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintblue, tintblue_back)));
        }
Example #6
0
        internal void RemoveAction(CCAction action, CCNode target)
        {
            if (action == null || target == null)
                return;

            HashElement element;
            if (targets.TryGetValue(target, out element))
            {
                int limit = element.ActionStates.Count;
                bool actionFound = false;

                for (int i = 0; i < limit; i++)
                {
                    var actionState = element.ActionStates[i];

                    if (actionState.Action == action && actionState.OriginalTarget == target)
                    {
                        RemoveActionAtIndex(i, element);
                        actionFound = true;
                        break;
                    }
                }

                if (!actionFound)
                    CCLog.Log("CocosSharp : RemoveAction: Action not found");
            }
            else
            {
                CCLog.Log("CocosSharp : RemoveAction: Target not found");
            }

        }
Example #7
0
        public CCActionState AddAction(CCAction action, CCNode target, bool paused = false)
        {
            Debug.Assert(action != null);
            Debug.Assert(target != null);

            HashElement element;
            if (!targets.TryGetValue(target, out element))
            {
                element = new HashElement();
                element.Paused = paused;
                element.Target = target;
                targets.Add(target, element);
            }

            ActionAllocWithHashElement(element);
            var isActionRunning = false;
            foreach (var existingState in element.ActionStates)
            {
                if (existingState.Action == action)
                {
                    isActionRunning = true;
                    break;
                }
            }
            Debug.Assert(!isActionRunning, "CocosSharp : Action is already running for this target.");
            var state = action.StartAction(target);
            element.ActionStates.Add(state);

            return state;
        }
Example #8
0
 public CCLayerMultiplex(CCAction inAction, CCAction outAction) : this(inAction, outAction, null)
 {
 }
		private void createActions()
		{
			//swing action for health drops
			CCFiniteTimeAction easeSwing = new CCSequence(
						   new CCEaseInOut(new CCRotateTo(1.2f, -10), 2),
						   new CCEaseInOut(new CCRotateTo(1.2f, 10), 2));
			_swingHealth = new CCRepeatForever(easeSwing);
			//_swingHealth ->retain();

			//action sequence for shockwave: fade out, call back when done
			_shockwaveSequence = new CCSequence(
							new CCFadeOut(1.0f),
							new CCCallFunc(shockwaveDone));
			//_shockwaveSequence->retain();

			//action to grow bomb
			_growBomb = new CCScaleTo(6.0f, 1);
			//_growBomb->retain();

			//action to rotate sprites
			_rotateSprite = new CCRepeatForever(new CCRotateBy(0.5f, -90));
			//_rotateSprite->retain();


			//sprite animations
			CCAnimation animation;

			var spriteFrameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

			animation = new CCAnimation();
			CCSpriteFrame frame;
			int i;
			//animation for ground hit
			for (i = 1; i <= 10; i++)
			{

				frame = spriteFrameCache[String.Format("boom{0}.png", i)];
				animation.AddSpriteFrame(frame);

			}



			animation.DelayPerUnit = (1 / 10.0f);
			animation.RestoreOriginalFrame = true;
			_groundHit = new CCSequence(
						new CCMoveBy(0, new CCPoint(0, _screenSize.Height * 0.12f)),
						new CCAnimate(animation),
						new CCCallFuncN(animationDone));
			//_groundHit->retain();

			animation = new CCAnimation();
			//animation for falling object explosion
			for (i = 1; i <= 7; i++)
			{

				frame = spriteFrameCache[String.Format("explosion_small{0}.png", i)];

				animation.AddSpriteFrame(frame);
			}

			animation.DelayPerUnit = 0.5f / 7.0f;
			animation.RestoreOriginalFrame = true;
			_explosion = new CCSequence(
					new CCAnimate(animation),
					new CCCallFuncN(animationDone)
					);
			;
			// _explosion->retain();
		}
        public void InitializeMonkey()
        {
            var spriteSheet = new CCSpriteSheet("animations/monkey.plist");
            var walkAnimation = new CCAnimation(spriteSheet.Frames, 0.1f);
            monkeyAction = new CCRepeatForever(new CCAnimate(walkAnimation));

            // Load the frames using the Frames property which
            var animationFrames = spriteSheet.Frames.FindAll((x) =>
                {
                    return x.TextureFilename.StartsWith("frame");
                });

            monkeySprite = new CCSprite(animationFrames.First()) { Name = "Monkey" };
            monkeySprite.Scale = 0.5f;
        }
Example #11
0
        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;
            }

            CocosSharp.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);
        }
Example #12
0
		// Commented out for now as it does not seem to be used
		//public void Debug()
		//{
		//}

		public void SetCallFunc(CCAction callFunc, string callbackNamed)
		{
			_keyframeCallFuncs.Add(callbackNamed, callFunc);
		}
Example #13
0
 public CCLayerMultiplex(CCAction inAction, CCAction outAction) : this(inAction, outAction, null)
 {
 }