Пример #1
0
        public override bool init()
        {
            if (base.init())
            {
                CCSize s = CCDirector.sharedDirector().getWinSize();

                CCLayerColor background = CCLayerColor.layerWithColor(new ccColor4B(255, 0, 255, 255));
                addChild(background);

                CCLayerColor sprite_a = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(255, 0, 0, 255), 700, 700);
                sprite_a.anchorPoint           = new CCPoint(0.5f, 0.5f);
                sprite_a.isRelativeAnchorPoint = true;
                sprite_a.position = new CCPoint(0.0f, s.height / 2);
                addChild(sprite_a);

                sprite_a.runAction(CCRepeatForever.actionWithAction((CCActionInterval)CCSequence.actions(
                                                                        CCMoveTo.actionWithDuration(1.0f, new CCPoint(1024.0f, 384.0f)),
                                                                        CCMoveTo.actionWithDuration(1.0f, new CCPoint(0.0f, 384.0f)))));

                CCLayerColor sprite_b = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(0, 0, 255, 255), 400, 400);
                sprite_b.anchorPoint           = new CCPoint(0.5f, 0.5f);
                sprite_b.isRelativeAnchorPoint = true;
                sprite_b.position = new CCPoint(s.width / 2, s.height / 2);
                addChild(sprite_b);

                CCMenuItemLabel label = CCMenuItemLabel.itemWithLabel(CCLabelTTF.labelWithString("Flip Me", "Helvetica", 24), this, callBack);
                CCMenu          menu  = CCMenu.menuWithItems(label);
                menu.position = new CCPoint(s.width - 200.0f, 50.0f);
                addChild(menu);

                return(true);
            }

            return(false);
        }
Пример #2
0
        public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_)
        {
            //base.ccTouchesEnded(touches, event_);
            object  it    = touches.First();
            CCTouch touch = (CCTouch)(it);

            CCPoint location          = touch.locationInView(touch.view());
            CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location);

            CCNode s = getChildByTag(ClickAndMoveTest.kTagSprite);

            s.stopAllActions();
            s.runAction(CCMoveTo.actionWithDuration(1, new CCPoint(convertedLocation.x, convertedLocation.y)));
            float o  = convertedLocation.x - s.position.x;
            float a  = convertedLocation.y - s.position.y;
            float at = (float)(Math.Atan(o / a) * 57.29577951f);

            if (a < 0)
            {
                if (o < 0)
                {
                    at = 180 + Math.Abs(at);
                }
                else
                {
                    at = 180 - Math.Abs(at);
                }
            }

            s.runAction(CCRotateTo.actionWithDuration(1, at));
        }
        public TMXUncompressedTest()
        {
            CCLayerColor color = CCLayerColor.layerWithColor(new ccColor4B(64, 64, 64, 255));

            addChild(color, -1);

            CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test2-uncompressed");

            addChild(map, 0, TileMapTestScene.kTagTileMap);

            CCSize s = map.contentSize;
            ////----UXLOG("ContentSize: %f, %f", s.width,s.height);

            // move map to the center of the screen
            CCSize ms = map.MapSize;
            CCSize ts = map.TileSize;

            map.runAction(CCMoveTo.actionWithDuration(1.0f, new CCPoint(-ms.width * ts.width / 2, -ms.height * ts.height / 2)));

            // testing release map
            CCTMXLayer layer;

            foreach (var pObject in map.children)
            {
                layer = (CCTMXLayer)pObject;

                if (layer == null)
                {
                    break;
                }

                layer.releaseMap();
            }
        }
Пример #4
0
        public void Hide()
        {
            //指定移动到最左边并超出屏幕
            CCMoveTo move = CCMoveTo.actionWithDuration(0.5f, new CCPoint(-CCDirector.sharedDirector().getWinSize().width, 0));

            //执行一个队列行为,当移动完成后就会调用HideAniCompled
            this.runAction(CCSequence.actionOneTwo(move, CCCallFunc.actionWithTarget(this, HideAniCompled)));
        }
