public SpriteBatchNodeAliased()
        {
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 10);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSprite sprite1 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));

            sprite1.position = (new CCPoint(s.width / 2 - 100, s.height / 2));
            batch.addChild(sprite1, 0, (int)kTagSprite.kTagSprite1);

            CCSprite sprite2 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));

            sprite2.position = (new CCPoint(s.width / 2 + 100, s.height / 2));
            batch.addChild(sprite2, 0, (int)kTagSprite.kTagSprite2);

            CCActionInterval scale      = CCScaleBy.actionWithDuration(2, 5);
            CCActionInterval scale_back = (CCActionInterval)scale.reverse();
            CCActionInterval seq        = (CCActionInterval)(CCSequence.actions(scale, scale_back));
            CCAction         repeat     = CCRepeatForever.actionWithAction(seq);

            CCAction repeat2 = (CCAction)(repeat.copy());

            sprite1.runAction(repeat);
            sprite2.runAction(repeat2);
        }
        public void removeAndAddSprite(float dt)
        {
            CCSpriteBatchNode batch  = (CCSpriteBatchNode)(getChildByTag((int)kTags.kTagSpriteBatchNode));
            CCSprite          sprite = (CCSprite)(batch.getChildByTag((int)kTagSprite.kTagSprite5));

            batch.removeChild(sprite, false);
            batch.addChild(sprite, 0, (int)kTagSprite.kTagSprite5);
        }
        public SpriteBatchNodeZVertex()
        {
            //
            // This test tests z-order
            // If you are going to use it is better to use a 3D projection
            //
            // WARNING:
            // The developer is resposible for ordering it's sprites according to it's Z if the sprite has
            // transparent parts.
            //


            CCSize s    = CCDirector.sharedDirector().getWinSize();
            float  step = s.width / 12;

            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1);

            // camera uses the center of the image as the pivoting point
            batch.contentSize = new CCSize(s.width, s.height);
            batch.anchorPoint = (new CCPoint(0.5f, 0.5f));
            batch.position    = (new CCPoint(s.width / 2, s.height / 2));


            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            for (int i = 0; i < 5; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
                sprite.position = (new CCPoint((i + 1) * step, s.height / 2));
                sprite.vertexZ  = (10 + i * 40);
                batch.addChild(sprite, 0);
            }

            for (int i = 5; i < 11; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
                sprite.position = (new CCPoint((i + 1) * step, s.height / 2));
                sprite.vertexZ  = 10 + (10 - i) * 40;
                batch.addChild(sprite, 0);
            }

            batch.runAction(CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0));
        }
        public SpriteBatchNodeReorder()
        {
            List <Object>     a       = new List <Object>(10);
            CCSpriteBatchNode asmtest = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts");

            for (int i = 0; i < 10; i++)
            {
                CCSprite s1 = CCSprite.spriteWithBatchNode(asmtest, new CCRect(0, 0, 50, 50));
                a.Add(s1);
                asmtest.addChild(s1, 10);
            }

            for (int i = 0; i < 10; i++)
            {
                if (i != 5)
                {
                    asmtest.reorderChild((CCNode)(a[i]), 9);
                }
            }

            int           prev     = -1;
            List <CCNode> children = asmtest.children;
            CCSprite      child;

            foreach (var item in children)
            {
                child = (CCSprite)item;
                if (child == null)
                {
                    break;
                }

                int currentIndex = child.atlasIndex;
                Debug.Assert(prev == currentIndex - 1, "Child order failed");
                ////----UXLOG("children %x - atlasIndex:%d", child, currentIndex);
                prev = currentIndex;
            }

            prev = -1;
            List <CCSprite> sChildren = asmtest.Descendants;

            foreach (var item in sChildren)
            {
                child = (CCSprite)item;
                if (child == null)
                {
                    break;
                }

                int currentIndex = child.atlasIndex;
                Debug.Assert(prev == currentIndex - 1, "Child order failed");
                ////----UXLOG("descendant %x - atlasIndex:%d", child, currentIndex);
                prev = currentIndex;
            }

            //a.release();       //memory leak : 2010-0415
        }
        public SpriteBatchNodeFlip()
        {
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 10);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSprite sprite1 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));

            sprite1.position = (new CCPoint(s.width / 2 - 100, s.height / 2));
            batch.addChild(sprite1, 0, (int)kTagSprite.kTagSprite1);

            CCSprite sprite2 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));

            sprite2.position = new CCPoint(s.width / 2 + 100, s.height / 2);
            batch.addChild(sprite2, 0, (int)kTagSprite.kTagSprite2);

            schedule(flipSprites, 1);
        }
        public SpriteBatchNodeZOrder()
        {
            m_dir = 1;

            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.sharedDirector().getWinSize();

            float step = s.width / 11;

            for (int i = 0; i < 5; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
                sprite.position = (new CCPoint((i + 1) * step, s.height / 2));
                batch.addChild(sprite, i);
            }

            for (int i = 5; i < 10; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
                sprite.position = new CCPoint((i + 1) * step, s.height / 2);
                batch.addChild(sprite, 14 - i);
            }

            CCSprite sprite1 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 3, 121 * 0, 85, 121));

            batch.addChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
            sprite1.position = (new CCPoint(s.width / 2, s.height / 2 - 20));
            sprite1.scale    = 6;
            sprite1.Color    = new ccColor3B(Color.Red);

            schedule(reorderSprite, 1);
        }
        public SpriteBatchNodeReorderIssue744()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // Testing issue #744
            // http://code.google.com/p/cocos2d-iphone/issues/detail?id=744
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 15);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSprite sprite = CCSprite.spriteWithBatchNode(batch, new CCRect(0, 0, 85, 121));

            sprite.position = (new CCPoint(s.width / 2, s.height / 2));
            batch.addChild(sprite, 3);
            batch.reorderChild(sprite, 1);
        }
