当场景处理其子节点的时候betway体育app,API文档

#pragma mark ---- 移动飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction *moveAction = [SKAction moveToY:0 duration:1]; //设置速度 moveAction.speed = 0.5; [planeNode runAction:moveAction]; SKSpriteNode *planeNode1 = (SKSpriteNode *)[self childNodeWithName:@"plane1"]; SKAction *moveAction1 = [SKAction moveToY:0 duration:1]; //设置速度 moveAction1.speed = 2; [planeNode1 runAction:moveAction1];}@end
移步动作

挪动动作在一个戏耍中是最分布的动作了.移动动作根本分为以点的方式活动和以偏移量的方式移动.且听自个儿慢慢道来.

里面以点的情势活动的基本点有八个SKAction类方法来创制.

+ (SKAction *)moveTo:location duration:(NSTimeInterval)sec;

location: 用来钦赐节点移动到的地点.sec:用来钦定移动动作所急需的时间.

+ (SKAction *)moveToX:x duration:(NSTimeInterval)sec;

x: 用来钦命节点的x轴上移步到的地方.节点的y轴上的值不改变化.sec:用来钦定移动动作所要求的时间.

+ (SKAction *)moveToY:y duration:(NSTimeInterval)sec;

y: 用来钦定节点的y轴上移动到的地方.节点的x轴上的值不改变化.sec:用来钦命移动动作所须要的时间.

以偏移量的款型活动首要有二种两种类方法.

+ (SKAction *)moveBy:delta duration:(NSTimeInterval)sec;

delta:是叁个矢量,用力啊钦点偏移量,类型为CGVector,CGVector是一个很简短的结构体,有dx和dy组成.dx表示x轴上的偏移量,dy代表y轴上的偏移量.结构体方式如下.

struct CGVector { CGFloat dx; CGFloat dy;};

sec:用来内定移动动作所急需的时间.

+ (SKAction *)moveByX:deltaX y:deltaY duration:(NSTimeInterval)sec;

deltaX:表示在x轴上的偏移量.deltaY:表示在y轴上的偏移量.sec:用来内定移动动作所急需的时间.

示例:

#pragma mark ---- 以点的形式移动飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint position = [touch locationInNode:self]; SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction * moveAction = [SKAction moveTo:position duration:1]; [planeNode runAction:moveAction]; } 

#pragma mark ---- 以偏移量的形式移动飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction * moveAction = [SKAction moveBy:CGVectorMake duration:1]; [planeNode runAction:moveAction]; }

地点的独家以点的款式和偏移量的款型做出了示范,大家看一下功用图.当我们每一趟点击荧屏的时候接触移动动作,下边大家就看一下二种方式的功力图有啥不一样.

betway体育app 1以点花样活动作效果果图betway体育app 2以偏移量格局活动作效果果图

17、块动作

动用runBlock()方法达成,异步调用动作的法子,可钦赐实行的线程。

func blockAction() {
        let ball = SKSpriteNode.init(imageNamed: "soccer")
        ball.position = CGPoint.init(x: KScreenWidth/2, y: KScreenHeight/2)
        ball.size = CGSize.init(width: 80, height: 80)
        self.addChild(ball)

        // 创建块动作
        let blockAction = SKAction.run { 
            let rotate = SKAction.rotate(byAngle: CGFloat(Double.pi*2), duration: 3)
            let runRepeat = SKAction.repeatForever(rotate)
            ball.run(runRepeat)
        }
        ball.run(blockAction)
    }

安装动作实施的线程:

SKAction.run({
}, queue: DispatchQueue)

+ (SKAction*)scaleXBy:(CGFloat)xScale y:(CGFloat)yScale duration:(NSTimeInterval)sec;

在Coca ColaKit中央银行使SKPhysicsBody类来创建物理体. 在七喜Kit中物理体分为3类,如下所示.

betway体育app 3

尺寸动作

尺寸动作正是用来修改节点的尺码的.其语法格局有以下三种,分别是以目的值调节尺寸,单独调度目的节点的惊人或许增幅,以增量的形式调解全体的尺寸.具体语法情势如下.

以目的值调解尺寸

+ (SKAction *)resizeToWidth:width height:height duration:(NSTimeInterval)duration;

单独调度目的节点的可观恐怕增长幅度的二种样式语法如下

//调整宽度+ (SKAction *)resizeToWidth:width duration:(NSTimeInterval)duration;//调整高度+ (SKAction *)resizeToHeight:height duration:(NSTimeInterval)duration;

