08.spritekit Journey--animation in the scene

Source: Internet
Author: User
Tags spritekit

08.spritekit Journey--animation in the scene

Then, the above, show whether static text can not meet your desire, then the content of this article absolutely let you boiling blood, remember childhood love to see animation, now there is such a chance to you to create is it a little excited to think about it?

The core of the animation actions is. The Sprite Kit majority action of the in is actually changing the Node properties of the node (). If you do not understand the node is what, suggest good Google Baidu under, although all is the most basic knowledge, but I think "lofty building on the ground", lay a good foundation is the key, the other is to insist.

About nodes:
Nodes are one of the simplest and most difficult concepts to understand. First we have one SKView , which will present multiple scenes SKScene (), a scene with a lot of sprites sprite () and other content, like the "Hello World" above. The text is one node , even the scene is a node , but is a root node. Sprite Kit In the future I will dedicate a chapter to the relationship between the categories.

Go back to our action question and remember that the action is also an object that describes the changes you made to the node, such as panning, rotating, shrinking, and so on, creating the object and then telling the node to execute the design action! When the final scene is rendered, these actions are pulled, dynamically displaying a series of changes that we have designed until all the actions have been performed.

Give text declaration--to animate the text
  1. Or the previous demo, to helloNode add additional configuration:

    //其实就是给该节点进行命名helloNode.name = "helloNode"

    All nodes have a property, name just like a baby named to describe the node. Why would you name it? Imagine that after we may have to take the node to do some operations, if the name of a famous, cliff can be found.

  2. Overwrite ( override ) The method in the touchesBegan(touches: NSSet, withEvent event: UIEvent) parent class method, which can be good in scene class. skscene is UIResponder the most basic class, so it can respond to user action, when the touch 场景 event occurs, you can receive the notification, and then we find by name helloNode node and tells it to perform a short animation.

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent){    //记住 返回的是可选类型SKNode? 有可能得到nil  所以你要解包    //比如你要查找的节点名字拼错就意味着找不到 等于nil    if let helloNode = childNodeWithName("helloNode"){        //纯手打,不对之处见谅        //在x,y方向上移动相对举例,比如原来在(0,100) 执行下面之后是(0,200)        //moveTo才是移动到具体某个位置        let moveUp = SKAction.moveByX(0, y: 100, duration: 0.5)        //放大操作        let zoom = SKAction.scaleTo(2.0, duration: 0.25)        //延迟        let pause = SKAction.waitForDuration(0.5)        //说白了就是透明度最终变0,即渐隐        let fadeAway = SKAction.fadeOutWithDuration(0.25)        //从节点树种移除该节点        let remove = SKAction.removeFromParent()        let moveSequence = SKAction.sequence[moveUp,zoom,                            pause,fadeAway,remove]        helloNode.runAction(moveSequence)    }}
  3. Build and Run. Enjoy yourself.

08.spritekit Journey--animation in the scene

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.