Пример #1
0
        public SpriteFrameTest()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // 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.plist");
            cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");
            cache.AddSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue");

            //
            // Animation using Sprite BatchNode
            //
            m_pSprite1          = new CCSprite("grossini_dance_01.png");
            m_pSprite1.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));

            CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");

            spritebatch.AddChild(m_pSprite1);
            AddChild(spritebatch);

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

            string str = "";

            for (int i = 1; i < 15; i++)
            {
                str = string.Format("grossini_dance_{0:00}.png", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.3f);

            m_pSprite1.RunAction(new CCRepeatForever(new CCAnimate(animation)));

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

            //
            // Animation using standard Sprite
            //
            m_pSprite2          = new CCSprite("grossini_dance_01.png");
            m_pSprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2));
            AddChild(m_pSprite2);


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

            for (int i = 1; i < 15; i++)
            {
                string temp;
                str = string.Format("grossini_dance_gray_{0:00}.png", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                moreFrames.Add(frame);
            }


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

            // append frames from another batch
            moreFrames.AddRange(animFrames);
            CCAnimation animMixed = new CCAnimation(moreFrames, 0.3f);


            m_pSprite2.RunAction(new CCRepeatForever(new CCAnimate(animMixed)));



            // to test issue #732, uncomment the following line
            m_pSprite2.FlipX = false;
            m_pSprite2.FlipY = false;

            Schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
Пример #2
0
        public CCSprite createSpriteWithTag(int tag)
        {
            // create

            CCSprite sprite = null;

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

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

            case 4:
            {
                var    idx = CCRandom.Next(1, 14);
                string str = string.Format("Images/grossini_dance_{0:00}", idx);
                sprite = new CCSprite(str);
                parent.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 5:
            case 6:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 1400 / 100);

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

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

            case 7:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 1400 / 100);

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

                string str = string.Format("Images/sprites_test/sprite-{0}-{1}", x, y);
                sprite = new CCSprite(str);
                parent.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 8:
            case 9:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 6400 / 100);

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

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

            default:
                break;
            }

            return(sprite);
        }