以增量的样式调解全体的尺寸.

+ (SKAction *)resizeByWidth:width height:height duration:(NSTimeInterval)duration;

尺寸动作演示:

废话相当的少说,直接上代码.以以指标值调度尺寸为例.

#pragma mark ---- 改变尺寸飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction *sizeAction = [SKAction resizeToWidth:200 height:200 duration:0.5]; [planeNode runAction:sizeAction];}

效能图如下.

betway体育app 4

应用方法,创设Smart:
let KScreenWidth = UIScreen.main.bounds.width
let KScreenHeight = UIScreen.main.bounds.height
func addNode() {
        let texture = SKTexture.init(imageNamed: "ao.jpg")  // 纹理
        let splash = SKSpriteNode.init(texture: texture)
//        let splash = SKSpriteNode.init(imageNamed: "ao.jpg")
        splash.size = CGSize.init(width: KScreenWidth, height: KScreenHeight)
        splash.position = CGPoint.init(x: KScreenWidth/2, y: KScreenHeight/2)
        // 设置锚点
//        splash.anchorPoint = CGPoint.init(x: 0.0, y: 0.0)
        // 精灵着色
        splash.color = SKColor.green
        splash.colorBlendFactor = 0.3   // 颜色混合因子0~1
        splash.setScale(2)  // 缩放 放大两倍
//        splash.xScale = 2   // 单独缩放x
        splash.zRotation = CGFloat(Double.pi)/2  // 旋转
        splash.alpha = 0.5
        splash.isHidden = false
        self.addChild(splash)

//        splash.removeFromParent()
//        removeAllChildren()
    }

当中的锚点能够依据上面包车型地铁图理解

betway体育app 5

B2588466-9F89-4209-9EB8-BC732A1F1935.png

能够领略为将图纸订在墙上,锚点也便是钉子钉的职位,默许是(0.5, 0.5)。

+ (SKAction*)resizeByWidth:(CGFloat)width height:(CGFloat)height duration:(NSTimeInterval)duration;

正如的效果与利益图,场景已经安装好边界了.我们看到飞船降落的过程最终并不可能抢先显示屏了.

下边就用七个乖巧表达速度属性.代码如下.

反向动作

反向动作正是场景中的节点原本往一个主旋律实行活动,不过在运营时那么些节点却向相反的防线举行了运动,假诺想要实现行反革命向运动,就供给动用到反向运动,反向运动的创导方法为指标方法,是采纳贰个动作调用- (SKAction *)reversedAction;回到动作就能够说那个动作的反向动作. 其语法方式如下所示.

- (SKAction *)reversedAction;

反向示例:

就那方面包车型大巴路线动作为例,我们创立它的反向动作,为了进一步活跃形象,笔者给动作的接触设置了八个BOOL,具体的示范代码如下.

#pragma mark ---- 以反向形式移动飞船 ----BOOL isReversed = YES;//设置监控反向的BOOL值.-touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ isReversed = ! isReversed; SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; CGRect createRect = CGRectMake(0, 0, 100, 100); CGPathRef path = CGPathCreateWithRect(createRect, nil); SKAction * moveAction = [SKAction followPath:path duration:2]; SKAction *reversedAction = [moveAction reversedAction]; if (isReversed) { [planeNode runAction:moveAction]; }else{ [planeNode runAction:reversedAction]; } }

betway体育app,如下图所示,那正是反向动作的效果与利益图

betway体育app 6反向作用图.gif

8、调治尺寸的动作

调动尺寸的动作包括:以目的值调治尺寸、以增量调解尺寸

let resizeWidth = SKAction.resize(toWidth: 100, height: 100, duration: 2)  // 以目标值调整尺寸
ball.run(resizeWidth)
let resize = SKAction.resize(byWidth: 200, height: 200, duration: 2)  // 以增量调整尺寸
ball.run(resize)

+ (SKAction*)scaleBy:(CGFloat)scale duration:(NSTimeInterval)sec;

SKPhysicsBody的创导情势根本有二种.如下所示.

betway体育app 7逐个Smart对象设置的曲线形式betway体育app 8效果图

光滑度动作

折射率动作就是钦命节点的反射率的动作,尽管看起来相比简单,然而语法方式比非常多,下边就静心的认证各样语法方式.

下边包车型客车三个语法是毫无内定阿尔法值的,多少个阿尔法值为1,多少个为0,我们只须要设定两个的动作时间就可以了.

