ios8升级ios12教程

In this tutorial, we’ll discuss SpriteKit and build a Hello World iOS Application out of it using Swift.

在本教程中,我们将讨论SpriteKit,并使用Swift从中构建一个Hello World iOS应用程序。

入门 (Getting Started)

SpriteKit is a framework that’s used to create high-performance 2D games while rendering graphics and animation textures.
SpriteKit has an optimized animation system and advances physics effects that are ideal to create engaging 2D games.

SpriteKit是一个框架,用于在渲染图形和动画纹理的同时创建高性能2D游戏。
SpriteKit具有优化的动画系统,并增强了物理效果,非常适合制作引人入胜的2D游戏。

To get started with the SpriteKit Game Project launch your XCode and choose the Game template as shown below:

要开始使用SpriteKit Game Project,请启动XCode并选择Game模板,如下所示:

On the next screen make sure that you choose SpriteKit. Once XCode builds your project, you’ll see many files generated in your Project panel. These include GameScene.swift, .sks files and the GameViewController.
The code can look intimidating at first. Don’t worry we’ll start from the SpriteKit basics before reaching till there.
Build and run the application on your simulator or device.
Following is the output:

在下一个屏幕上,确保选择SpriteKit。 XCode构建项目后,您将在“项目”面板中看到许多生成的文件。 其中包括GameScene.swift,.sks文件和GameViewController。
该代码乍一看可能令人生畏。 别担心,在到达那里之前,我们将从SpriteKit基础开始。
在模拟器或设备上生成并运行该应用程序。
以下是输出:

That’s the sample Hello World SpriteKit application created. But that was all XCode magic. Let’s start from ground zero and cover the important concepts and terms and build our version of SpriteKit Hello World Application.

那就是创建的示例Hello World SpriteKit应用程序。 但这就是XCode的全部魔力。 让我们从零开始,介绍重要的概念和术语,并构建我们的SpriteKit Hello World应用程序版本。

SpriteKit的基础 (Basics of SpriteKit)

Sprites are nothing but animated textured images.
SpriteKit consists of the following important classes:

精灵不过是动画纹理图像。
SpriteKit包含以下重要类:

  • SKView: This is a subclass of the UIView. SKView is the view in which all of the SpriteKit contents are added and displayed on the screen.SKView :这是UIView的子类。 SKView是其中添加了所有SpriteKit内容并在屏幕上显示的视图。
  • SKNode: This is the building block of SpriteKit. It is just an empty node. No visual elements. On a SKNode we can add child nodes such as SKSpriteNode. These nodes can be visual elements or a scene.SKNode :这是SpriteKit的构建块。 它只是一个空节点。 没有视觉元素。 在SKNode上,我们可以添加子节点,例如SKSpriteNode。 这些节点可以是视觉元素或场景。
  • SKScene: An SKScene is a subclass of the SKNode. It represents a single scene from the game. SKScene acts as a root node of the SKNode. SKScene provides the content to the SKView. You just need to call the function presentScene over the SKView and pass the scene instance.SKScene :SKScene是SKNode的子类。 它代表了游戏中的一个场景。 SKScene充当SKNode的根节点。 SKScene将内容提供给SKView。 您只需要在presentScene上调用函数presentScene并传递场景实例。
  • SKAction: An SKAction is used to set actions such as animations/movements on SKNodes.SKAction :SKAction用于设置动作,例如SKNode上的动画/动作。
  • SKPhysicsBody: This class adds the physics components to the SKNodes. Components such as gravity, collision are commonly used in games.SKPhysicsBody :此类将物理组件添加到SKNodes。 游戏中通常使用重力,碰撞等组件。
SKScene origin lies at the bottom left corner.
SKScene的原点位于左下角。

Now create a new XCode Project and choose single view application. We’ll build the SpriteKit project from the scratch.

现在创建一个新的XCode项目并选择单视图应用程序。 我们将从头开始构建SpriteKit项目。

Goto your MainStoryboard and set the custom class type as SKView.

转到MainStoryboard并将自定义类类型设置为SKView。

Right click on the project folder and select new file of the type SpriteKitScene as shown below:

We’ve named the file HelloScene.sks.
This is the layout editor of it:

