Exemple #1
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);
        }
Exemple #2
0
        public SceneStart()
        {
            base.init();
            #region SanguoCommander2
            //取得屏幕大小
            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_setting);
            //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);
            #endregion

            //测试动画的角色
            List <string> id_buff = new List <string>()
            {
                "B1", "B2", "B3", "B4", "Hero02", "A1", "A2", "A3", "A4", "Hero11"
            };
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    var actor = new ActorBase(new ActorData(id_buff[i * 5 + j]));
                    actor.ActorDir = (ActorDir)(i + 1);
                    actor.position = new CCPoint(64 + i * 64, 64 + j * 64);
                    //单数为站立动作,双数为攻击动作
                    if (j % 2 == 1)
                    {
                        actor.StateToRun();
                    }
                    else
                    {
                        actor.StateToAttack();
                    }
                    //添加角色
                    this.addChild(actor);
                }
            }
            //
        }
        public SceneGame()
        {
            base.init();
            //背景图
            //CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_game.png");
            //background.anchorPoint = new CCPoint(0, 0);
            //this.addChild(background);
            //地图
            CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/Level0");
            //map.removeChild(map.layerNamed("units"),false);
            //取得宽高
            CCSize size = CCDirector.sharedDirector().getWinSize();

            //保证地图是居中地图显示
            map.position = new CCPoint((size.width - map.contentSize.width) / 2, (size.height - map.contentSize.height) / 2);
            this.addChild(map);
            //返回按钮
            CCMenuItemSprite btn_attack = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_soldierattack1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_soldierattack2.png"),
                this, click_attack);
            CCMenu menu = CCMenu.menuWithItems(btn_attack);

            menu.position = new CCPoint(732, 36);
            this.addChild(menu);
        }
Exemple #4
0
        public SceneStart()
        {
            base.init();
            //取得屏幕大小
            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_setting);
            //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);
        }
Exemple #5
0
        public LayerLevels()
        {
            //关卡选择层
            CCPoint offset = new CCPoint(170, 180);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //关卡的按钮
                    CCMenuItemSprite level = CCMenuItemSprite.itemFromNormalSprite(
                        CCSprite.spriteWithSpriteFrameName("btn_level1.png"),
                        CCSprite.spriteWithSpriteFrameName("btn_level2.png"),
                        this, click_level);
                    CCMenu menu = CCMenu.menuWithItems(level);
                    //位置相对于左上的UI界面
                    menu.position = CCDirector.sharedDirector().convertToUI(new CCPoint(offset.x + 160 * i, offset.y + 85 * j));
                    this.addChild(menu);
                    //创建一个MenuItem,用作文本内容
                    CCMenuItem menuitem = new CCMenuItem();
                    //指定Arial的字体描述,保证fonts里有Arial.spritefont
                    var text = CCLabelTTF.labelWithString((j * 4 + i + 1).ToString(), "Arial", 12);
                    //将颜色指定为黑色
                    text.Color = new ccColor3B();
                    menuitem.addChild(text);
                    menu.addChild(menuitem);
                }
            }
        }
Exemple #6
0
        public SelectScene()
        {
            base.init();
            //取得屏幕大小
            CCSize size = CCDirector.sharedDirector().getWinSize();
            //背景图
            CCSprite background = CCSprite.spriteWithFile("background//select");

            background.position = new CCPoint(size.width / 2, size.height / 2);
            this.addChild(background);
            // 两个人物的选择
            CCMenuItemSprite button_uncle = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("selectM01.png"),
                CCSprite.spriteWithSpriteFrameName("selectM02.png"),
                this, click_start);
            //两个按钮
            CCMenuItemSprite button_kfc = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("selectK01.png"),
                CCSprite.spriteWithSpriteFrameName("selectK02.png"),
                this, click_start);
            //MenuItem需要通过CCMenu组合
            CCMenu menu = CCMenu.menuWithItems(button_uncle, button_kfc);

            //设置到界面中间偏下
            menu.alignItemsHorizontallyWithPadding(120);
            menu.position = new CCPoint(size.width / 2, size.height / 2 - 20);
            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 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));
        }
