COCOS2d解决连发问题

 

设定连发开关,当点击时打开连击开关,手指抬起时关闭。

 private CGPoint storePoint = null;//保存的触摸点
 private Boolean running = false;  //连续开火

 

定时器随时检测(实际上游戏很多的schedule),当检测连发开关为ture,并且目标不为空时,发射。正常发射因抬起时已经置为flase,则不会连发。

    public void randomMove(float f) {//定时任务

        if (running&&storePoint!=null) {//未抬指,目标不为空,则连发
            startFire();
        }
  if (touchPoint.y > 100) {  //开炮
            running = true;//连发打开
            fishGun.setRotation(FishUtils.getRotation(fishGun.getPosition(), touchPoint) - 90);//渔枪转角度
            startFire();
        }

        return true;
    }

    @Override
    public boolean ccTouchesEnded(MotionEvent event) {
        running=false;  //连发停止
        return super.ccTouchesEnded(event);
    }

 

posted @ 2021-12-12 12:50  风肖肖(肖遥)  阅读(40)  评论(0编辑  收藏  举报