Exemple #8
0
        public void addNewSprite()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCPoint p = new CCPoint((float)(rand.NextDouble() * s.width), (float)(rand.NextDouble() * s.height));

            CCSpriteBatchNode batch = (CCSpriteBatchNode)getChildByTag((int)kTags.kTagSpriteBatchNode);

            int idx = (int)(rand.NextDouble() * 1400 / 100);
            int x   = (idx % 5) * 85;
            int y   = (idx / 5) * 121;


            CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(x, y, 85, 121));

            batch.addChild(sprite);

            sprite.position = (new CCPoint(p.x, p.y));

            CCActionInterval action;
            float            random = (float)rand.NextDouble();

            if (random < 0.20)
            {
                action = CCScaleBy.actionWithDuration(3, 2);
            }
            else if (random < 0.40)
            {
                action = CCRotateBy.actionWithDuration(3, 360);
            }
            else if (random < 0.60)
            {
                action = CCBlink.actionWithDuration(1, 3);
            }
            else if (random < 0.8)
            {
                action = CCTintBy.actionWithDuration(2, 0, -255, -255);
            }
            else
            {
                action = CCFadeOut.actionWithDuration(2);
            }
            CCActionInterval action_back = (CCActionInterval)action.reverse();
            CCActionInterval seq         = (CCActionInterval)(CCSequence.actions(action, action_back));

            sprite.runAction(CCRepeatForever.actionWithAction(seq));
        }
        public SpriteBatchNodeAnchorPoint()
        {
            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.sharedDirector().getWinSize();


            CCActionInterval rotate = CCRotateBy.actionWithDuration(10, 360);
            CCAction         action = CCRepeatForever.actionWithAction(rotate);

            for (int i = 0; i < 3; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * i, 121 * 1, 85, 121));
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("Images/r1");
                point.scale    = 0.25f;
                point.position = sprite.position;
                addChild(point, 1);

                switch (i)
                {
                case 0:
                    sprite.anchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.anchorPoint = (new CCPoint(0.5f, 0.5f));
                    break;

                case 2:
                    sprite.anchorPoint = (new CCPoint(1, 1));
                    break;
                }

                point.position = sprite.position;

                CCAction copy = (CCAction)(action.copy());
                sprite.runAction(copy);
                batch.addChild(sprite, i);
            }
        }
Exemple #10
0
        public Sprite6()
        {
            // small capacity. Testing resizing
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1);

            addChild(batch, 0, kTagSpriteBatchNode);
            batch.isRelativeAnchorPoint = false;

            CCSize s = CCDirector.sharedDirector().getWinSize();

            batch.anchorPoint = new CCPoint(0.5f, 0.5f);
            batch.contentSize = (new CCSize(s.width, s.height));


            // SpriteBatchNode actions
            CCActionInterval rotate = CCRotateBy.actionWithDuration(5, 360);
            CCAction         action = CCRepeatForever.actionWithAction(rotate);

            // SpriteBatchNode actions
            CCActionInterval rotate_back    = (CCActionInterval)rotate.reverse();
            CCActionInterval rotate_seq     = (CCActionInterval)(CCSequence.actions(rotate, rotate_back));
            CCAction         rotate_forever = CCRepeatForever.actionWithAction(rotate_seq);

            CCActionInterval scale         = CCScaleBy.actionWithDuration(5, 1.5f);
            CCActionInterval scale_back    = (CCActionInterval)scale.reverse();
            CCActionInterval scale_seq     = (CCActionInterval)(CCSequence.actions(scale, scale_back));
            CCAction         scale_forever = CCRepeatForever.actionWithAction(scale_seq);

            float step = s.width / 4;

            for (int i = 0; i < 3; i++)
            {
                CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * i, 121 * 1, 85, 121));
                sprite.position = (new CCPoint((i + 1) * step, s.height / 2));

                sprite.runAction((CCAction)(action.copy()));
                batch.addChild(sprite, i);
            }

            batch.runAction(scale_forever);
            batch.runAction(rotate_forever);
        }