右键单击项目文件夹,然后选择SpriteKitScene类型的新文件,如下所示:

我们已将文件命名为HelloScene.sks。
这是它的布局编辑器:

Now we need to create a HelloScene.swift file to connect with the above SK scene file.
Create a new file of the type Cocoa Touch class and choose the following class type as the parent:

现在,我们需要创建一个HelloScene.swift文件,以与上述SK场景文件连接。
创建类型为Cocoa Touch类的新文件,然后选择以下类类型作为父类:

The HelloScene.swift file looks like this:

HelloScene.swift文件如下所示:

Ensure that you’ve imported SpriteKit module in it.

确保已在其中导入SpriteKit模块。

Now its time to connect this scene file in the scene layout editor:

现在是时候在场景布局编辑器中连接该场景文件了:

添加精灵 (Adding a Sprite)

To add a sprite from the layout editor we do:

要从布局编辑器添加一个精灵,我们要做:

We can add set any file path to images present in the Assets folder on this Color Sprite.
For now, let’s keep it blank.

我们可以将任何文件路径添加到此Color Sprite上Assets文件夹中的图像。
现在,让我们保持空白。

Adding a Sprite programmatically.
To do so in the HelloScene.swift file, we need to add the child node inside a didMove() function that’s overridden.

以编程方式添加Sprite。
为此,在HelloScene.swift文件中,我们需要在被覆盖的didMove()函数内添加子节点。

import SpriteKitclass HelloScene: SKScene {override func didMove(to view: SKView) {let label = SKLabelNode()label.text = "Hello World!"label.position = CGPoint(x: self.frame.midX, y: self.frame.midY)label.fontSize = 30label.fontColor = SKColor.redself.addChild(label)}
}

We’ve adding a SKLabelNode which displays a Sprite with a text.
The SKLabelNode must be assigned a position else it’ll be placed at the bottom left of the screen.
We’ve centered it here and set the fonts and sizes.
Finally we add the SKLabelNode to the SKScene using addChild()

我们添加了一个SKLabelNode,它显示带有文本的Sprite。
必须为SKLabelNode分配一个位置,否则将其放置在屏幕的左下方。
我们将其定位在此处并设置字体和大小。
最后,我们使用addChild()将SKLabelNode添加到SKScene

从我们的ViewController运行SKScene (Running the SKScene from our ViewController)

We need to now add the SKScene to the ViewController.swift file. In it, we’ll present the scene to the SKView:

现在,我们需要将SKScene添加到ViewController.swift文件中。 在其中,我们将场景呈现给SKView:

import UIKit
import SpriteKit
class ViewController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.if let view = self.view as? SKView{if let scene = SKScene(fileNamed: "HelloScene"){scene.scaleMode = .aspectFillview.presentScene(scene)}}}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}}

We’ve set the scale mode to fill the screen.

我们已经设置了缩放模式以填充屏幕。

The output of the above application is:

上面的应用程序的输出是:

This brings an end to this basic SpriteKit introductory tutorial.
You can download the project from the link below:

这结束了此基本的SpriteKit入门教程。
您可以从下面的链接下载项目:

iOSSpriteKitHelloWorldiOSSpriteKitHelloWorld

翻译自: https://www.journaldev.com/21623/ios-spritekit-tutorial

ios8升级ios12教程

