Example #1
0
        public override void onEnter()
        {
            base.onEnter();

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

            // the root object just rotates around
            m_root = CCSprite.spriteWithFile(s_pPathR1);
            addChild(m_root, 1);
            m_root.position = (new CCPoint(s.width / 2, s.height / 2));

            // the target object is offset from root, and the streak is moved to follow it
            m_target = CCSprite.spriteWithFile(s_pPathR1);
            m_root.addChild(m_target);
            m_target.position = (new CCPoint(100, 0));

            // create the streak object and add it to the scene
            //m_streak = CCMotionStreak.streakWithFade(2, 3, s_streak, 32, 32, new ccColor4B(0,255,0,255) );
            addChild(m_streak);
            // schedule an update on each frame so we can syncronize the streak with the target
            schedule(onUpdate);

            CCActionInterval a1 = CCRotateBy.actionWithDuration(2, 360);

            CCAction         action1 = CCRepeatForever.actionWithAction(a1);
            CCActionInterval motion  = CCMoveBy.actionWithDuration(2, new CCPoint(100, 0));

            m_root.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(motion, motion.reverse()))));
            m_root.runAction(action1);
        }
Example #2
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));
        }
        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);
        }
Example #4
0
        public void addNewSprite()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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


            CCNode   node   = getChildByTag((int)kTags.kTagSpriteBatchNode);
            CCSprite sprite = CCSprite.spriteWithTexture(m_texture1, new CCRect(x, y, 85, 121));

            node.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 void reparentSprite(float dt)
        {
            CCNode p1 = getChildByTag((int)kTags.kTagNode);
            CCNode p2 = getChildByTag((int)kTags.kTagSpriteBatchNode);

            List <CCNode> retArray = new List <CCNode>(250);

            if (m_usingSpriteBatchNode)
            {
                CC_SWAP(p1, p2);
            }


            ////----UXLOG("New parent is: %x", p2);

            CCNode        node;
            List <CCNode> children = p1.children;

            foreach (var item in children)
            {
                if (item == null)
                {
                    break;
                }
                retArray.Add(item);
            }

            int i = 0;

            p1.removeAllChildrenWithCleanup(false);

            foreach (var item in retArray)
            {
                if (item == null)
                {
                    break;
                }
                p2.addChild(item, i, i);
                i++;
            }
            m_usingSpriteBatchNode = !m_usingSpriteBatchNode;
        }
Example #6
0
        public override void onEnter()
        {
            base.onEnter();

            float x, y;

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

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

            CCNode blue  = CCLayerColor.layerWithColor(new ccColor4B(0, 0, 255, 255));
            CCNode red   = CCLayerColor.layerWithColor(new ccColor4B(255, 0, 0, 255));
            CCNode green = CCLayerColor.layerWithColor(new ccColor4B(0, 255, 0, 255));
            CCNode white = CCLayerColor.layerWithColor(new ccColor4B(255, 255, 255, 255));

            blue.scale    = (0.5f);
            blue.position = (new CCPoint(-x / 4, -y / 4));
            blue.addChild(SpriteLayer.node());

            red.scale    = (0.5f);
            red.position = (new CCPoint(x / 4, -y / 4));

            green.scale    = (0.5f);
            green.position = (new CCPoint(-x / 4, y / 4));
            green.addChild(TestLayer.node());

            white.scale    = (0.5f);
            white.position = (new CCPoint(x / 4, y / 4));

            addChild(blue, -1);
            addChild(white);
            addChild(green);
            addChild(red);

            CCAction rot = CCRotateBy.actionWithDuration(8, 720);

            blue.runAction(rot);
            red.runAction((CCAction)(rot.copy()));
            green.runAction((CCAction)(rot.copy()));
            white.runAction((CCAction)(rot.copy()));
        }
Example #7
0
        public void initWithSubTest(int nSubTest, CCNode p)
        {
            subtestNumber = nSubTest;
            parent        = p;
            batchNode     = null;

            /*
             * Tests:
             * 1: 1 (32-bit) PNG sprite of 52 x 139
             * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
             * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
             * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139
             *
             * 5: 14 (32-bit) PNG sprites of 85 x 121 each
             * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
             * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
             * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each
             *
             * 9: 64 (32-bit) sprites of 32 x 32 each
             * 10: 64 (32-bit) PNG Batch Node of 32 x 32 each
             * 11: 64 (16-bit) PNG Batch Node of 32 x 32 each
             * 12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
             */

            // purge textures
            CCTextureCache mgr = CCTextureCache.sharedTextureCache();

            //		[mgr removeAllTextures];
            mgr.removeTexture(mgr.addImage("Images/grossinis_sister1"));
            mgr.removeTexture(mgr.addImage("Images/grossini_dance_atlas"));
            mgr.removeTexture(mgr.addImage("Images/spritesheet1"));

            switch (subtestNumber)
            {
            case 1:
            case 4:
            case 7:
                break;

            ///
            case 2:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossinis_sister1", 100);
                p.addChild(batchNode, 0);
                break;

            case 3:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossinis_sister1", 100);
                p.addChild(batchNode, 0);
                break;

            ///
            case 5:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 100);
                p.addChild(batchNode, 0);
                break;

            case 6:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 100);
                p.addChild(batchNode, 0);
                break;

            ///
            case 8:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/spritesheet1", 100);
                p.addChild(batchNode, 0);
                break;

            case 9:
                CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444);
                batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/spritesheet1", 100);
                p.addChild(batchNode, 0);
                break;

            default:
                break;
            }

            //if (batchNode != null)
            //{
            //    batchNode.retain();
            //}

            CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Default);
        }
Example #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);
        }