Пример #3
0
        public void createGameScreen()
        {
            CCSprite bg = new CCSprite("bg.png");

            bg.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.5f);
            AddChild(bg, kBackground);

            _lineContainer = LineContainer.Create();
            AddChild(_lineContainer);


            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("sprite_sheet.plist");
            _gameBatchNode = new CCSpriteBatchNode("sprite_sheet.png", 100);

            AddChild(_gameBatchNode, kForeground);

            _rocket          = Rocket.Create();
            _rocket.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.1f);
            _gameBatchNode.AddChild(_rocket, kForeground, kSpriteRocket);

            //add planets
            GameSprite planet;

            _planets = new List <GameSprite>();
            // _planets->retain();

            planet          = new GameSprite("planet_1.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.25f,
                                          _screenSize.Height * 0.8f);

            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_2.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.8f,
                                          _screenSize.Height * 0.45f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_3.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.75f,
                                          _screenSize.Height * 0.8f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_4.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.5f,
                                          _screenSize.Height * 0.5f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_5.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.18f,
                                          _screenSize.Height * 0.45f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_6.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.8f,
                                          _screenSize.Height * 0.15f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            planet          = new GameSprite("planet_7.png");
            planet.Position = new CCPoint(_screenSize.Width * 0.18f,
                                          _screenSize.Height * 0.1f);
            _gameBatchNode.AddChild(planet, kBackground, kSpritePlanet);
            _planets.Add(planet);

            CCSprite scoreLabel = new GameSprite("label_score.png");

            scoreLabel.Position = new CCPoint(_screenSize.Width * 0.4f, _screenSize.Height * 0.95f);
            _gameBatchNode.AddChild(scoreLabel, kBackground);

            _scoreDisplay = new CCLabelTtf("0", "MarkerFelt", 22);

            _scoreDisplay.AnchorPoint = new CCPoint(0, 0.5f);
            _scoreDisplay.Position    = new CCPoint(_screenSize.Width * 0.48f, _screenSize.Height * 0.95f);
            AddChild(_scoreDisplay, kBackground);

            _pauseBtn          = new GameSprite("btn_pause_off.png");
            _pauseBtn.Visible  = false;
            _pauseBtn.Position = new CCPoint(_screenSize.Width * 0.06f, _screenSize.Height * 0.95f);
            _gameBatchNode.AddChild(_pauseBtn, kBackground);


            _intro          = new GameSprite("logo.png");
            _intro.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.55f);
            CCSprite play = new CCSprite("label_play.png");

            play.Position = new CCPoint(_intro.BoundingBox.Size.Width * 0.5f, -_intro.BoundingBox.Size.Height * 0.5f);
            _intro.AddChild(play);
            _gameBatchNode.AddChild(_intro, kForeground);

            _gameOver          = new GameSprite("gameOver.png");
            _gameOver.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.55f);
            _gameOver.Visible  = false;
            _gameBatchNode.AddChild(_gameOver, kForeground);

            _paused          = new GameSprite("label_paused.png");
            _paused.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.55f);
            _paused.Visible  = false;
            _gameBatchNode.AddChild(_paused, kForeground);
        }
        public SpriteBatchNodeOffsetAnchorScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("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 spritesheet = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritesheet);

                var    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).ToString();
                    }
                    str = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.SpriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever(new CCAnimate(animation)));

                CCActionInterval scale      = new CCScaleBy(2, 2);
                CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
                CCActionInterval seq_scale  = (CCActionInterval)(CCSequence.FromActions(scale, scale_back));
                sprite.RunAction(new CCRepeatForever(seq_scale));

                spritesheet.AddChild(sprite, i);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }
        public SpriteBatchNodeOffsetAnchorSkewScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = new CCPoint(s.Width / 4 * (i + 1), s.Height / 2);

                CCSprite point = new CCSprite("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 = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritebatch);

                var    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 = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever(new CCAnimate(animation)));

                animFrames = null;

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

                CCFiniteTimeAction seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back);
                sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew));

                // scale
                CCScaleBy          scale      = new CCScaleBy(2, 2);
                CCActionInterval   scale_back = (CCActionInterval)scale.Reverse();
                CCFiniteTimeAction seq_scale  = new CCSequence(scale, scale_back);
                sprite.RunAction(new CCRepeatForever((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 = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1);

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

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

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


            CCSize s = CCDirector.SharedDirector.WinSize;

            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      = new CCFadeIn(2);
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCAction         fade        = new CCRepeatForever((CCActionInterval)(CCSequence.FromActions(action, action_back)));

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

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

            CCActionInterval tintblue      = new CCTintBy(2, -255, -255, 0);
            CCActionInterval tintblue_back = (CCActionInterval)tintblue.Reverse();
            CCAction         blue          = new CCRepeatForever((CCActionInterval)(CCSequence.FromActions(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);
        }
Пример #7
0
        public SpriteBatchNodeChildrenZ()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // parents
            CCSpriteBatchNode batch;
            CCSprite          sprite1, sprite2, sprite3;


            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");

            // test 1
            batch = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2));

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

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

            batch.AddChild(sprite1);
            sprite1.AddChild(sprite2, 2);
            sprite1.AddChild(sprite3, -2);

            // test 2
            batch = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(2 * s.Width / 3, s.Height / 2));

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

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

            batch.AddChild(sprite1);
            sprite1.AddChild(sprite2, -2);
            sprite1.AddChild(sprite3, 2);

            // test 3
            batch = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(s.Width / 2 - 90, s.Height / 4));

            sprite2          = new CCSprite("grossini_dance_02.png");
            sprite2.Position = (new CCPoint(s.Width / 2 - 60, s.Height / 4));

            sprite3          = new CCSprite("grossini_dance_03.png");
            sprite3.Position = (new CCPoint(s.Width / 2 - 30, s.Height / 4));

            batch.AddChild(sprite1, 10);
            batch.AddChild(sprite2, -10);
            batch.AddChild(sprite3, -5);

            // test 4
            batch = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(s.Width / 2 + 30, s.Height / 4));

            sprite2          = new CCSprite("grossini_dance_02.png");
            sprite2.Position = (new CCPoint(s.Width / 2 + 60, s.Height / 4));

            sprite3          = new CCSprite("grossini_dance_03.png");
            sprite3.Position = (new CCPoint(s.Width / 2 + 90, s.Height / 4));

            batch.AddChild(sprite1, -10);
            batch.AddChild(sprite2, -5);
            batch.AddChild(sprite3, -2);
        }