//alpha值为1+ (SKAction *)fadeInWithDuration:(NSTimeInterval)sec;//alpha值为0+ (SKAction *)fadeOutWithDuration:(NSTimeInterval)sec;

下边包车型地铁语法是供给钦命阿尔法值的.

+ (SKAction *)fadeAlphaTo:alpha duration:(NSTimeInterval)sec;

上面包车型大巴语法是急需内定alpha值的增量.

+ (SKAction *)fadeAlphaBy:factor duration:(NSTimeInterval)sec;

折射率动作的身体力行

本人就以不难的绝不钦命的反射率的动作为示例.

#pragma mark ---- 飞船的透明度 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction *alphaInAction = [SKAction fadeInWithDuration:1]; SKAction *alphaOutAction = [SKAction fadeOutWithDuration:1]; SKAction *repeatAction = [SKAction repeatActionForever:[SKAction sequence:@[ alphaOutAction, alphaInAction ]]]; [planeNode runAction:repeatAction];}

当大家点击荧屏的时候,效果图如下.

betway体育app 9

SKLightNode使用:
func addLightNode() {
        backgroundColor = SKColor.black
        // 创建精灵
        let spriNode = SKSpriteNode.init(color: UIColor.white, size: CGSize.init(width: 300, height: 300))
        spriNode.position = CGPoint.init(x: KScreenWidth/2, y: KScreenHeight/2)
        self.addChild(spriNode)
        // 添加光源
        let nodeNormMap = spriNode.texture?.generatingNormalMap()
        spriNode.normalTexture = nodeNormMap
        spriNode.lightingBitMask = 1    // 被何种光照
        spriNode.name = "SprNOde"
        let lightSprite = SKLightNode() //实例化光源
        lightSprite.position = CGPoint.init(x: KScreenWidth/2 + 60, y: KScreenHeight/2) // 关照位置
        lightSprite.name = "LightSptite"
        lightSprite.categoryBitMask = 1 // 光的种类
        self.addChild(lightSprite)
    }

运作结果截图:

betway体育app 10

C9C46872B5421D98C7940C17C21B4D3C.png

图片来自互连网

betway体育app 11

betway体育app 12

旋转动作

娱乐中的物体的旋转多数供给用的旋转动作,旋转动作的开创方法独有一种,如下所示.

+ (SKAction *)rotateByAngle:radians duration:(NSTimeInterval)sec;

sec:用来钦定旋转动作所急需的时间.radians:用来内定Smart只怕别的节点的转动量,以弧度为单位;上边所示的常用的角度.

#define M_PI 3.14159265358979323846264338327950288 /* 180度 */#define M_PI_2 1.57079632679489661923132169163975144 /* 90度 */#define M_PI_4 0.785398163397448309615660845819875721 /* 45度 */

旋转示例:

#pragma mark --- 添加旋转动作 ----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *windmillNode = (SKSpriteNode *)[self childNodeWithName:@"windmillNode"]; //删除所有的动作 [windmillNode removeAllActions]; SKAction *rotateAction = [SKAction rotateByAngle:M_PI*2 duration:0.3]; [windmillNode runAction:rotateAction];}

地点是以三个扇车的灵活为例,做旋转动作,每当点击荧屏,Smart就能够旋转360度.效果图如下.

betway体育app 13旋转效果图

betway体育app 14

moveToX和moveToY多个办法同样,正是在另二个坐标不改造的气象下将X或Y坐标改换为设定值,这里大家设定多个都是0,所以五个键按下后会开掘火箭回到了坐标系的原点也正是左下角。

#import "GameScene.h"@interface GameScene ()<SKPhysicsContactDelegate>@end@implementation GameScene-(instancetype)initWithSize:size{ if (self = [super initWithSize:size]) { // //设置场景的物理世界// // self.physicsWorld.gravity = CGVectorMake(0.0, -9.8);//// self.physicsWorld.contactDelegate = self; } return self;}-didMoveToView:view{ [self backgroundNode]; [self planeNode];}#pragma mark ----创建背景-----backgroundNode{ SKSpriteNode *backgroundNode = [SKSpriteNode spriteNodeWithImageNamed:@"bg_02.jpg"]; backgroundNode.position = CGPointZero; backgroundNode.zPosition = 0; backgroundNode.anchorPoint = CGPointZero; backgroundNode.size = self.size; [self addChild:backgroundNode]; }#pragma mark ---- 创建飞船 -----planeNode{ SKSpriteNode *planeNode = [SKSpriteNode spriteNodeWithImageNamed:@"飞机.png"]; planeNode.position = CGPointMake(self.size.width/2, self.size.height/2); planeNode.anchorPoint = CGPointMake; planeNode.zPosition = 1; planeNode.name = @"plane"; [self addChild:planeNode]; }-touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; //给精灵添加物理体 planeNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:planeNode.size];}@end