Exemple #11
0
        public SpriteSubclass()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/ghosts");
            CCSpriteBatchNode aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts");

            // MySprite1
            MySprite1 sprite = MySprite1.spriteWithSpriteFrameName("father.gif");

            sprite.position = (new CCPoint(s.width / 4 * 1, s.height / 2));
            aParent.addChild(sprite);
            addChild(aParent);

            // MySprite2
            MySprite2 sprite2 = MySprite2.spriteWithFile("Images/grossini");

            addChild(sprite2);
            sprite2.position = (new CCPoint(s.width / 4 * 3, s.height / 2));
        }
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("Images/r1");
                point.scale    = 0.25f;
                point.position = sprite.position;
                addChild(point, 200);

                switch (i)
                {
                case 0:
                    sprite.anchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.anchorPoint = new CCPoint(0.5f, 0.5f);
                    break;

                case 2:
                    sprite.anchorPoint = (new CCPoint(1, 1));
                    break;
                }

                point.position = sprite.position;

                CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");
                addChild(spritebatch);

                List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>();
                string tmp = "";
                for (int j = 0; j < 14; j++)
                {
                    string temp = "";
                    if (i + 1 < 10)
                    {
                        temp = "0" + (i + 1);
                    }
                    else
                    {
                        temp = (i + 1).ToString();
                    }
                    tmp = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false)));

                animFrames = null;

                CCFlipY            flip      = CCFlipY.actionWithFlipY(true);
                CCFlipY            flip_back = CCFlipY.actionWithFlipY(false);
                CCDelayTime        delay     = CCDelayTime.actionWithDuration(1);
                CCFiniteTimeAction seq       = CCSequence.actions((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.copyWithZone(null), (CCFiniteTimeAction)flip_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));

                spritebatch.addChild(sprite, i);
            }
        }
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // parents
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");

            CCSprite sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");

            sprite1.position = (new CCPoint(s.width / 3, s.height / 2));

            CCSprite sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");

            sprite2.position = (new CCPoint(50, 50));

            CCSprite sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");

            sprite3.position = (new CCPoint(-50, -50));

            batch.addChild(sprite1);
            sprite1.addChild(sprite2);
            sprite1.addChild(sprite3);

            // BEGIN NEW CODE
            List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>();
            string str = "";

            for (int i = 1; i < 15; i++)
            {
                string temp = "";
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f);

            sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));
            // END NEW CODE

            CCActionInterval action        = CCMoveBy.actionWithDuration(2, new CCPoint(200, 0));
            CCActionInterval action_back   = (CCActionInterval)action.reverse();
            CCActionInterval action_rot    = CCRotateBy.actionWithDuration(2, 360);
            CCActionInterval action_s      = CCScaleBy.actionWithDuration(2, 2);
            CCActionInterval action_s_back = (CCActionInterval)action_s.reverse();

            CCActionInterval seq2 = (CCActionInterval)action_rot.reverse();

            sprite2.runAction(CCRepeatForever.actionWithAction(seq2));

            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction(action_rot)));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back)))));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back)))));
        }
        public SpriteBatchNodeOffsetAnchorRotation()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("Images/r1");
                point.scale    = 0.25f;
                point.position = sprite.position;
                addChild(point, 200);

                switch (i)
                {
                case 0:
                    sprite.anchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.anchorPoint = new CCPoint(0.5f, 0.5f);
                    break;

                case 2:
                    sprite.anchorPoint = new CCPoint(1, 1);
                    break;
                }

                point.position = sprite.position;

                CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");
                addChild(spritebatch);

                List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(14);
                string str = "";
                for (int k = 0; k < 14; k++)
                {
                    string temp = "";
                    if (k + 1 < 10)
                    {
                        temp = "0" + (k + 1);
                    }
                    else
                    {
                        temp = k + 1 + "";
                    }
                    str = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));
                sprite.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(10, 360)));

                spritebatch.addChild(sprite, i);

                //animFrames.release();    // win32 : memory leak    2010-0415
            }
        }
        public SpriteFrameTest()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames);
            CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();

            cache.addSpriteFramesWithFile("animations/grossini");
            cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");
            cache.addSpriteFramesWithFile("animations/grossini_blue", "animations/images/grossini_blue");

            //
            // Animation using Sprite BatchNode
            //
            m_pSprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            m_pSprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2));

            CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");

            spritebatch.addChild(m_pSprite1);
            addChild(spritebatch);

            List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15);

            string str = "";

            for (int i = 1; i < 15; i++)
            {
                string temp;
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

            m_pSprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));

            // to test issue #732, uncomment the following line
            m_pSprite1.IsFlipX = false;
            m_pSprite1.IsFlipY = false;

            //
            // Animation using standard Sprite
            //
            m_pSprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            m_pSprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2));
            addChild(m_pSprite2);


            List <CCSpriteFrame> moreFrames = new List <CCSpriteFrame>(20);

            for (int i = 1; i < 15; i++)
            {
                string temp;
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_gray_{0}.png", temp);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                moreFrames.Add(frame);
            }


            for (int i = 1; i < 5; i++)
            {
                str = string.Format("grossini_blue_0{0}.png", i);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                moreFrames.Add(frame);
            }

            // append frames from another batch
            moreFrames.AddRange(animFrames);
            CCAnimation animMixed = CCAnimation.animationWithFrames(moreFrames);


            m_pSprite2.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animMixed, false)));



            // to test issue #732, uncomment the following line
            m_pSprite2.IsFlipX = (false);
            m_pSprite2.IsFlipY = (false);

            schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