Exemple #9
0
        public SceneSelect()
        {
            base.init();
            //背景图
            CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_select.png");

            background.anchorPoint = new CCPoint(0, 0);
            this.addChild(background);
            //返回按钮
            CCMenuItemSprite btn_back = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_back1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_back2.png"),
                this, click_back);
            CCMenu menu = CCMenu.menuWithItems(btn_back);

            menu.position = new CCPoint(666, 32);
            this.addChild(menu);
            //上面的Tab按钮
            CCSprite tab1 = CCSprite.spriteWithSpriteFrameName("tab_shu1.png");
            CCSprite tab2 = CCSprite.spriteWithSpriteFrameName("tab_wu2.png");
            CCSprite tab3 = CCSprite.spriteWithSpriteFrameName("tab_wei2.png");

            tab1.position = new CCPoint(115, 430);
            tab2.position = new CCPoint(335, 430);
            tab3.position = new CCPoint(575, 430);
            this.addChild(tab1);
            this.addChild(tab2);
            this.addChild(tab3);

            CCPoint offset = new CCPoint(150, 150);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    CCMenuItemSprite level = CCMenuItemSprite.itemFromNormalSprite(
                        CCSprite.spriteWithSpriteFrameName("btn_level1.png"),
                        CCSprite.spriteWithSpriteFrameName("btn_level2.png"),
                        this, click_level);
                    menu          = CCMenu.menuWithItems(level);
                    menu.position = new CCPoint(offset.x + 160 * i, offset.y + 85 * j);
                    this.addChild(menu);
                }
            }
        }
        public SceneGame()
        {
            base.init();
            //±³¾°Í¼
            CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_game.png");

            background.anchorPoint = new CCPoint(0, 0);
            this.addChild(background);
            //·µ»Ø°´Å¥
            CCMenuItemSprite btn_attack = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_soldierattack1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_soldierattack2.png"),
                this, click_attack);
            CCMenu menu = CCMenu.menuWithItems(btn_attack);

            menu.position = new CCPoint(732, 36);
            this.addChild(menu);
        }
Exemple #11
0
        public SceneOver()
        {
            base.init();
            //±³¾°Í¼
            CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_over.png");

            background.anchorPoint = new CCPoint(0, 0);
            this.addChild(background);
            //ÎÄ×Ö
            CCSprite title = CCSprite.spriteWithSpriteFrameName("text_over.png");

            title.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width / 2, CCDirector.sharedDirector().getWinSize().height / 2 + 150);
            this.addChild(title);
            //·µ»Ø°´Å¥
            CCMenuItemSprite btn_back = CCMenuItemSprite.itemFromNormalSprite(
                CCSprite.spriteWithSpriteFrameName("btn_back1.png"),
                CCSprite.spriteWithSpriteFrameName("btn_back2.png"),
                this, click_back);
            CCMenu menu = CCMenu.menuWithItems(btn_back);

            menu.position = new CCPoint(666, 32);
            this.addChild(menu);
        }
Exemple #12
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

            // 员工
        }
        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 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)))));
        }
Exemple #15
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 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 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
            }
        }
        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 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);
        }