想要设置可能是获得动作所急需的时间,必要选择到duration那个属性.在API小说的duration属性介绍如下图所示.

再也动作

重新动作及一个动作运转往往大概无多次,在那之中重复动作分为Infiniti重复和装有自然次数的重复.当中两种语法方式如下.

//无限重复+ (SKAction *)repeatActionForever:(SKAction *)action;

//具有一定次数的重复+ (SKAction *)repeatAction:(SKAction *)action count:(NSUInteger)count;

action:用来钦点重复的动作.count:用来钦命重复的次数.

双重动作演示:

大家就拿地点的身体力行队列动作演示来增多在重复动作的中.如下代码所示.

#pragma mark ---- 移动飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint position = [touch locationInNode:self]; SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction * moveAction = [SKAction moveTo:position duration:1]; SKAction *moveZeroAction = [SKAction moveTo:CGPointMake(self.size.width/2, self.size.height/2) duration:1]; SKAction *groupAction = [SKAction sequence:@[ moveAction, moveZeroAction ]]; SKAction * repeatAction = [SKAction repeatActionForever:groupAction]; [planeNode runAction:repeatAction];}

功能图如下,当大家点击显示屏的一个地点的时候,飞船会没完没了的往返移动.

betway体育app 15

组成动作注意事项:
上边陈诉的组动作,系列动作,重复动作是以子动作的不二秘诀包蕴其余动作:
贰个行列动作中有四个子动作,类别中的每一个动作在前八个动作甘休在此之前初叶。
二个组动作中有多少个子动作,动作组中的全数动作同不时间起始施行。
三个重新动作中独有一个子动作,当再次动作中的子动作完结时,重复动作将再也初阶施行。
地点二种动作能够嵌套使用,这种使动作结合起来的本事能够帮您为节点加多特别复杂的动作。
曲线格局包蕴三种:

SKActionTimingLinear 平均布满
SKActionTimingEaseIn 先导异常慢,再加速
SKActionTimingEaseOut 开始快,再变慢
SKActionTimingEaseInEaseOut 先导慢,再加速至中间,再变慢
let spriteMoveUp = SKAction.moveBy(x: 300, y: 0, duration: 1.0)

spriteMoveUp.speed = 1.3  // 速度
spriteMoveUp.timingMode = SKActionTimingMode.easeInEaseOut  // 曲线方式
print(ball.speed)  // 获取并输出动作所需时间

betway体育app 16

我们在下面的代码基础上海展览中心开更改,大家只需求在touchBegan之中给场景的物理体设置为边类型的物理体就行了. 具体代码如下.

betway体育app 17效果图

水彩动作

颜色动作其实是退换节点的颜料以及混合因子,语法情势总共有两种,一种是只变动混合因子,另外一种是改动颜色和混合因子,对于混合因子,类型为CGFloat类型,能够清楚为颜色的深浅度.具体的语法情势如下.

只变动混合因子

+ (SKAction *)colorizeWithColorBlendFactor:colorBlendFactor duration:(NSTimeInterval)sec;

并且退换混合因子和颜色

+ (SKAction *)colorizeWithColor:(SKColor *)color colorBlendFactor:colorBlendFactor duration:(NSTimeInterval)sec;

水彩动作演示:

上面以只变动混合因子为示例.

#pragma mark ---- 改变飞船的颜色 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction *sizeAction = [SKAction colorizeWithColorBlendFactor:0.66 duration:1]; [planeNode runAction:sizeAction];}

效益图如下.通过成效图大家会发觉飞机全体的颜料会变浅.

betway体育app 18

10、改造光滑度的动作

有三种,分别是不要求钦命阿尔法值和钦点阿尔法值(以目的值钦点、以增量值钦定)。

