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 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);
        }
        public CCSprite makeSpriteZ(int aZ)
        {
            CCSprite sprite = CCSprite.spriteWithBatchNode(batchNode, new CCRect(128, 0, 64, 64));

            batchNode.addChild(sprite, aZ + 1, 0);

            //children
            CCSprite spriteShadow = CCSprite.spriteWithBatchNode(batchNode, new CCRect(0, 0, 64, 64));

            spriteShadow.Opacity = 128;
            sprite.addChild(spriteShadow, aZ, 3);

            CCSprite spriteTop = CCSprite.spriteWithBatchNode(batchNode, new CCRect(64, 0, 64, 64));

            sprite.addChild(spriteTop, aZ + 2, 3);

            return(sprite);
        }
Example #4
0
        public CCSprite createSpriteWithTag(int tag)
        {
            Random random = new Random();

            // create
            CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888);

            CCSprite sprite = null;

            switch (subtestNumber)
            {
            case 1:
            {
                sprite = CCSprite.spriteWithFile("Images/grossinis_sister1");
                parent.addChild(sprite, 0, tag + 100);
                break;
            }

            case 2:
            case 3:
            {
                sprite = CCSprite.spriteWithBatchNode(batchNode, new CCRect(0, 0, 52, 139));
                batchNode.addChild(sprite, 0, tag + 100);
                break;
            }

            case 4:
            {
                int idx = (random.Next() * 1400 / 100) + 1;
                //char str[32] = {0};
                string str;
                //sprintf(str, "Images/grossini_dance_%02d.png", idx);
                str    = string.Format("Images/grossini_dance_{0:2d}.png", idx);
                sprite = CCSprite.spriteWithFile(str);
                parent.addChild(sprite, 0, tag + 100);
                break;
            }

            case 5:
            case 6:
            {
                int y, x;
                int r = (random.Next() * 1400 / 100);

                y = r / 5;
                x = r % 5;

                x     *= 85;
                y     *= 121;
                sprite = CCSprite.spriteWithBatchNode(batchNode, new CCRect(x, y, 85, 121));
                batchNode.addChild(sprite, 0, tag + 100);
                break;
            }

            case 7:
            {
                int y, x;
                int r = (random.Next() * 6400 / 100);

                y = r / 8;
                x = r % 8;

                //char str[40] = {0};
                string str;
                //sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y);
                str    = string.Format("Images/sprites_test/sprite-{0:D}-{1:D}.png", x, y);
                sprite = CCSprite.spriteWithFile(str);
                parent.addChild(sprite, 0, tag + 100);
                break;
            }

            case 8:
            case 9:
            {
                int y, x;
                int r = (random.Next() * 6400 / 100);

                y = r / 8;
                x = r % 8;

                x     *= 32;
                y     *= 32;
                sprite = CCSprite.spriteWithBatchNode(batchNode, new CCRect(x, y, 32, 32));
                batchNode.addChild(sprite, 0, tag + 100);
                break;
            }

            default:
                break;
            }

            CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Default);

            return(sprite);
        }