Пример #8
0
        public SpriteBatchNodeChildrenAnchorPoint()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");

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

            //
            // SpriteBatchNode
            //
            // parents

            aParent = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(aParent, 0);

            // anchor (0,0)
            sprite1             = new CCSprite("grossini_dance_08.png");
            sprite1.Position    = (new CCPoint(s.Width / 4, s.Height / 2));
            sprite1.AnchorPoint = (new CCPoint(0, 0));

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

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

            sprite4          = new CCSprite("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          = new CCSprite("Images/r1");
            point.Scale    = 0.25f;
            point.Position = sprite1.Position;
            AddChild(point, 10);


            // anchor (0.5, 0.5)
            sprite1             = new CCSprite("grossini_dance_08.png");
            sprite1.Position    = (new CCPoint(s.Width / 2, s.Height / 2));
            sprite1.AnchorPoint = (new CCPoint(0.5f, 0.5f));

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

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

            sprite4          = new CCSprite("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          = new CCSprite("Images/r1");
            point.Scale    = 0.25f;
            point.Position = sprite1.Position;
            AddChild(point, 10);


            // anchor (1,1)
            sprite1             = new CCSprite("grossini_dance_08.png");
            sprite1.Position    = (new CCPoint(s.Width / 2 + s.Width / 4, s.Height / 2));
            sprite1.AnchorPoint = (new CCPoint(1, 1));

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

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

            sprite4          = new CCSprite("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          = new CCSprite("Images/r1");
            point.Scale    = 0.25f;
            point.Position = sprite1.Position;
            AddChild(point, 10);
        }
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // parents
            CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50);

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

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");

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

            sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2));

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

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

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

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

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

            // BEGIN NEW CODE
            var    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 = new CCAnimation(animFrames, 0.2f);

            sprite1.RunAction(new CCRepeatForever(new CCAnimate(animation)));
            // END NEW CODE

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

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

            sprite2.RunAction(new CCRepeatForever(seq2));

            sprite1.RunAction((CCAction)(new CCRepeatForever(action_rot)));
            sprite1.RunAction((CCAction)(new CCRepeatForever((CCActionInterval)(new CCSequence(action, action_back)))));
            sprite1.RunAction((CCAction)(new CCRepeatForever((CCActionInterval)(new CCSequence(action_s, action_s_back)))));
        }