Exemple #16
0
        public override void onEnter()
        {
            base.onEnter();
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
            //
            // CCSpriteFrameCache is a cache of CCSpriteFrames
            // CCSpriteFrames each contain a texture id and a rect (frame).

            CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();

            cache.addSpriteFramesWithFile("animations/grossini-aliases", "animations/images/grossini-aliases");

            //
            // Animation using Sprite batch
            //
            // A CCSpriteBatchNode can reference one and only one texture (one .png file)
            // Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode
            // All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call
            // If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
            //
            // When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
            // When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation,
            // but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode,
            // and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode
            //

            CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");

            sprite.position = (new CCPoint(s.width * 0.5f, s.height * 0.5f));

            CCSpriteBatchNode spriteBatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini-aliases");

            spriteBatch.addChild(sprite);
            addChild(spriteBatch);

            List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15);
            string str = "";

            for (int i = 1; i < 15; i++)
            {
                string temp = "";
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                // Obtain frames by alias name
                str = string.Format("dance_{0}", temp);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

            // 14 frames * 1sec = 14 seconds
            sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(14.0f, animation, false)));
        }
Exemple #17
0
        public SpriteBatchNodeChildren2()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // parents
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);

            batch.Texture.generateMipmap();

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");


            CCSprite sprite11 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");

            sprite11.position = (new CCPoint(s.width / 3, s.height / 2));

            CCSprite sprite12 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");

            sprite12.position = (new CCPoint(20, 30));
            sprite12.scale    = 0.2f;

            CCSprite sprite13 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");

            sprite13.position = (new CCPoint(-20, 30));
            sprite13.scale    = 0.2f;

            batch.addChild(sprite11);
            sprite11.addChild(sprite12, -2);
            sprite11.addChild(sprite13, 2);

            // don't rotate with it's parent
            sprite12.honorParentTransform = ((ccHonorParentTransform)(sprite12.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE));

            // don't scale and rotate with it's parent
            sprite13.honorParentTransform = ((ccHonorParentTransform)(sprite13.honorParentTransform & (ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE | ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE)));

            CCActionInterval action        = CCMoveBy.actionWithDuration(2, new CCPoint(200, 0));
            CCActionInterval action_back   = (CCActionInterval)action.reverse();
            CCActionInterval action_rot    = CCRotateBy.actionWithDuration(2, 360);
            CCActionInterval action_s      = CCScaleBy.actionWithDuration(2, 2);
            CCActionInterval action_s_back = (CCActionInterval)action_s.reverse();

            sprite11.runAction(CCRepeatForever.actionWithAction(action_rot));
            sprite11.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back))));
            sprite11.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back))));

            //
            // another set of parent / children
            //

            CCSprite sprite21 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");

            sprite21.position = (new CCPoint(2 * s.width / 3, s.height / 2 - 50));

            CCSprite sprite22 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");

            sprite22.position = (new CCPoint(20, 30));
            sprite22.scale    = 0.8f;

            CCSprite sprite23 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");

            sprite23.position = (new CCPoint(-20, 30));
            sprite23.scale    = 0.8f;

            batch.addChild(sprite21);
            sprite21.addChild(sprite22, -2);
            sprite21.addChild(sprite23, 2);

            // don't rotate with it's parent
            sprite22.honorParentTransform = ((ccHonorParentTransform)(sprite22.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE));

            // don't scale and rotate with it's parent
            sprite23.honorParentTransform = ((ccHonorParentTransform)(sprite23.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE));

            sprite21.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(1, 360)));
            sprite21.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(CCScaleTo.actionWithDuration(0.5f, 5.0f), CCScaleTo.actionWithDuration(0.5f, 1)))));
        }
        public SpriteBatchNodeOffsetAnchorSkewScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = new CCPoint(s.width / 4 * (i + 1), s.height / 2);

                CCSprite point = CCSprite.spriteWithFile("Images/r1");
                point.scale    = 0.25f;
                point.position = sprite.position;
                addChild(point, 200);

                switch (i)
                {
                case 0:
                    sprite.anchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.anchorPoint = new CCPoint(0.5f, 0.5f);
                    break;

                case 2:
                    sprite.anchorPoint = new CCPoint(1, 1);
                    break;
                }

                point.position = sprite.position;

                CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");
                addChild(spritebatch);

                List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>();
                string tmp = "";
                for (int j = 0; j < 14; j++)
                {
                    string temp = "";
                    if (j + 1 < 10)
                    {
                        temp = "0" + (j + 1);
                    }
                    else
                    {
                        temp = (j + 1).ToString();
                    }
                    tmp = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false)));

                animFrames = null;

                // skew
                CCSkewBy         skewX      = CCSkewBy.actionWithDuration(2, 45, 0);
                CCActionInterval skewX_back = (CCActionInterval)skewX.reverse();
                CCSkewBy         skewY      = CCSkewBy.actionWithDuration(2, 0, 45);
                CCActionInterval skewY_back = (CCActionInterval)skewY.reverse();

                CCFiniteTimeAction seq_skew = CCSequence.actions(skewX, skewX_back, skewY, skewY_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_skew));

                // scale
                CCScaleBy          scale      = CCScaleBy.actionWithDuration(2, 2);
                CCActionInterval   scale_back = (CCActionInterval)scale.reverse();
                CCFiniteTimeAction seq_scale  = CCSequence.actions(scale, scale_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_scale));

                spritebatch.addChild(sprite, i);
            }
        }
        public SpriteBatchNodeColorOpacity()
        {
            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1);

            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

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

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


            CCSize s = CCDirector.sharedDirector().getWinSize();

            sprite1.position = new CCPoint((s.width / 5) * 1, (s.height / 3) * 1);
            sprite2.position = new CCPoint((s.width / 5) * 2, (s.height / 3) * 1);
            sprite3.position = new CCPoint((s.width / 5) * 3, (s.height / 3) * 1);
            sprite4.position = new CCPoint((s.width / 5) * 4, (s.height / 3) * 1);
            sprite5.position = new CCPoint((s.width / 5) * 1, (s.height / 3) * 2);
            sprite6.position = new CCPoint((s.width / 5) * 2, (s.height / 3) * 2);
            sprite7.position = new CCPoint((s.width / 5) * 3, (s.height / 3) * 2);
            sprite8.position = new CCPoint((s.width / 5) * 4, (s.height / 3) * 2);

            CCActionInterval action      = CCFadeIn.actionWithDuration(2);
            CCActionInterval action_back = (CCActionInterval)action.reverse();
            CCAction         fade        = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back)));

            CCActionInterval tintred      = CCTintBy.actionWithDuration(2, 0, -255, -255);
            CCActionInterval tintred_back = (CCActionInterval)tintred.reverse();
            CCAction         red          = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(tintred, tintred_back)));

            CCActionInterval tintgreen      = CCTintBy.actionWithDuration(2, -255, 0, -255);
            CCActionInterval tintgreen_back = (CCActionInterval)tintgreen.reverse();
            CCAction         green          = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(tintgreen, tintgreen_back)));

            CCActionInterval tintblue      = CCTintBy.actionWithDuration(2, -255, -255, 0);
            CCActionInterval tintblue_back = (CCActionInterval)tintblue.reverse();
            CCAction         blue          = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(tintblue, tintblue_back)));


            sprite5.runAction(red);
            sprite6.runAction(green);
            sprite7.runAction(blue);
            sprite8.runAction(fade);

            // late add: test dirtyColor and dirtyPosition
            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);


            schedule(removeAndAddSprite, 2);
        }