public static void InitializeResource()
 {
     RandomNumber = new Random((int)DateTime.Now.Ticks);
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI01", "images/GameUI01");
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI02", "images/GameUI02");
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("plist/ActorsPack1");
 }
示例#2
0
        public Starscene()
        {
            base.init();
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/allimage");
            //取得屏幕大小
            CCSize size = CCDirector.sharedDirector().getWinSize();
            //背景图
            CCSprite background = CCSprite.spriteWithFile("background//start");

            background.position = new CCPoint(size.width / 2, size.height / 2);

            this.addChild(background);
            //两个按钮
            CCMenuItemSprite btn_start = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("playbutton01.png"),
                CCSprite.spriteWithSpriteFrameName("playbutton03.png"),
                this, click_start);
            CCMenuItemSprite btn_back = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("quitbutton01.png"),
                CCSprite.spriteWithSpriteFrameName("quitbutton03.png"),
                this, click_people);
            //MenuItem需要通过CCMenu组合
            CCMenu menu_star = CCMenu.menuWithItems(btn_start);
            CCMenu menu_back = CCMenu.menuWithItems(btn_back);

            // 设置开始和结束按钮
            menu_star.position = new CCPoint(size.width / 4 * 3 - 60, 70);
            this.addChild(menu_star);
            menu_back.position = new CCPoint(size.width / 4 * 3 + 70, 150);
            this.addChild(menu_back);
        }
        public SceneStart()
        {
            base.init();
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI01", "images/GameUI01");
            //取得屏幕大小
            CCSize size = CCDirector.sharedDirector().getWinSize();
            //背景图
            CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_start.png");

            background.anchorPoint = new CCPoint(0, 0);
            this.addChild(background);
            //Logo图
            CCSprite logo = CCSprite.spriteWithSpriteFrameName("logo.png");

            //设置到界面中间偏上
            logo.position = new CCPoint(size.width / 2, size.height / 2 + 120);
            this.addChild(logo);
            //两个按钮
            CCMenuItemSprite btn_start = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_start1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_start2.png"),
                this, click_start);
            CCMenuItemSprite btn_setting = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_setting1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_setting2.png"),
                this, click_start);
            //MenuItem需要通过CCMenu组合
            CCMenu menu = CCMenu.menuWithItems(btn_start, btn_setting);

            //一个垂直间隔排列
            menu.alignItemsVerticallyWithPadding(10);
            //设置到界面中间偏下
            menu.position = new CCPoint(size.width / 2, size.height / 2 - 120);
            this.addChild(menu);
        }
        public SpriteBatchNodeReorderIssue767()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/ghosts", "animations/images/ghosts");
            CCNode   aParent;
            CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;

            //
            // SpriteBatchNode: 3 levels of children
            //
            aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts");
            addChild(aParent, 0, (int)kTagSprite.kTagSprite1);

            // parent
            l1          = CCSprite.spriteWithSpriteFrameName("father.gif");
            l1.position = (new CCPoint(s.width / 2, s.height / 2));
            aParent.addChild(l1, 0, (int)kTagSprite.kTagSprite2);
            CCSize l1Size = l1.contentSize;

            // child left
            l2a          = CCSprite.spriteWithSpriteFrameName("sister1.gif");
            l2a.position = (new CCPoint(-25 + l1Size.width / 2, 0 + l1Size.height / 2));
            l1.addChild(l2a, -1, (int)kTags.kTagSpriteLeft);
            CCSize l2aSize = l2a.contentSize;

            // child right
            l2b          = CCSprite.spriteWithSpriteFrameName("sister2.gif");
            l2b.position = new CCPoint(+25 + l1Size.width / 2, 0 + l1Size.height / 2);
            l1.addChild(l2b, 1, (int)kTags.kTagSpriteRight);
            CCSize l2bSize = l2a.contentSize;


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

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

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

            // child right top
            l3b2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b2.scale    = 0.65f;
            l3b2.position = (new CCPoint(0 + l2bSize.width / 2, +50 + l2bSize.height / 2));
            l2b.addChild(l3b2, 1);

            schedule(reorderSprites, 1);
        }
        public override void onExit()
        {
            base.onExit();
            CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();

            cache.removeSpriteFramesFromFile("animations/grossini");
            cache.removeSpriteFramesFromFile("animations/grossini_gray");
        }