Пример #10
0
        private void createGameScreen()
        {
            //add bg
            CCSprite bg = new CCSprite("bg");

            bg.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.5f);
            AddChild(bg);

            //create spritebatch node
            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("sprite_sheet.plist");

            _gameBatchNode = new CCSpriteBatchNode("sprite_sheet.png");

            //ProcessSprite(_gameBatchNode);
            //_gameBatchNode.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            AddChild(_gameBatchNode);

            //create cityscape
            CCSprite sprite;

            for (int i = 0; i < 2; i++)
            {
                sprite = new CCSprite("city_dark.png");                 //new CCSprite("city_dark.png");
                //sprite.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                ProcessSprite(sprite);

                sprite.Position = new CCPoint(_screenSize.Width * (0.25f + i * 0.5f),
                                              sprite.BoundingBox.Size.Height * 0.5f);

                _gameBatchNode.AddChild(sprite, kForeground);

                sprite = new CCSprite("city_light.png");                // new CCSprite("city_light.png");
                //sprite.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                ProcessSprite(sprite);

                sprite.Position = new CCPoint(_screenSize.Width * (0.25f + i * 0.5f),
                                              sprite.BoundingBox.Size.Height * 0.9f);

                _gameBatchNode.AddChild(sprite, kBackground);
            }

            //add trees
            for (int i = 0; i < 3; i++)
            {
                sprite = new CCSprite("trees.png");                // new CCSprite("trees.png");

                //sprite.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                ProcessSprite(sprite);

                sprite.Position = new CCPoint(_screenSize.Width * (0.2f + i * 0.3f),
                                              sprite.BoundingBox.Size.Height * 0.5f);

                _gameBatchNode.AddChild(sprite, kForeground);
            }

            //add HUD
            _scoreDisplay             = new CCLabelTtf("0", "MarkerFelt", 22);
            _scoreDisplay.AnchorPoint = new CCPoint(1f, 0.5f);
            _scoreDisplay.Position    = new CCPoint(_screenSize.Width * 0.8f, _screenSize.Height * 0.94f);
            AddChild(_scoreDisplay);

            _energyDisplay          = new CCLabelTtf("100%", "MarkerFelt", 22);
            _energyDisplay.Position = new CCPoint(_screenSize.Width * 0.3f, _screenSize.Height * 0.94f);
            AddChild(_energyDisplay);

            CCSprite icon = new CCSprite("health_icon.png");             // new CCSprite("health_icon.png");

            icon.Position = new CCPoint(_screenSize.Width * 0.15f, _screenSize.Height * 0.94f);

            //icon.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(icon);

            _gameBatchNode.AddChild(icon, kBackground);

            //add clouds
            CCSprite cloud;

            _clouds = new List <CCSprite>(4);
            //_clouds

            float cloud_y;

            for (int i = 0; i < 4; i++)
            {
                cloud_y = i % 2 == 0 ? _screenSize.Height * 0.4f : _screenSize.Height * 0.5f;
                cloud   = new CCSprite(CCSpriteFrameCache.SharedSpriteFrameCache["cloud.png"]);               // new CCSprite("cloud.png");
                ProcessSprite(cloud);
                //cloud.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                cloud.Position = new CCPoint(_screenSize.Width * 0.1f + i * _screenSize.Width * 0.3f, cloud_y);
                _gameBatchNode.AddChild(cloud, kBackground);
                _clouds.Add(cloud);
            }

            //CREATE BOMB SPRITE
            _bomb = new CCSprite("bomb.png");
            //_bomb.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(_bomb);
            //_bomb.Texture.GenerateMipmap();
            _bomb.Visible = false;

            CCSize size = _bomb.BoundingBox.Size;

            //add sparkle inside bomb sprite
            CCSprite sparkle = new CCSprite("sparkle.png");

            //sparkle.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(sparkle);
            sparkle.Position = new CCPoint(size.Width * 0.72f, size.Height * 0.72f);
            _bomb.AddChild(sparkle, kMiddleground, kSpriteSparkle);


            //add halo inside bomb sprite
            CCSprite halo = new CCSprite("halo.png");

            //halo.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(halo);
            halo.Position = new CCPoint(size.Width * 0.4f, size.Height * 0.4f);
            _bomb.AddChild(halo, kMiddleground, kSpriteHalo);
            _gameBatchNode.AddChild(_bomb, kForeground);

            //add shockwave
            _shockWave = new CCSprite("shockwave.png");
            //_shockWave.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(_shockWave);

            _shockWave.Visible = false;
            _gameBatchNode.AddChild(_shockWave);

            //intro message
            _introMessage = new CCSprite("logo.png");
            //_introMessage.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(_introMessage);
            _introMessage.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.6f);
            _introMessage.Visible  = true;
            AddChild(_introMessage, kForeground);

            //game over message
            _gameOverMessage          = new CCSprite("gameover.png");
            _gameOverMessage.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.65f);

            //_gameOverMessage.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
            ProcessSprite(_gameOverMessage);
            _gameOverMessage.Visible = false;
            AddChild(_gameOverMessage, kForeground);
        }