Пример #5
0
        public void Show()
        {
            //将其显示出来
            this.visible = true;
            //把位置设置到最右边出屏幕外
            this.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width, 0);
            //指定移动到0,0点
            CCMoveTo move = CCMoveTo.actionWithDuration(0.5f, new CCPoint(0, 0));

            //运行这个Action
            this.runAction(move);
        }
Пример #6
0
        void gSensor_CurrentValueChanged(object sender, SensorReadingEventArgs <AccelerometerReading> e)
        {
            CCPoint newPos  = new CCPoint(position.x, position.y);
            Vector3 vector3 = e.SensorReading.Acceleration;

            if (vector3.Y <= 0.2 && vector3.Y > 0)
            {
                //RunAnimateAction_RepeatForever(_run);
                runAction(CCMoveTo.actionWithDuration(1, new CCPoint(60, 100)));
            }
            else if (vector3.Y <= 0 && vector3.Y > -0.2)
            {
                runAction(CCMoveTo.actionWithDuration(1, new CCPoint(300, 100)));
                RunAnimateAction_RepeatForever(_run);
            }
        }
Пример #7
0
        public TMXIsoTest()
        {
            CCLayerColor color = CCLayerColor.layerWithColor(new ccColor4B(new Color(64, 64, 64, 255)));

            addChild(color, -1);

            CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test01");

            addChild(map, 0, 1);

            // move map to the center of the screen
            CCSize ms = map.MapSize;
            CCSize ts = map.TileSize;

            map.runAction(CCMoveTo.actionWithDuration(1.0f, new CCPoint(-ms.width * ts.width / 2, -ms.height * ts.height / 2)));
        }
Пример #8
0
        public override void onEnter()
        {
            base.onEnter();

            centerSprites(3);

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

            CCActionInterval actionTo = CCMoveTo.actionWithDuration(2, new CCPoint(s.width - 40, s.height - 40));
            CCActionInterval actionBy = CCMoveBy.actionWithDuration(2, new CCPoint(80, 80));

            // source code: CCActionInterval* actionByBack = actionBy->reverse();
            CCFiniteTimeAction actionByBack = actionBy.reverse();

            m_tamara.runAction(actionTo);
            m_grossini.runAction(CCSequence.actions(actionBy, actionByBack));
            m_kathia.runAction(CCMoveTo.actionWithDuration(1, new CCPoint(40, 40)));
        }
Пример #9
0
        public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_)
        {
            actor.actack();
            base.ccTouchesEnded(touches, event_);
            CCTouch touch    = touches.FirstOrDefault();
            CCPoint location = touch.locationInView(touch.view());

            location = CCDirector.sharedDirector().convertToGL(location);

            //set up initial location of projectile
            CCSize   winSize    = CCDirector.sharedDirector().getWinSize();
            CCSprite projectile = CCSprite.spriteWithFile(@"sprites/hamberger");

            projectile.position = new CCPoint(actor.position.x, actor.position.y + 20);

            this.addChild(projectile);

            float offX = location.x - projectile.position.x;
            float offY = location.y - projectile.position.y;

            offY -= 30;

            float realX = winSize.width + projectile.contentSize.width / 2;
            float ratio = offY / offX;
            float realY = realX * ratio + projectile.position.y;

            realY -= 30;
            CCPoint realDest = new CCPoint(realX, realY);

            //Determine the length of how far we're shooting
            float offRealX = realX - projectile.position.x;
            float offRealY = realY - projectile.position.y;

            offRealY -= 30;
            float length           = (float)Math.Sqrt(offRealX * offRealX + offRealY * offRealY);
            float velocity         = 480 / 1;//480pixls/lsec
            float realMoveDuration = length / velocity;

            //Move projectile to actual endpoint
            projectile.runAction(CCSequence.actions(CCMoveTo.actionWithDuration(realMoveDuration, realDest),
                                                    CCCallFuncN.actionWithTarget(this, spriteMoveFinished)));
        }