随笔 - 91,  文章 - 0,  评论 - 4,  阅读 - 13万

简介

SKScene对象代表SpriteKit中的内容场景。场景是SpriteKit节点树中的根节点(SKNode)。这些节点提供场景动画和渲染以显示的内容。要显示一个场景,你可以从SKView、SKRenderer或wkinterfaceeskscene中呈现它。

使用

SKScene

  • 初始化
/// 初始化方法
public init(size: CGSize)
/// 场景在不同尺寸下的拉伸样式
open var scaleMode: SKSceneScaleMode
/// @available(iOS 10.0, *) 场景初始化后调用,相当于 ViewDidLoad()
open func sceneDidLoad()
/// 加载到 SKView 上
open func didMove(to view: SKView)
/// 从 SKView 上移除
open func willMove(from view: SKView)
/// scence 场景尺寸改变
open func didChangeSize(_ oldSize: CGSize)
  • 配置窗口
/// @available(iOS 9.0, *) 摄像机,当场景的尺寸大于当前屏幕时,可以去初始化摄像机,用于获取基于摄像机相对于场景的位置的视图缩放和平移
weak open var camera: SKCameraNode?
/// 场景的坐标原点位置,范围是(0, 0) ~ (1, 1)。默认是(0, 0),屏幕左下角为原点。往上是 y 值增加,往下是 y 值减少,往右是 x  值增加,往左是 x 值减少
open var anchorPoint: CGPoint
/// 场景的屋里世界,包含时间流速、重力等等
open var physicsWorld: SKPhysicsWorld { get }
/// 父视图
weak open var view: SKView? { get }
  • 响应帧周期,每一帧都调用一次
/// currentTime 每次都是增加的,两次的时间间隔就是一帧的时间
open func update(_ currentTime: TimeInterval)
/// action 相关帧周期
open func didEvaluateActions()
/// PhysicsBody 相关帧周期
open func didSimulatePhysics()
/// @available(iOS 8.0, *) 更新约束 相关帧周期
open func didApplyConstraints()
/// @available(iOS 8.0, *) 每一帧调用完成
open func didFinishUpdate()
  • 音频相关
/// @available(iOS 9.0, *) 场景中音频的听者位置的节点。
weak open var listener: SKNode?
/// @available(iOS 9.0, *) 场景中包含的音频节点播放音频的引擎
open var audioEngine: AVAudioEngine { get }
  • 代理
@available(iOS 8.0, *)
weak open var delegate: SKSceneDelegate?
/// 执行任何特定于应用程序的逻辑来更新您的场景
optional func update(_ currentTime: TimeInterval, for scene: SKScene)
/// 完成场景动作后
optional func didEvaluateActions(for scene: SKScene)
/// 完成物理模拟后
optional func didSimulatePhysics(for scene: SKScene)
/// 更新约束后
optional func didApplyConstraints(for scene: SKScene)
/// 完成所有的动画后
optional func didFinishUpdate(for scene: SKScene)
  • 坐标转换
/// 将点从视图坐标转换为场景坐标
open func convertPoint(fromView point: CGPoint) -> CGPoint
/// 将点从场景坐标转换为视图坐标
open func convertPoint(toView point: CGPoint) -> CGPoint
posted on   xiao孛  阅读(128)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示