Пример #11
0
        /// <summary>
        /// Constructs a new level.
        /// </summary>
        /// <param name="anindiegame"></param>
        public Level(StartGameScene startGameScene)
        {
            StartGameScene = startGameScene;
            // Load background layer textures. For now, all levels must
            // use the same backgrounds and only use the left-most part of them.
            AppDelegate.GameSpriteBatchNode.RemoveAllChildren();

            PlayerCharacterSheet = AppDelegate.GameSpriteBatchNode;

            layers    = new CCSprite[12];
            layers[0] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[1] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[2] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[3] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1114, 1536, 277));
            layers[4] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1114, 1536, 277));

            layers[5]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[6]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[7]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[8]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1400, 894, 400));
            layers[9]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1400, 894, 400));
            layers[9].FlipX  = true;
            layers[10]       = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(920, 1400, 901, 480));
            layers[11]       = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(920, 1400, 901, 480));
            layers[11].FlipX = true;

            frontLayers    = new CCSprite[3];
            frontLayers[0] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1802, 755, 96));
            frontLayers[1] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(800, 1900, 755, 96));
            frontLayers[2] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1900, 755, 96));

            _layer1Vector = new CCPoint(0, (AppDelegate.GameHeight / 2) + 70);
            _layer2Vector = new CCPoint(layers[3].BoundingBox.Size.Width / 2, (AppDelegate.GameHeight / 2));
            _layer3Vector = new CCPoint(0, (AppDelegate.GameHeight / 2) - 100);

            _ilayer1Vector = new CCPoint(layers[0].BoundingBox.Size.Width, (AppDelegate.GameHeight / 2) + 70);
            _ilayer2Vector = new CCPoint(layers[3].BoundingBox.Size.Width * 1.5f, AppDelegate.GameHeight / 2);
            _ilayer3Vector = new CCPoint(layers[5].BoundingBox.Size.Width, (AppDelegate.GameHeight / 2) - 100);

            _jlayer1Vector = new CCPoint(layers[0].BoundingBox.Size.Width * 2, (AppDelegate.GameHeight / 2) + 70);
            _jlayer3Vector = new CCPoint(layers[5].BoundingBox.Size.Width * 2, (AppDelegate.GameHeight / 2) - 100);

            _frontLayer1Vector = new CCPoint(0, frontLayers[0].BoundingBox.Size.Height / 2);
            _frontLayer2Vector = new CCPoint(frontLayers[0].BoundingBox.Size.Width, frontLayers[1].BoundingBox.Size.Height / 2);
            _frontLayer3Vector = new CCPoint((frontLayers[0].BoundingBox.Size.Width * 2), frontLayers[2].BoundingBox.Size.Height / 2);


            var playerSpawnPoint = new CCPoint((AppDelegate.GameWidth / 3), 100);

            Ball = new Ball(this, new CCPoint(AppDelegate.GameWidth / 2, AppDelegate.GameHeight + 200));

            Credits   = new List <CreditText>(5);
            Platforms = new List <Platform>(3);
            Walls     = new List <Wall>(2);
            Questions = new List <Question>(7);

            Platforms.Add(new Platform("sprites/platform_big.png", PlatformTypes.Large, new CCPoint(0, -80)));
            Platforms.Add(new Platform("sprites/platform_big.png", PlatformTypes.Large, new CCPoint(AppDelegate.GameWidth, -80)));
            TrapDoor = new Platform("sprites/platform.png", PlatformTypes.YouWin, new CCPoint(AppDelegate.GameWidth / 2, 10));
            Platforms.Add(this.TrapDoor);

            Walls.Add(new Wall("sprites/wall.png", new CCPoint(0, AppDelegate.GameHeight / 2)));
            Walls.Add(new Wall("sprites/wall.png", new CCPoint(AppDelegate.GameWidth, AppDelegate.GameHeight / 2)));

            Questions.Add(new Question("Wait... what is he doing?", new CCPoint(AppDelegate.GameWidth / 2, -200)));
            Questions.Add(new Question("Where is he going?", new CCPoint(AppDelegate.GameWidth / 2, -700)));
            Questions.Add(new Question("The game is over; why is he trying to leave?", new CCPoint(AppDelegate.GameWidth / 2, -1200)));
            Questions.Add(new Question("Is he starting another journey?", new CCPoint(AppDelegate.GameWidth / 2, -1700)));
            Questions.Add(new Question("What do we do now?", new CCPoint(AppDelegate.GameWidth / 2, -2200)));
            Questions.Add(new Question("We can't allow that.", new CCPoint(AppDelegate.GameWidth / 2, -2700)));
            Questions.Add(new Question("Stop him!", new CCPoint(AppDelegate.GameWidth / 2, -3200), 200));

            //setup classic segment platforms
            for (int i = 0; i < TopPlatforms.Capacity; i++)
            {
                var newPlatform = new Platform(this, PlatformTypes.Top);
                if (i > 40)
                {
                    newPlatform.isAlive = false;
                }
                else
                {
                    newPlatform.StopAllActions();
                    newPlatform.Rotation = 0;
                    newPlatform.Position = new CCPoint(((newPlatform.BoundingBox.Size.Width) * (i)) + (newPlatform.BoundingBox.Size.Width / 2), (newPlatform.BoundingBox.Size.Height / 2) + newPlatform.BoundingBox.Size.Height);
                    //if(i != 24)
                    //    newPlatform.reachedSpawnPoint = true;
                }
                TopPlatforms.Add(newPlatform);
            }

            for (int i = 0; i < MidPlatforms.Capacity; i++)
            {
                var newPlatform = new Platform(this, PlatformTypes.Middle);
                MidPlatforms.Add(newPlatform);
                if (i > 40)
                {
                    newPlatform.isAlive = false;
                }
                else
                {
                    newPlatform.StopAllActions();
                    newPlatform.Rotation = 0;
                    newPlatform.Position = new CCPoint(((newPlatform.BoundingBox.Size.Width) * (i)) + (newPlatform.BoundingBox.Size.Width / 2), (newPlatform.BoundingBox.Size.Height / 2));
                }
            }

            for (int i = 0; i < Spikes.Capacity; i++)
            {
                var spike = new Spike(this)
                {
                    isAlive = false
                };
                Spikes.Add(spike);
            }

            for (int i = 0; i < AttackCreditTexts.Capacity; i++)
            {
                var credit = new CreditText(this, new CCPoint(100, AppDelegate.GameWidth + 200), CreditTypes.AttackingFirstLast);
                credit.CreditNames.ForEach(name => name.Color = CCColor3B.Red);
                AttackCreditTexts.Add(credit);
            }

            InitClouds();

            //add elements to screen
            layers[0].Position = _layer1Vector;
            layers[1].Position = _ilayer1Vector;
            layers[2].Position = _jlayer1Vector;

            layers[0].Color = SkyColor;
            layers[1].Color = SkyColor;
            layers[2].Color = SkyColor;


            PlayerCharacterSheet.AddChild(layers[0], 0);
            PlayerCharacterSheet.AddChild(layers[1], 0);
            PlayerCharacterSheet.AddChild(layers[2], 0);

            layers[3].Position = _layer2Vector + new CCPoint(0, -123);
            layers[4].Position = _ilayer2Vector + new CCPoint(0, -123);

            PlayerCharacterSheet.AddChild(layers[3], 2);
            PlayerCharacterSheet.AddChild(layers[4], 2);

            PlayerCharacterSheet.AddChild(layers[8], 2);
            PlayerCharacterSheet.AddChild(layers[9], 2);
            PlayerCharacterSheet.AddChild(layers[10], 2);
            PlayerCharacterSheet.AddChild(layers[11], 2);

            foreach (var cloud in Clouds)
            {
                PlayerCharacterSheet.AddChild(cloud, 3);
                if (!cloud.IsAlive)
                {
                    cloud.Visible = false;
                }
            }

            layers[5].Position = _layer3Vector;
            layers[6].Position = _ilayer3Vector;
            layers[7].Position = _jlayer3Vector;

            PlayerCharacterSheet.AddChild(layers[5], 4);
            PlayerCharacterSheet.AddChild(layers[6], 4);
            PlayerCharacterSheet.AddChild(layers[7], 4);

            Platforms.ForEach(platform => StartGameScene.AddChild(platform, 5));
            Walls.ForEach(wall => StartGameScene.AddChild(wall, 4));
            StartGameScene.AddChild(Ball, 4);
            Questions.ForEach(question => StartGameScene.AddChild(question, 4));

            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -200), CreditTypes.RollingFirstLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -400), CreditTypes.RollingFirstMiddleLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -600), CreditTypes.RollingFirstLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -800), CreditTypes.RollingFirstMiddleLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -1000), CreditTypes.RollingFirstLast));

            Ball.Reset(new CCPoint(AppDelegate.GameWidth / 2, AppDelegate.GameHeight + 200));

            foreach (var s in Spikes)
            {
                PlayerCharacterSheet.AddChild(s, 4);
                if (!s.isAlive)
                {
                    s.Visible = false;
                }
            }

            foreach (var p in TopPlatforms)
            {
                PlayerCharacterSheet.AddChild(p, 5);
                if (!p.isAlive)
                {
                    p.Visible = false;
                }
            }

            foreach (var p in MidPlatforms)
            {
                PlayerCharacterSheet.AddChild(p, 5);
                if (!p.isAlive)
                {
                    p.Visible = false;
                }
            }

            frontLayers[0].Position = _frontLayer1Vector;
            frontLayers[1].Position = _frontLayer2Vector;
            frontLayers[2].Position = _frontLayer3Vector;

            PlayerCharacterSheet.AddChild(frontLayers[0], 6);
            PlayerCharacterSheet.AddChild(frontLayers[1], 6);
            PlayerCharacterSheet.AddChild(frontLayers[2], 6);

            StartGameScene.AddChild(PlayerCharacterSheet);

            frontLayers[0].Visible = false;
            frontLayers[1].Visible = false;
            frontLayers[2].Visible = false;

            layers[0].Visible  = false;
            layers[1].Visible  = false;
            layers[2].Visible  = false;
            layers[3].Visible  = false;
            layers[4].Visible  = false;
            layers[5].Visible  = false;
            layers[6].Visible  = false;
            layers[7].Visible  = false;
            layers[8].Visible  = false;
            layers[9].Visible  = false;
            layers[10].Visible = false;
            layers[11].Visible = false;

            TopPlatforms.ForEach(tile => tile.Visible = false);
            MidPlatforms.ForEach(tile => tile.Visible = false);
        }
        public RenderTextureZbuffer()
        {
            //this->setIsTouchEnabled(true);
            TouchEnabled = true;
            CCSize     size  = CCDirector.SharedDirector.WinSize;
            CCLabelTTF label = new CCLabelTTF("vertexZ = 50", "Marker Felt", 32);

            label.Position = new CCPoint(size.Width / 2, size.Height * 0.25f);
            AddChild(label);

            CCLabelTTF label2 = new CCLabelTTF("vertexZ = 0", "Marker Felt", 32);

            label2.Position = new CCPoint(size.Width / 2, size.Height * 0.5f);
            AddChild(label2);

            CCLabelTTF label3 = new CCLabelTTF("vertexZ = -50", "Marker Felt", 32);

            label3.Position = new CCPoint(size.Width / 2, size.Height * 0.75f);
            AddChild(label3);

            label.VertexZ  = 50;
            label2.VertexZ = 0;
            label3.VertexZ = -50;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("Images/bugs/circle.plist");

            mgr = new CCSpriteBatchNode("Images/bugs/circle", 9);
            AddChild(mgr);

            sp1 = new CCSprite("Images/bugs/circle");
            sp2 = new CCSprite("Images/bugs/circle");
            sp3 = new CCSprite("Images/bugs/circle");
            sp4 = new CCSprite("Images/bugs/circle");
            sp5 = new CCSprite("Images/bugs/circle");
            sp6 = new CCSprite("Images/bugs/circle");
            sp7 = new CCSprite("Images/bugs/circle");
            sp8 = new CCSprite("Images/bugs/circle");
            sp9 = new CCSprite("Images/bugs/circle");

            mgr.AddChild(sp1, 9);
            mgr.AddChild(sp2, 8);
            mgr.AddChild(sp3, 7);
            mgr.AddChild(sp4, 6);
            mgr.AddChild(sp5, 5);
            mgr.AddChild(sp6, 4);
            mgr.AddChild(sp7, 3);
            mgr.AddChild(sp8, 2);
            mgr.AddChild(sp9, 1);

            sp1.VertexZ = 400;
            sp2.VertexZ = 300;
            sp3.VertexZ = 200;
            sp4.VertexZ = 100;
            sp5.VertexZ = 0;
            sp6.VertexZ = -100;
            sp7.VertexZ = -200;
            sp8.VertexZ = -300;
            sp9.VertexZ = -400;

            sp9.Scale = 2;
            sp9.Color = CCTypes.CCYellow;
        }