示例#6
0
        public static MySprite1 spriteWithSpriteFrameName(string pszSpriteFrameName)
        {
            CCSpriteFrame pFrame    = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(pszSpriteFrameName);
            MySprite1     pobSprite = new MySprite1();

            pobSprite.initWithSpriteFrame(pFrame);

            return(pobSprite);
        }
        public void flipSprites(float dt)
        {
            counter++;

            bool fx = false;
            bool fy = false;
            int  i  = counter % 4;

            switch (i)
            {
            case 0:
                fx = false;
                fy = false;
                break;

            case 1:
                fx = true;
                fy = false;
                break;

            case 2:
                fx = false;
                fy = true;
                break;

            case 3:
                fx = true;
                fy = true;
                break;
            }
            sprite1.IsFlipX = (fx);
            sprite2.IsFlipX = (fx);
            sprite1.IsFlipY = (fy);
            sprite2.IsFlipY = (fy);
            string temp = "";

            if (++spriteFrameIndex > 14)
            {
                spriteFrameIndex = 1;
            }
            if (spriteFrameIndex < 10)
            {
                temp = "0" + spriteFrameIndex;
            }
            else
            {
                temp = spriteFrameIndex.ToString();
            }
            string str1 = "";
            string str2 = "";

            str1 = string.Format("grossini_dance_{0}.png", temp);
            str2 = string.Format("grossini_dance_generic_{0}.png", temp);
            sprite1.DisplayFrame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str1);
            sprite2.DisplayFrame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str2);
        }
        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));
        }
        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);
        }
示例#10
0
        public ActorBase(ActorData data)
        {
            ActorData = data;
            //创建攻击动画
            List <CCSpriteFrame> _attackFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _attackFrames_flip = new List <CCSpriteFrame>();

            for (int i = 0; i < 4; i++)
            {
                _attackFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _attackFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_attack      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_attackFrames, 0.1f));
            _action_attack_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_attackFrames_flip, 0.1f));
            //创建行走动画
            List <CCSpriteFrame> _runFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _runFrames_flip = new List <CCSpriteFrame>();

            for (int i = 4; i < 6; i++)
            {
                _runFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _runFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_run      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFrames, 0.1f));
            _action_run_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFrames_flip, 0.1f));
            //创建站立动画
            List <CCSpriteFrame> _standFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _standFrames_flip = new List <CCSpriteFrame>();

            for (int i = 6; i < 7; i++)
            {
                _standFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _standFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_stand      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_standFrames, 0.2f));
            _action_stand_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_standFrames_flip, 0.2f));
            //创建死亡动画
            List <CCSpriteFrame> _deadFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _deadFrames_flip = new List <CCSpriteFrame>();

            for (int i = 7; i < 9; i++)
            {
                _deadFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _deadFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_dead      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_deadFrames, 0.3f));
            _action_dead_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_deadFrames_flip, 0.3f));
            //初始化默认帧
            base.initWithSpriteFrame(_standFrames[0]);
        }
示例#11
0
        public SpriteSubclass()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

            addChild(sprite2);
            sprite2.position = (new CCPoint(s.width / 4 * 3, s.height / 2));
        }
示例#12
0
        public Uncle_sprite()
        {
            //uncledata = data;

            // 创建走的动画
            List <CCSpriteFrame> _runFream = new List <CCSpriteFrame>();

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/zhengyu");
            CCSpriteBatchNode sheet = CCSpriteBatchNode.batchNodeWithFile(@"plist/Images/zhengyu");

            this.addChild(sheet);
            for (int i = 1; i <= 4; i++)
            {
                _runFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("MM0{0}.png", i)));
            }
            _run = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFream, 0.12f));

            List <CCSpriteFrame> _actackFream = new List <CCSpriteFrame>();

            // 创建攻击时候动作
            for (int i = 1; i <= 5; i++)
            {
                _actackFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("Mthrow0{0}.png", i)));
            }
            _actack = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_actackFream, 0.3f));

            position = new CCPoint(100, 100);
            // 初始化开始帧
            base.initWithSpriteFrame(_runFream[0]);


            // 如果手机倾斜
            if (Accelerometer.IsSupported)
            {
                gSensor = new Accelerometer();
                gSensor.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(gSensor_CurrentValueChanged);
                gSensor.Start();
            }
        }
示例#13
0
        public override void onEnter()
        {
            base.onEnter();

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

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("zwoptex/grossini");
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("zwoptex/grossini-generic");

            CCLayerColor layer1 = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(255, 0, 0, 255), 85, 121);

            layer1.position = (new CCPoint(s.width / 2 - 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f)));
            addChild(layer1);

            sprite1          = CCSprite.spriteWithSpriteFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("grossini_dance_01.png"));
            sprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2));
            addChild(sprite1);

            sprite1.IsFlipX = (false);
            sprite1.IsFlipY = (false);

            CCLayerColor layer2 = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(255, 0, 0, 255), 85, 121);

            layer2.position = (new CCPoint(s.width / 2 + 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f)));
            addChild(layer2);

            sprite2          = CCSprite.spriteWithSpriteFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("grossini_dance_generic_01.png"));
            sprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2));
            addChild(sprite2);

            sprite2.IsFlipX = (false);
            sprite2.IsFlipY = (false);

            schedule((startIn05Secs), 1.0f);

            counter = 0;
        }
