示例#1
0
 /// <summary>
 /// 检测是否与Wolf对象碰撞
 /// </summary>
 /// <param name="wolf"></param>
 /// <returns>碰撞返回true,否则返回false</returns>
 public bool collideWithWolf(Wolf wolf)
 {
     CCRect wolfRect = wolf.rect();
     if(CCRect.CCRectIntersetsRect(wolfRect,rect()))//通过Rect是否相交判断是否碰撞
     {
         return true;
     }
     return false;
 }
        Wolf wolf; //主角

        #endregion Fields

        #region Constructors

        public GameLayer()
        {
            base.isTouchEnabled = true;//开启触屏事件
            CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.kCCDeviceOrientationPortraitUpsideDown;//设置朝向,竖屏

            //得分
            score = 0;
            lblScore = CCLabelTTF.labelWithString(string.Format("得分:{0}",score), "Yahei", 30);
            lblScore.position = new CCPoint(100, 100);
            this.addChild(lblScore);

            wolf = new Wolf();
            wolf.runing(this);//Sprite跑动动画

            this.schedule(CreateGoldOrBomb, 3.0f);//每隔3.0秒调用函数,类似线程
            this.schedule(collide);//默认下1.0/60s执行
        }