Пример #13
0
        public SpriteBatchNodeChildrenChildren()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist");

            CCSpriteBatchNode aParent;
            CCSprite          l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;
            CCActionInterval  rot = new CCRotateBy(10, 360);
            CCAction          seq = new CCRepeatForever(rot);

            CCActionInterval rot_back    = (CCActionInterval)rot.Reverse();
            CCAction         rot_back_fe = new CCRepeatForever(rot_back);

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

            aParent = new CCSpriteBatchNode("animations/ghosts");
            aParent.Texture.GenerateMipmap();
            AddChild(aParent);

            // parent
            l1          = new CCSprite("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          = new CCSprite("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          = new CCSprite("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          = new CCSprite("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          = new CCSprite("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          = new CCSprite("child1.gif");
            l3b1.Scale    = 0.45f;
            l3b1.FlipY    = true;
            l3b1.Position = new CCPoint(0 + l2bSize.Width / 2, -100 + l2bSize.Height / 2);
            l2b.AddChild(l3b1);

            // child right top
            l3b2          = new CCSprite("child1.gif");
            l3b2.Scale    = 0.45f;
            l3b2.FlipY    = true;
            l3b1.Position = new CCPoint(0 + l2bSize.Width / 2, +100 + l2bSize.Height / 2);
            l2b.AddChild(l3b2);
        }
        public SpriteBatchNodeChildrenScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini_family.plist");

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

            //
            // Children + Scale using Sprite
            // Test 1
            //
            aParent          = new CCNode();
            sprite1          = new CCSprite("grossinis_sister1.png");
            sprite1.Position = new CCPoint(s.Width / 4, s.Height / 4);
            sprite1.ScaleX   = -0.5f;
            sprite1.ScaleY   = 2.0f;
            sprite1.RunAction(seq);


            sprite2          = new CCSprite("grossinis_sister2.png");
            sprite2.Position = (new CCPoint(50, 0));

            AddChild(aParent);
            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2);


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

            aParent          = new CCSpriteBatchNode("animations/grossini_family");
            sprite1          = new CCSprite("grossinis_sister1.png");
            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          = new CCSprite("grossinis_sister2.png");
            sprite2.Position = (new CCPoint(50, 0));

            AddChild(aParent);
            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2);


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

            aParent          = new CCNode();
            sprite1          = new CCSprite("grossinis_sister1.png");
            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          = new CCSprite("grossinis_sister2.png");
            sprite2.Position = (new CCPoint(50, 0));

            AddChild(aParent);
            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2);

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

            aParent          = new CCSpriteBatchNode("animations/grossini_family");
            sprite1          = new CCSprite("grossinis_sister1.png");
            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          = new CCSprite("grossinis_sister2.png");
            sprite2.Position = (new CCPoint(50, 0));

            AddChild(aParent);
            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2);
        }
