コード例 #1
0
        public SpriteChildrenVisibility()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode   aParent;
            CCSprite sprite1, sprite2, sprite3;

            //
            // SpriteBatchNode
            //
            // parents
            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            aParent.position = (new CCPoint(s.width / 3, s.height / 2));
            addChild(aParent, 0);



            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(0, 0));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, 2);

            sprite1.runAction(CCBlink.actionWithDuration(5, 10));

            //
            // Sprite
            //
            aParent          = CCNode.node();
            aParent.position = (new CCPoint(2 * s.width / 3, s.height / 2));
            addChild(aParent, 0);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(0, 0));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, 2);

            sprite1.runAction(CCBlink.actionWithDuration(5, 10));
        }
コード例 #2
0
        public SpriteHybrid()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // parents
            CCNode            parent1 = CCNode.node();
            CCSpriteBatchNode parent2 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);

            addChild(parent1, 0, (int)kTags.kTagNode);
            addChild(parent2, 0, (int)kTags.kTagSpriteBatchNode);


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


            // create 250 sprites
            // only show 80% of them
            for (int i = 0; i < 250; i++)
            {
                int    spriteIdx = (int)(rand.NextDouble() * 14);
                string str       = "";
                string temp      = "";
                if (spriteIdx + 1 < 10)
                {
                    temp = "0" + (spriteIdx + 1);
                }
                else
                {
                    temp = (spriteIdx + 1).ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame  = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                CCSprite      sprite = CCSprite.spriteWithSpriteFrame(frame);
                parent1.addChild(sprite, i, i);

                float x = -1000;
                float y = -1000;
                if (rand.NextDouble() < 0.2f)
                {
                    x = (float)(rand.NextDouble() * s.width);
                    y = (float)(rand.NextDouble() * s.height);
                }
                sprite.position = (new CCPoint(x, y));

                CCActionInterval action = CCRotateBy.actionWithDuration(4, 360);
                sprite.runAction(CCRepeatForever.actionWithAction(action));
            }

            m_usingSpriteBatchNode = false;

            schedule(reparentSprite, 2);
        }
コード例 #3
0
        public SpriteNewTexture()
        {
            base.isTouchEnabled = true;

            CCNode node = CCNode.node();

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

            m_texture1 = CCTextureCache.sharedTextureCache().addImage("Images/grossini_dance_atlas");
            m_texture2 = CCTextureCache.sharedTextureCache().addImage("Images/grossini_dance_atlas-mono");

            m_usingTexture1 = true;

            for (int i = 0; i < 30; i++)
            {
                addNewSprite();
            }
        }
コード例 #4
0
        public SpriteZVertex()
        {
            //
            // 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.
            //

            m_dir  = 1;
            m_time = 0;

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

            CCNode node = CCNode.node();

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

            addChild(node, 0);

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

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

            node.runAction(CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0));
        }
コード例 #5
0
        public SpriteChildrenAnchorPoint()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode   aParent;
            CCSprite sprite1, sprite2, sprite3, sprite4, point;

            //
            // SpriteBatchNode
            //
            // parents

            aParent = CCNode.node();
            addChild(aParent, 0);

            // anchor (0,0)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 4, s.height / 2));
            sprite1.anchorPoint = (new CCPoint(0, 0));


            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;


            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

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


            // anchor (0.5, 0.5)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 2, s.height / 2));
            sprite1.anchorPoint = (new CCPoint(0.5f, 0.5f));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

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


            // anchor (1,1)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 2 + s.width / 4, s.height / 2));
            sprite1.anchorPoint = new CCPoint(1, 1);


            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

            point          = CCSprite.spriteWithFile("Images/r1");
            point.scale    = 0.25f;
            point.position = sprite1.position;
            addChild(point, 10);
        }
コード例 #6
0
        public SpriteBatchNodeChildrenScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode           aParent;
            CCSprite         sprite1, sprite2;
            CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360);
            CCAction         seq = CCRepeatForever.actionWithAction(rot);

            //
            // Children + Scale using Sprite
            // Test 1
            //
            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction(seq);


            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using SpriteBatchNode
            // Test 2
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(3 * s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using Sprite
            // Test 3
            //

            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = (1.5f);
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);

            //
            // Children + Scale using Sprite
            // Test 4
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(3 * s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = 1.5f;
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);
        }
