iOS 简易游戏操作控制盘设计

大家无论在玩王者荣耀,还是绝地求生等升级版的游戏时,都会遇到游戏操作控制盘。

基于此,个人开发了一个简易的操作盘,主要包括两个部分:操作控制台背景 和 中间操作圆球。

基于此,定义:consoleBGImageView,放置一张初始Image;定义中间操作圆球为:rotateButton

通过约束条件,来控制rotateButton只能在consoleBGImageView范围内转动

通过UIPanGestureRecognizer添加rotateButton拖动手势,当转动到不同的方向时,修改相应的背景图,这样可以知道转动到哪个方向。

通过如下代码,控制手指触碰的点限制在圆盘内部

-(void)rotateLocation:(CGPoint)pLocation {
    if([self IfYuntaiViewIsIntheBigView:pLocation]){
        self.rotateButton.center = CGPointMake(pLocation.x, pLocation.y);
        
        CGPoint tranPoint = CGPointMake(pLocation.x - centerViewX, pLocation.y - centerViewY);
        ELPCircleConsoleMoveDirection direction = [self determineCameraDirection:tranPoint];
        currentDirection = direction;
    } else {
        CGFloat radius = self.traceView.size.width * 0.5;
        CGPoint pointc = self.consoleBGImageView.center;
        CGPoint changePoint = [self CirclePoint:radius withCenterCircle:pointc withCurrentPoint:pLocation];
        
        self.rotateButton.center = CGPointMake(changePoint.x, changePoint.y);
        
        CGPoint tranPoint = CGPointMake(changePoint.x - centerViewX, changePoint.y - centerViewY);
        ELPCircleConsoleMoveDirection direction = [self determineCameraDirection:tranPoint];
        currentDirection = direction;
    }
    
    CGFloat xValue = fabs(self.rotateButton.centerX - centerViewX);
    CGFloat yValue = fabs(self.rotateButton.centerY - centerViewY);
    
    CGFloat currentRadiusValue = xValue * xValue + yValue * yValue;
    CGFloat bgImgRadiusWith = self.consoleBGImageView.width * 0.5 * 0.5;
    if(currentRadiusValue > bgImgRadiusWith * bgImgRadiusWith * 0.6) {
        [self sendRotateButtonRotateCmd];
    } else {
        [self resumBackgroundImgToNormal];
    }
}

详细代码详见如下链接,如果对你有帮助,麻烦star一个,谢谢。
https://github.com/ElsonPeng/ELPCircleConsoleView

效果图如下:


screenshot.png
Simulator Screen Shot - iPhone 8 Plus - 2018-03-04 at 22.43.55.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 爱需要伴随着觉知,因为爱本身所具有的盲目驱力,会让我们像是无意识一样地行动着。这种爱不但没有办法为我们带来深沉的满...
    悠导阅读 2,744评论 0 0
  • 摩能国际水灵珠加盟怎么样 摩能国际水灵珠加盟怎么样?微商行业从兴起到发展到如今的整个过程,有的人通过这一行业赚到了...
    5abf0b0e26ae阅读 3,582评论 0 0
  • 第三章 大器晚成梦不迟 力撑王家精神柱 隔墙都有耳,何况当村当疃的好事。王有财听说葛亮长了本事,美滋滋端坐在炕上巴...
    ZHOU春雨阅读 3,593评论 0 5
  • 第一次有男生在我面前哭,一句话都不说。 最开始我们认识的时候,坐在操场上聊天,那时候还是夏天,我们最后结束的时候,...
    西东宋阅读 2,967评论 0 1
  • 淅淅沥沥敲打着窗,今天的心情好吗? 泪水混杂着雨水顺着脸颊的轮廓留下 赶走了炎热带来了清凉 但是为什么心情还是如此...
    伪斜杠青年阅读 1,459评论 0 0

友情链接更多精彩内容