// 不需要指定alpha值
let fadeOut = SKAction.fadeOut(withDuration: 0.25)
let fadeIn = SKAction.fadeIn(withDuration: 0.25)
// 指定alpha值
let fadeOutAlpha = SKAction.fadeAlpha(to: 0, duration: 0.2) // 以目标值指定
let fadeInAlpha = SKAction.fadeAlpha(to: 1, duration: 0.2)
let hide = SKAction.fadeAlpha(by: -1, duration: 0.2)    // 以增量值指定
let show = SKAction.fadeAlpha(by: 1, duration: 0.2)

在MoveShowScene.m中增多如下代码

大意引擎的简约实用就聊到那,在上面一篇作品,小编将写一下有关物理引擎的属性和冲击事件的达成.迎接关怀~谢谢.

betway体育app 19

斩断投机的余地,本事更加好地收获出路。在不知凡几时候,大家都亟待一种斩断投机退路的胆量。
5、延迟动作

行使waitForDuration()方法达成。以系列动作为例,在体系中插入三个推迟动作。

let wait = SKAction.wait(forDuration: 1.0)   // 延迟动作(延迟1s)
let sequence = SKAction.sequence([spriteMoveUp, wait, actionMove])
ball.run(sequence)

对KeyDown方法的switch选拔中增加如下分支:

-touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //设置边界 self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.size.width, self.size.height)]; SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; //设置矩形物理体 planeNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:planeNode.size];}
-->动作的本性德姆o

SKAction分类

2、手势

广大的手势识别器:

名称 功能
UITapGestureRecognizer 轻拍
UIPinchGestureRecognizer
UISwipeGestureRecognizer 滑动
UIRotationGestureRecognizer 旋转
UIPanGestureRecognizer 移动
UILongPressGestureRecognizer 长按
  • 轻拍
    分两步,增加手势、完结手势方法。
    func addGestureRecognizer() {
        let tapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
        self.view?.addGestureRecognizer(tapGestureRecognizer)
    }

    func handleTap() {
        backgroundColor = UIColor.yellow
    }

  • 捏 其实正是因此五个指头的张合,完成图片的放大和紧缩。
    func addGestureRecognizer() {
        let pinchGestureRecognizer = UIPinchGestureRecognizer.init(target: self, action: #selector(handlepin(recognizer:)))
        self.view?.addGestureRecognizer(pinchGestureRecognizer)
    }

    var lastScale: CGFloat = 0.0
    func handlepin(recognizer: UIPinchGestureRecognizer) {
        self.view?.bringSubview(toFront: view!)
        // 复原
        if(recognizer.state == UIGestureRecognizerState.ended){
            lastScale = 1.0
            return
        }

        let scale: CGFloat = 1.0 - (lastScale - recognizer.scale)
        let current: CGAffineTransform = recognizer.view!.transform
        let newaa = current.scaledBy(x: scale, y: scale)
        recognizer.view?.transform = newaa
        lastScale = recognizer.scale
    }
  • 旋转
    因此旋转手势,三个指头旋转调控图片旋转。
    func addGestureRecognizer() {
        let rotationGestureRecognizer = UIRotationGestureRecognizer.init(target: self, action: #selector(handRotation(recognizer:)))
        self.view?.addGestureRecognizer(rotationGestureRecognizer)
    }
    // 旋转
    func handRotation(recognizer: UIRotationGestureRecognizer) {
        let rataion:CGFloat = recognizer.rotation
        sprite.zRotation = -rataion
    }
  • 移动
    和出手中的touchesMoved类似意义,通过移出手势,能够使图片跟初阶指的位移手势移动。
    func addGestureRecognizer() {
        let panGestureRecognizer = UIPanGestureRecognizer.init(target: self, action: #selector(handPan(recognizer:)))
        self.view?.addGestureRecognizer(panGestureRecognizer)
    }
    // 移动
    func handPan(recognizer: UIPanGestureRecognizer) {
        let point = recognizer.location(in: self.view)
        let pointY = (self.view?.frame.size.height)! - point.y
        sprite.position = CGPoint.init(x: point.x, y: pointY)
    }
  • 滑动
    滑入手势:UISwipeGestureRecognizer。在使用时方可使用direction属性设置滑动手势滑动的动向。
    func addGestureRecognizer() {
        let swipeLeftGestureRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(handSwipeLeft))     // 向左滑动
        swipeLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirection.left;
        self.view?.addGestureRecognizer(swipeLeftGestureRecognizer)

        let swipeRightGestureRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(handSwipeRight))     // 向右滑动
        swipeRightGestureRecognizer.direction = UISwipeGestureRecognizerDirection.right;
        self.view?.addGestureRecognizer(swipeRightGestureRecognizer)
    }
    // 滑动
    func handSwipeLeft() {
        let actionMove = SKAction.move(to: CGPoint.init(x: sprite.size.width/2, y: KScreenHeight/2), duration: 1)
        sprite.run(actionMove)
    }
    func handSwipeRight() {
        let actionMove = SKAction.move(to: CGPoint.init(x: KScreenWidth - sprite.size.width/2, y: KScreenHeight/2), duration: 1)
        sprite.run(actionMove)
    }
  • 长按
    func addGestureRecognizer() {
        let longPressGestureRecognizer = UILongPressGestureRecognizer.init(target: self, action: #selector(handLongPress))
        self.view?.addGestureRecognizer(longPressGestureRecognizer)
    }
    // 长按
    func handLongPress() {
        backgroundColor = UIColor.gray
    }

事先大家兑现了让火箭来到鼠标点击地方的动作,以往大家来品尝一下SKAciton中任何的动作,以及通过键盘进行操作的艺术。

物理体 功能
动态体积 模拟系统中一个有体积和速度,可以受理和碰撞作用的物理对象
静态体积 与动态体积相似,单他的速度可以忽略,其它不受利于碰撞的作用.然而,因为它然后具有体积,其他对象可以弹开它与它进行交互
遍是一个静态无体积的主体.遍从来不会被模拟移动,且它们的质量并不重要.遍被用于场景中的负空间或者是一条不可逾越且不可见的微薄的边界
#pragma mark ---- 移动飞船 -----touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ SKSpriteNode *planeNode = (SKSpriteNode *)[self childNodeWithName:@"plane"]; SKAction *moveAction = [SKAction moveToY:0 duration:1]; //设置速度 moveAction.speed = 0.5; [planeNode runAction:moveAction]; SKSpriteNode *planeNode1 = (SKSpriteNode *)[self childNodeWithName:@"plane1"]; SKAction *moveAction1 = [SKAction moveToY:0 duration:1]; //设置速度 moveAction1.speed = 2; [planeNode1 runAction:moveAction1]; NSLog(@"动作一的所需时间:%f",moveAction.duration); NSLog(@"动作二的所需时间:%f",moveAction1.duration); }@end
组动作

组动作,大家在地点的移动操作的躬体力行中已经做了回顾的言传身教,组合动作其实便是吧多个只怕多少个以上的动作放在一齐同临时间进行,组合动作最大的风味就是同一时间性,不管多少个动作都以还要奉行的.其语法情势如下:

+ (SKAction *)group:(NSArray<SKAction*> *)actions;

actions:是一个数组类型,数组中的成分是SKAction.

组动作示例:

组动作示例的身体力行代码就相当少解释了,大家就参照着地点的进程动作的示范代码就能够了,当然了,组动作是足以别的的动作极度使用的.

13、路线动作

行使followPath()方法达成。方法中的属性:

path 用来内定八个CGPathRef路线
offset 用来钦命路径中的点是还是不是为绝对坐标,true(相对坐标),false(相对坐标)
orient 钦赐Z轴在转悠时属性是还是不是变动
sec 动作时间

func pathAction() {
        let background = SKSpriteNode.init(imageNamed: "field")
        background.position = CGPoint.init(x: KScreenWidth/2, y: KScreenHeight/2)
        background.size = CGSize.init(width: KScreenWidth, height: KScreenHeight)
        self.addChild(background)

        let ball = SKSpriteNode.init(imageNamed: "soccer")
        ball.position = CGPoint.init(x: KScreenWidth/2, y: KScreenHeight/2)
        ball.size = CGSize.init(width: 50, height: 50)
        self.addChild(ball)

        let circle = CGPath.init(roundedRect: CGRect.init(x: 200, y:100 , width: 200, height: 200), cornerWidth: 100, cornerHeight: 100, transform: nil)
        let follow = SKAction.follow(circle, asOffset: false, orientToPath: false, duration: 5)
        let runRepeat = SKAction.repeatForever(follow)
        // 反向运动
        let reverse = runRepeat.reversed()
        // 速度动作
        let speedaction = SKAction.speed(to: 15, duration: 1.0)
        let group = SKAction.group([speedaction, reverse])
        ball.run(group)

    }

今昔我们来试试看旋转

betway体育app 20效果图

本文由必威发布于必威-编程,转载请注明出处:当场景处理其子节点的时候betway体育app,API文档

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。