ios8升级ios12教程_iOS SpriteKit教程相关推荐

  1. ios8升级ios12教程_iOS Hello World示例教程

    ios8升级ios12教程 In this tutorial we'll develop our first iPhone Application which displays a Hello Wor ...

  2. iPhone 6 ios8 升级IOS12

    IPHONE6 也是老机器了,还用着IOS8.4的系统,现在官方12都出来了,看报告说不错,遂升级,先用爱思助手.直接白苹果了,白苹果后还闪烁着红屏. 回家开了MAC,下载了新的ITUNES,威锋网下 ...

  3. SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10.50.1600

    今天将由于需要就将我的SQL 2008升级到SQL 2008 R2. 说到为什么要升级是因为,从另一台机器上备份了一个数据库,到我的机器上还原的时候提示"System.Data.SqlCli ...

  4. 查看宝塔面板账号密码命令_宝塔面板升级到最新版图文教程

    往期教程: 宝塔面板教程(1)基于云服务器搭建宝塔面板教程最全详解 宝塔面板教程(2)宝塔面板添加WordPress站点详细图文教程 宝塔面板教程(3)基于宝塔面板成功配置网站SSL安全证书 宝塔面板 ...

  5. 联想笔记本G510升级固态硬盘(SSD)血泪教程!!!

    #联想笔记本G510升级固态硬盘(SSD)血泪教程!!! 用了5年的联想笔记本G510,经过了四年的游戏历程,然后四年后还老当益壮的挣扎在我工作的战斗一线,是我并肩作战多年,比兄弟还要亲的兄弟,虽然此 ...

  6. 为什么我魅族m2显示无服务器,魅族m2升级刷机flyme4.0教程及注意事项.doc

    魅族m2升级刷机flyme4.0教程及注意事项 魅族mx2怎么升级flyme4.0?魅族mx2升级flyme4.0教程及注意事项 小编带来了魅族mx2升级flyme4.0教程及注意事项,并且会提供fl ...

  7. mysql官网下载最新版升级版本多版本安装教程

    mysql官网下载最新版升级版本多版本安装教程 有好多人经常问我有没有mysql的安装包,很是无语,因为问的很多 ,所以今天就写一个教程. 1.下载安装包 点击打开下载地址:mysql官网下载地址,打 ...

  8. android版本如何升级包,安卓手机系统怎么升级?安卓手机系统升级教程

    安卓手机系统怎么升级 随着系统的更新换代,相信不少网友对安卓系统的升级都很感兴趣,而这里指的一般都是通过刷机来升级,好像不刷就浑身不舒服一样.安卓系统升级可以在电脑上面下载官方的升级包,或者像小米系统 ...

  9. android 8.0 一加5,一加5如何升级安卓8.0 一加5升级安卓8.0图文教程

    2017-12-26 17:18:05 一加5如何升级安卓8.0 一加5升级安卓8.0图文教程 标签:一加5,一加5升级,一加5 8.0刷机包 一加5如何升级安卓8.0,rom基地小编今天带来一加5升 ...

最新文章

  1. 虚拟主播上线:多模态将改变人机交互的未来
  2. 【DataGuard】ORA-16014 and ORA-00312 Messages in Alert.log of Physical Standby
  3. win32 数据类型 vs c#
  4. ajax代码编程题,关于AJAX管家代码的几个基本问​​题
  5. Angularjs总结(五)指令运用及常用控件的赋值操作
  6. Python与机器视觉(x)图像差分-图像相减
  7. 【华为云技术分享】ArcFace简介
  8. c语言基础程序设计报告,c语言程序设计基础课程设计报告.doc
  9. a标签中执行js函数
  10. Discuz!X/数据库操作方法
  11. 泰克示波器面板上的旋钮的作用有哪些
  12. Aspnet Mvc 前后端分离项目手记(三)关于restful 风格Url设计
  13. 匿名信一封来信一封云来信表白祝福道歉短信H5公众号系统搭建(搭建赠送人工传话系统+主机管理面板)
  14. spss python_ARIMA模型 - [SPSS Python]
  15. TensorFlow北大公开课学习笔记-4.1损失函数
  16. uniapp修改底部导航栏
  17. 华为FreeBuds SE耳机有杂音异响的解决办法
  18. java连接sftp工具类
  19. UE5神通--POI解决方案
  20. 什么是CSS(层叠样式表)

热门文章

  1. 'datetime.datetime' has no attribute 'datetime'问题
  2. [转]导出数据到Excel的几种方法
  3. [转载] python isinstance()方法的使用
  4. [转载] python基于内置的SimpleHTTPServer来搭建简易的FTP服务器实现局域网内文件共享
  5. [转载] Visual Studio 2017 VC项目设置 printf 输出到 Console 窗口调试
  6. [转载] Python一行代码实现1到100之和
  7. 带新手玩转MVC——不讲道理就是干(上)
  8. JVM01----JVM结构
  9. 前端之JavaScript进阶
  10. Echarts Y轴min显示奇葩问题(做此记录)