コード例 #7
0
        public SpriteChildrenChildren()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode           aParent;
            CCSprite         l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;
            CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360);
            CCAction         seq = CCRepeatForever.actionWithAction(rot);

            CCActionInterval rot_back    = (CCActionInterval)rot.reverse();
            CCAction         rot_back_fe = CCRepeatForever.actionWithAction(rot_back);

            //
            // SpriteBatchNode: 3 levels of children
            //

            aParent = CCNode.node();
            addChild(aParent);

            // parent
            l1          = CCSprite.spriteWithSpriteFrameName("father.gif");
            l1.position = (new CCPoint(s.width / 2, s.height / 2));
            l1.runAction((CCAction)(seq.copy()));
            aParent.addChild(l1);
            CCSize l1Size = l1.contentSize;

            // child left
            l2a          = CCSprite.spriteWithSpriteFrameName("sister1.gif");
            l2a.position = (new CCPoint(-50 + l1Size.width / 2, 0 + l1Size.height / 2));
            l2a.runAction((CCAction)(rot_back_fe.copy()));
            l1.addChild(l2a);
            CCSize l2aSize = l2a.contentSize;

            // child right
            l2b          = CCSprite.spriteWithSpriteFrameName("sister2.gif");
            l2b.position = (new CCPoint(+50 + l1Size.width / 2, 0 + l1Size.height / 2));
            l2b.runAction((CCAction)(rot_back_fe.copy()));
            l1.addChild(l2b);
            CCSize l2bSize = l2a.contentSize;

            // child left bottom
            l3a1          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3a1.scale    = 0.45f;
            l3a1.position = new CCPoint(0 + l2aSize.width / 2, -100 + l2aSize.height / 2);
            l2a.addChild(l3a1);

            // child left top
            l3a2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3a2.scale    = 0.45f;
            l3a1.position = (new CCPoint(0 + l2aSize.width / 2, +100 + l2aSize.height / 2));
            l2a.addChild(l3a2);

            // child right bottom
            l3b1          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b1.scale    = 0.45f;
            l3b1.IsFlipY  = true;
            l3b1.position = (new CCPoint(0 + l2bSize.width / 2, -100 + l2bSize.height / 2));
            l2b.addChild(l3b1);

            // child right top
            l3b2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b2.scale    = 0.45f;
            l3b2.IsFlipY  = true;
            l3b1.position = new CCPoint(0 + l2bSize.width / 2, +100 + l2bSize.height / 2);
            l2b.addChild(l3b2);
        }
コード例 #8
0
        public TextLayer()
        {
            initWithColor(ccTypes.ccc4(32, 32, 32, 255));

            float x, y;

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

            x = size.width;
            y = size.height;

            CCNode           node   = CCNode.node();
            CCActionInterval effect = getAction();

            node.runAction(effect);
            addChild(node, 0, EffectTestScene.kTagBackground);

            CCSprite bg = CCSprite.spriteWithFile(TestResource.s_back3);

            node.addChild(bg, 0);
            bg.anchorPoint = new CCPoint(0.5f, 0.5f);
            bg.position    = new CCPoint(size.width / 2, size.height / 2);

            CCSprite grossini = CCSprite.spriteWithFile(TestResource.s_pPathSister2);

            node.addChild(grossini, 1);
            grossini.position = new CCPoint(x / 3, y / 2);
            CCActionInterval   sc      = CCScaleBy.actionWithDuration(2, 5);
            CCFiniteTimeAction sc_back = sc.reverse();

            grossini.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc, sc_back))));

            CCSprite tamara = CCSprite.spriteWithFile(TestResource.s_pPathSister1);

            node.addChild(tamara, 1);
            tamara.position = new CCPoint(2 * x / 3, y / 2);
            CCActionInterval   sc2      = CCScaleBy.actionWithDuration(2, 5);
            CCFiniteTimeAction sc2_back = sc2.reverse();

            tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc2, sc2_back))));

            CCLabelTTF label = CCLabelTTF.labelWithString(EffectTestScene.effectsList[EffectTestScene.actionIdx], "Arial", 32);

            label.position = new CCPoint(x / 2, y - 80);
            addChild(label);
            label.tag = EffectTestScene.kTagLabel;

            CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathB1, TestResource.s_pPathB2, this, backCallback);
            CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathR1, TestResource.s_pPathR2, this, restartCallback);
            CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathF1, TestResource.s_pPathF2, this, nextCallback);

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3);

            menu.position  = new CCPoint(0, 0);
            item1.position = new CCPoint(size.width / 2 - 100, 30);
            item2.position = new CCPoint(size.width / 2, 30);
            item3.position = new CCPoint(size.width / 2 + 100, 30);

            addChild(menu, 1);

            schedule(checkAnim);
        }