Preliminary study on SpriteKit

Source: Internet
Author: User
Tags spritekit

1.Spritekit Overview

Spritekit is an apple-powered native 2D game framework that supports game development elements such as texture sprites, particle effects, physics engines, and more.


Spritekit Advantages and Disadvantages:






Spritekit's coordinate system:


2. Introduction to common classes in Spritekit framework1.) Skview

? Skview is the view used to present the Skscene node

? You can use Presentscene: and Presentscene:transition: Methods to show the scene

? Note: You are not allowed to write Skview subclasses

2.) Skscene

? A scene is the root node of the content that is used to display spritekit content on a Skview

? The scene is infinitely large, where the content is presented to the user through the viewport (viewport)

? When instantiating a scene, the size parameter defines how large the scene viewport (viewport) is to be displayed

? To display the contents of other locations in the scene, move the viewport to the appropriate location to create a sknode responsible for the viewport changes

3.) Sknode

? Sknode is the Spritekit scene graph node. These branch nodes, together with the geometric leaf nodes , form a directed acyclic graph (DAG) of the spritekit scene graph tree

? Root nodes, all nodes have a unique parent node, the leaf node has no child nodes, and contains some shareable data that satisfies the DAG condition

? The so-called directed non-circular graph refers to: any one edge has a direction, and there is no loop diagram

? Basic properties:

? Frame/position: Border/Position

? Zposition/zrotation:z axis direction position/rotation angle

? xscale/yscale:x/y Axis Direction Scale

? Speed: Velocity

? Alpha: Transparency

? Paused: Controlling animation pauses

? Hidden: Controls whether to hide

? Userinteractionenabled: Whether user interaction is allowed

? Parent: Father Node

? Children: Child Node Array

? Name: Names (should remain unique in a scene tree)

? Scene: Current Location

? Physicsbody: Physical rigid body, a description of the physical properties of a node, such as: shape, density, etc.

? UserData: The user data dictionary for the current node, default to nil

? Sub-class

? Skspritenode: Sprite node, a 2D texture node that quickly displays images within a specified rectangular area

? Klabelnode: Display text labels with the specified font

? Skshapenode: Draws or fills a shape with the specified path

? Skvideonode: Video node with video playback support

? Skemitternode: Particle emitter node for particle effect support

? Skcropnode: Cropping a component, using a matte to crop its inner child nodes

? Skeffectnode: Render a node result using the Framebuffer effect to generate a screen shot at a moment

4.) skaction

? Skaction is an action that, through the node Execution (runaction) in the skscene scene, binds the action to the node, can change the structure and content of the node, and can also change the scene

? Common action

? Removefromparent: Remove a node from its parent node and use the method to remove it from the scene when it is no longer needed

? Sequence (series): executes multiple actions sequentially

? Group: Simultaneous execution of multiple actions concurrently

? Repeataction (repeat): repeats action, sequence, group by the specified number of times

? Repeatactionforever (repeat): Infinite loop action, sequence, group

3. Spritekit's rendering process
4. Spritekit's physics engine

? Physical World ( Physics World ) is the space used for physical simulation , which is created by default on the scene

? In the sprite kit, you can set up a physical rigid body (physicsbody) for each spriteto enable collision detection . Physical rigid bodies do not have to be consistent with the shape of the sprite itself (that is, the display image), and usually the physical rigid body does not need to be accurate to every point, which is sufficient for most games.

? sets the class mask that participates in the collision detection object ( Categorybitmask ), to distinguish between different physical objects . When a physical rigid body that detects two sprites collides, the type of the sprite can be distinguished by category and different processing is made according to the categories

? set up the agent to detect collision of objects. When a collision is detected, follow-up processing is done based on the category of the collision object, such as playing a sound or animation, and the proxy class is skphysicscontactdelegate.

5. Additional Rewards:

5.1 How do I use Xcode to create a texture collection?

Basic steps:

1. Put the picture material in a folder

2. Name the folder Name.atlas

3. Select file, add File to Project

4. In the edit area, select your project and click Build Settings


5. Enter the sprite in the search area and press RETURN

6. Set "Enable Textureatlas Generation" to Yes


5.2 How do I use texture animations?
1. Instantiate a texture set        sktextureatlas *altas = [Sktextureatlas atlasnamed:@ "image"];        _texturearray = [Nsmutablearray array];        for (int i=1; i<=5; i++) {            sktexture *texture = nil;                2. Load all textures in the texture set to array                texture = [Altas texturenamed:[nsstring stringwithformat:@ "%d.png", I]];            [_texturearray addobject:texture];        }        3. Instantiate texture Sprite        skspritenode *text = [Skspritenode spritenodewithtexture:_texturearray[0]];        Text.position = Cgpointmake (+);        [Self addchild:text];        _text = text;            4. Animated texture Sprite        skaction *action  = [skaction animatewithtextures:_texturearray timeperframe:0.2f];        [_text runaction:[skaction repeatactionforever:action];


*********************************************************************************************************** ***********************************************Ninja Dart Source: http://download.csdn.net/detail/luozhonglan/8313541hit the mole Source: http://download.csdn.net/detail/luozhonglan/8313529
The next big pomelo will introduce Scenekit, which is the framework Apple offers to make 3D games



Preliminary study on SpriteKit

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.