Пример #15
0
        public SpriteFrameTest()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;

            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            cache.AddSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue");

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

            string str = "";

            for (int i = 1; i < 15; i++)
            {
                str = string.Format("grossini_dance_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

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

            for (int i = 1; i < 15; i++)
            {
                string temp;
                str = string.Format("grossini_dance_gray_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                moreFrames.Add(frame);
            }


            for (int i = 1; i < 5; i++)
            {
                str = string.Format("grossini_blue_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                moreFrames.Add(frame);
            }

            // append frames from another batch
            moreFrames.AddRange(animFrames);

            animMixed = new CCAnimation(moreFrames, 0.3f);


            CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");

            AddChild(spritebatch);

            sprite1 = new CCSprite("grossini_dance_01.png");
            spritebatch.AddChild(sprite1);

            // to test issue #732, uncomment the following line
            sprite1.FlipX = false;
            sprite1.FlipY = false;

            // Animation using standard Sprite
            sprite2 = new CCSprite("grossini_dance_01.png");
            AddChild(sprite2);

            // to test issue #732, uncomment the following line
            sprite2.FlipX = false;
            sprite2.FlipY = false;
        }
Пример #16
0
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("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 = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritebatch);

                var    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 = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever(new CCAnimate(animation)));

                animFrames = null;

                CCFlipY            flip      = new CCFlipY(true);
                CCFlipY            flip_back = new CCFlipY(false);
                CCDelayTime        delay     = new CCDelayTime(1);
                CCFiniteTimeAction seq       = new CCSequence((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.Copy(null), (CCFiniteTimeAction)flip_back);
                sprite.RunAction(new CCRepeatForever((CCActionInterval)seq));

                spritebatch.AddChild(sprite, i);
            }
        }