Exemple #21
0
        public RenderTextureZbuffer()
        {
            //this->setIsTouchEnabled(true);
            isTouchEnabled = true;
            CCSize     size  = CCDirector.sharedDirector().getWinSize();
            CCLabelTTF label = CCLabelTTF.labelWithString("vertexZ = 50", "Marker Felt", 64);

            label.position = new CCPoint(size.width / 2, size.height * 0.25f);
            this.addChild(label);

            CCLabelTTF label2 = CCLabelTTF.labelWithString("vertexZ = 0", "Marker Felt", 64);

            label2.position = new CCPoint(size.width / 2, size.height * 0.5f);
            this.addChild(label2);

            CCLabelTTF label3 = CCLabelTTF.labelWithString("vertexZ = -50", "Marker Felt", 64);

            label3.position = new CCPoint(size.width / 2, size.height * 0.75f);
            this.addChild(label3);

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

#warning "CCSpriteFrameCache is not exist! "
            //CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("Images/bugs/circle.plist");
            mgr = CCSpriteBatchNode.batchNodeWithFile("Images/bugs/circle.png", 9);
            this.addChild(mgr);
            sp1 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp2 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp3 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp4 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp5 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp6 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp7 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp8 = CCSprite.spriteWithSpriteFrameName("circle.png");
            sp9 = CCSprite.spriteWithSpriteFrameName("circle.png");

            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 = new ccColor3B {
                r = 255, g = 255, b = 0
            };
        }
        public SpriteChildrenChildren()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

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

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

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

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

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

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

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

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

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

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

            // child right top
            l3b2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b2.scale    = 0.45f;
            l3b2.IsFlipY  = true;
            l3b1.position = new CCPoint(0 + l2bSize.width / 2, +100 + l2bSize.height / 2);
            l2b.addChild(l3b2);
        }
 public SceneSelect()
 {
     base.init();
     #region SanguoCommander4
     //背景图
     CCSprite background = CCSprite.spriteWithSpriteFrameName("bg_select.png");
     background.anchorPoint = new CCPoint(0, 0);
     this.addChild(background);
     //返回按钮
     CCMenuItemSprite btn_back = CCMenuItemSprite.itemFromNormalSprite(
         CCSprite.spriteWithSpriteFrameName("btn_back1.png"),
         CCSprite.spriteWithSpriteFrameName("btn_back2.png"),
         this, click_back);
     CCMenu menu = CCMenu.menuWithItems(btn_back);
     menu.position = new CCPoint(666, 32);
     this.addChild(menu);
     //上面的Tab按钮创建
     CCMenuItemSprite tab1 = CCMenuItemSprite.itemFromNormalSprite(
         CCSprite.spriteWithSpriteFrameName("tab_shu2.png"),
         CCSprite.spriteWithSpriteFrameName("tab_shu1.png"),
         CCSprite.spriteWithSpriteFrameName("tab_shu1.png"),
         this, click_story_tab);
     CCMenuItemSprite tab2 = CCMenuItemSprite.itemFromNormalSprite(
         CCSprite.spriteWithSpriteFrameName("tab_wu2.png"),
         CCSprite.spriteWithSpriteFrameName("tab_wu1.png"),
         CCSprite.spriteWithSpriteFrameName("tab_wu1.png"),
         this, click_story_tab);
     CCMenuItemSprite tab3 = CCMenuItemSprite.itemFromNormalSprite(
         CCSprite.spriteWithSpriteFrameName("tab_wei2.png"),
         CCSprite.spriteWithSpriteFrameName("tab_wei1.png"),
         CCSprite.spriteWithSpriteFrameName("tab_wei1.png"),
         this, click_story_tab);
     story_tabs = CCMenu.menuWithItems(tab1, tab2, tab3);
     //按照水平方向10个像素间隔分割
     story_tabs.alignItemsHorizontallyWithPadding(10);
     //转换为界面UI的坐标
     story_tabs.position = CCDirector.sharedDirector().convertToUI(new CCPoint(300, 72));
     //将第一个设置为不可点击
     tab1.Enabled = false;
     this.addChild(story_tabs);
     //添加测试层
     //this.addChild(new LayerLevels());
     //将标签对应到不同的LyerLevers 类中
     dictLayerLevels.Add(tab1, new LayerLevels()
     {
         visible = false
     });
     dictLayerLevels.Add(tab2, new LayerLevels()
     {
         visible = false
     });
     dictLayerLevels.Add(tab3, new LayerLevels()
     {
         visible = false
     });
     //将tab1显示为当前的关卡层
     showLayerLevels(dictLayerLevels[tab1]);
     //遍历并添加到界面中
     foreach (var item in dictLayerLevels.Values)
     {
         this.addChild(item);
     }
     #endregion
 }
Exemple #24
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)));
        }
Exemple #25
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 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
            }
        }