示例#14
0
        public Select_employee()
        {
            #region UI布置
            CCSize size = CCDirector.sharedDirector().getWinSize();
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/left_right");
            base.init();
            // 背景

            // 开始游戏按钮
            CCMenuItemImage star_button = CCMenuItemImage.itemFromNormalImage("UI/PK", "UI/PK1", this, click_star);
            CCMenu          starMenu    = CCMenu.menuWithItems(star_button);
            starMenu.position = new CCPoint(size.width - 60, size.height - 50);
            this.addChild(starMenu);

            // 返回按钮
            CCMenuItemImage back_button = CCMenuItemImage.itemFromNormalImage("CloseSelected", "CloseNormal", this, click_back);
            CCMenu          backMenu    = CCMenu.menuWithItems(back_button);
            backMenu.position = new CCPoint(size.width - 20, 40);
            this.addChild(backMenu);
            // 左右边移动键
            CCMenuItemSprite left_button = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("left_select.png"),
                CCSprite.spriteWithSpriteFrameName("left.png"),
                this, left);
            CCMenuItemSprite right_button = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("right_select.png"),
                CCSprite.spriteWithSpriteFrameName("right.png"),
                this, right);
            CCMenu select_menu = CCMenu.menuWithItems(left_button, right_button);
            select_menu.alignItemsHorizontallyWithPadding(440);
            select_menu.position = new CCPoint(size.width / 2, size.height / 4 * 3);
            this.addChild(select_menu);
            #endregion

            // 员工
        }
示例#15
0
 public static void InitializeResource()
 {
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI01", "images/GameUI01");
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI02", "images/GameUI02");
 }
示例#16
0
        public SpriteOffsetAnchorSkewScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

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

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

                point.position = sprite.position;

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

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

                animFrames = null;

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

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

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

                addChild(sprite, 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);
        }
        public SpriteBatchNodeChildrenZ()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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


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

            // test 1
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 3, s.height / 2));

            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));

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

            // test 2
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(2 * s.width / 3, s.height / 2));

            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));

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

            // test 3
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 2 - 90, s.height / 4));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(s.width / 2 - 60, s.height / 4));

            sprite3          = CCSprite.spriteWithSpriteFrameName("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 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 2 + 30, s.height / 4));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(s.width / 2 + 60, s.height / 4));

            sprite3          = CCSprite.spriteWithSpriteFrameName("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);
        }
        public SpriteBatchNodeOffsetAnchorRotation()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

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

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

                point.position = sprite.position;

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

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

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

                spritebatch.addChild(sprite, i);

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

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

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

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

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

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

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

            string str = "";

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

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

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

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

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


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

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


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

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


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



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

            schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

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

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

                point.position = sprite.position;

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

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

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

                animFrames = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction(action_rot)));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back)))));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back)))));
        }
示例#23
0
        public override void onEnter()
        {
            base.onEnter();
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();

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

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

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

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

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

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

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

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

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

            // 14 frames * 1sec = 14 seconds
            sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(14.0f, animation, false)));
        }
示例#24
0
        public AnimationCache()
        {
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_gray");
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_blue");

            //
            // create animation "dance"
            //
            List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15);
            string str = "";

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

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

            // Add an animation to the Cache
            CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance");

            //
            // create animation "dance gray"
            //
            animFrames.Clear();

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

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

            // Add an animation to the Cache
            CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_gray");

            //
            // create animation "dance blue"
            //
            animFrames.Clear();

            for (int i = 1; i < 4; i++)
            {
                str = String.Format("grossini_blue_0{0}.png", i);
                CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                animFrames.Add(frame);
            }

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

            // Add an animation to the Cache
            CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_blue");


            CCAnimationCache animCache = CCAnimationCache.sharedAnimationCache();

            CCAnimation normal     = animCache.animationByName("dance");
            CCAnimation dance_grey = animCache.animationByName("dance_gray");
            CCAnimation dance_blue = animCache.animationByName("dance_blue");

            CCAnimate animN = CCAnimate.actionWithAnimation(normal);
            CCAnimate animG = CCAnimate.actionWithAnimation(dance_grey);
            CCAnimate animB = CCAnimate.actionWithAnimation(dance_blue);

            CCFiniteTimeAction seq = CCSequence.actions(animN, animG, animB);

            // create an sprite without texture
            CCSprite grossini = new CCSprite();

            grossini.init();

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

            grossini.position = (new CCPoint(winSize.width / 2, winSize.height / 2));
            addChild(grossini);

            // run the animation
            grossini.runAction(seq);
        }
        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);
        }
        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);
        }
示例#27
0
 public static void InitializeResource()
 {
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/left_right");
 }
示例#28
0
        public SpriteBatchNodeChildren2()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            batch.Texture.generateMipmap();

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            sprite21.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(1, 360)));
            sprite21.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(CCScaleTo.actionWithDuration(0.5f, 5.0f), CCScaleTo.actionWithDuration(0.5f, 1)))));
        }
 public override void onExit()
 {
     base.onExit();
     CCSpriteFrameCache.sharedSpriteFrameCache().removeUnusedSpriteFrames();
 }
        public SpriteOffsetAnchorScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

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

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

                point.position = sprite.position;

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

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

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

                addChild(sprite, 0);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }