SpriteKit (SKNode的子类)

SKSpriteNode(精灵节点)

精灵节点,是一个2D纹理节点,在指定矩形区域内快速显示图像。SKNode的子类。处理图像和颜色的节点。

从图像文件名创建精灵

- (instancetype)initWithImageNamed:(NSString *)name;//使用图像文件初始化纹理精灵。
+ (instancetype)spriteNodeWithImageNamed:(NSString *)name normalMapped:(BOOL)generateNormalMap;//使用图像文件初始化纹理精灵,可选择添加法线贴图来模拟 3D 照明。

从纹理创建精灵

- (instancetype)initWithTexture:(nullable SKTexture *)texture;//使用现有纹理对象初始化纹理精灵。
- (instancetype)initWithTexture:(nullable SKTexture *)texture color:(SKColor *)color size:(CGSize)size;//用颜色和指定的边界初始化精灵。
- (instancetype)initWithColor:(SKColor *)color size:(CGSize)size;//用颜色和指定的边界初始化精灵。
+ (instancetype)spriteNodeWithImageNamed:(NSString *)name;//使用图像文件初始化纹理精灵。
+ (instancetype)spriteNodeWithTexture:(nullable SKTexture *)texture;//使用现有纹理对象初始化纹理精灵。
+ (instancetype)spriteNodeWithTexture:(nullable SKTexture *)texture size:(CGSize)size;//使用现有的纹理对象初始化纹理精灵,但具有指定的大小。
+ (instancetype)spriteNodeWithTexture:(nullable SKTexture *)texture normalMap:(nullable SKTexture *)normalMap;//使用法线贴图初始化纹理精灵以模拟 3D 照明。
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;//从存档初始化精灵。

设置精灵的大小和位置

@property (nonatomic) CGSize size;//精灵的尺寸,以点为单位。
- (void)scaleToSize:(CGSize)size;//大小缩放
@property (nonatomic) CGPoint anchorPoint;//用于在精灵中选择映射到其父坐标空间中的“位置”的位置。0.0-1.0

在九个部分缩放精灵

@property (nonatomic) CGRect centerRect;//拉伸纹理。拉伸采用9部分算法。

给精灵着色

@property (nonatomic, retain) SKColor *color;//精灵的基本颜色。
@property (nonatomic) CGFloat colorBlendFactor;//控制纹理和精灵颜色之间的混合。有效值的范围是从0.0到(包括)1.0。

点亮精灵

@property (nonatomic) uint32_t lightingBitMask;//表示被一组使用重叠照明类别的灯照亮。使用此蒙版将类别设置为非零的值的灯将会给这个精灵添加光线。
@property (nonatomic) uint32_t shadowCastBitMask;//定义哪些灯光为精灵添加阴影的蒙版。
@property (nonatomic) uint32_t shadowedBitMask;//定义此精灵遮挡哪些灯光的遮罩。
@property (nonatomic, retain, nullable) SKTexture *normalTexture;//指定精灵的法线贴图的纹理。这只会在精灵被至少一盏灯点亮时使用。

向精灵添加自定义着色器

@property (nonatomic, retain, nullable) SKShader *shader;//定义执行自定义每像素绘图或着色的代码的文本文件。
@property (nonatomic, nonnull, copy) NSDictionary *attributeValues;//与节点的附加着色器关联的每个属性的值。
- (void)setValue:(SKAttributeValue*)value forAttributeNamed:(nonnull NSString *)key;//设置附加着色器的属性值。
- (nullable SKAttributeValue*)valueForAttributeNamed:(nonnull NSString *)key;//设置着色器属性的值。

SKLabelNode(使用指定的字体显示文本标签)

+ (instancetype)labelNodeWithText:(nullable NSString *)text;//利用文字初始化
+ (instancetype)labelNodeWithAttributedText:(nullable NSAttributedString *)attributedText;//利用富文本初始化
+ (instancetype)labelNodeWithFontNamed:(nullable NSString *)fontName;//使用指定字体初始化一个新的标签对象。
- (instancetype)initWithFontNamed:(nullable NSString *)fontName;使用指定字体初始化一个新的标签对象。

@property (nonatomic) SKLabelVerticalAlignmentMode verticalAlignmentMode;//节点内文本的垂直位置。
@property (nonatomic) SKLabelHorizontalAlignmentMode horizontalAlignmentMode;//节点内文本的水平位置。
@property(nonatomic) NSInteger numberOfLines;//行数
@property(nonatomic) NSLineBreakMode lineBreakMode;//确定多行的换行模式。
@property(nonatomic) CGFloat preferredMaxLayoutWidth;//用于确定多行标签的布局宽度。

@property (nonatomic, copy, nullable) NSString *fontName;//字体
@property (nonatomic, copy, nullable) NSString *text;//文字
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;//富文本
@property (nonatomic) CGFloat fontSize;//文字大小

@property (nonatomic, retain, nullable) SKColor *fontColor;//文字颜色
@property (nonatomic) CGFloat colorBlendFactor;//描述颜色如何与字体颜色混合。
@property (nonatomic, retain, nullable) SKColor *color;//用于动画的字体颜色的替代方案。
@property (nonatomic) SKBlendMode blendMode;//用于将标签绘制到父级帧缓冲区的混合模式。

SKShapeNode(使用指定的路径绘制或填充形状)

从路径创建形状

+ (instancetype)shapeNodeWithPath:(CGPathRef)path;//从 Core Graphics 路径创建形状节点。
+ (instancetype)shapeNodeWithPath:(CGPathRef)path centered:(BOOL)centered;//从核心图形路径创建一个形状节点,以它的位置为中心。

从矩形创建形状

+ (instancetype)shapeNodeWithRect:(CGRect)rect;//创建具有矩形路径的形状节点。
+ (instancetype)shapeNodeWithRectOfSize:(CGSize)size;//创建一个形状节点,其矩形路径以节点的原点为中心。
+ (instancetype)shapeNodeWithRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;//创建一个带有圆角矩形路径的形状。
+ (instancetype)shapeNodeWithRectOfSize:(CGSize)size cornerRadius:(CGFloat)cornerRadius;//创建一个带有以节点位置为中心的圆角矩形路径的形状。

创建圆形

+ (instancetype)shapeNodeWithCircleOfRadius:(CGFloat)radius;//创建一个形状节点,其圆形路径以节点的原点为中心。

创建椭圆形状

+ (instancetype)shapeNodeWithEllipseInRect:(CGRect)rect;//创建一个形状节点,其椭圆路径以节点的原点为中心。
+ (instancetype)shapeNodeWithEllipseOfSize:(CGSize)size;//使用填充指定矩形的椭圆路径创建形状节点。

从一组点创建一个形状

+ (instancetype)shapeNodeWithPoints:(CGPoint *)points count:(size_t)numPoints;//从一系列点创建一个形状节点。
+ (instancetype)shapeNodeWithSplinePoints:(CGPoint *)points count:(size_t)numPoints;//从一系列点创建一个形状节点。(拐点平滑)

填充形状

@property (nonatomic, retain) SKColor *fillColor;//填充颜色
@property (nonatomic, retain, nullable) SKTexture *fillTexture;//用于填充形状的纹理。

边缘形状

@property (nonatomic) CGFloat lineWidth;//边缘宽度
@property (nonatomic, retain) SKColor *strokeColor;//边缘颜色
@property (nonatomic, retain, nullable) SKTexture *strokeTexture;//用于描边形状的纹理。
@property (nonatomic) CGFloat glowWidth;//从描边线向外延伸的光晕。
@property (nonatomic) CGLineCap lineCap;//用于渲染形状节点描边部分端点的样式。
@property (nonatomic) CGLineJoin lineJoin;渲染形状节点的描边部分时使用的连接类型。
@property (nonatomic) CGFloat miterLimit;//使用斜接连接样式描边线时使用的斜接限制。
@property (nonatomic, getter = isAntialiased) BOOL antialiased;//用于确定绘制时是否平滑描边路径。

配置 Alpha 混合

@property (nonatomic) SKBlendMode blendMode;//用于将标签绘制到父级帧缓冲区的混合模式。

控制或动画描边长度

@property (nonatomic, readonly) CGFloat lineLength;//如果要描边,节点的路径长度

自定义描边或填充绘图

@property (nonatomic, retain, nullable) SKShader *strokeShader;//用于确定形状节点描边部分颜色的自定义着色器。
@property (nonatomic, retain, nullable) SKShader *fillShader;//用于确定形状节点填充部分的颜色的自定义着色器。
@property (nonatomic, nonnull, copy) NSDictionary *attributeValues;//与节点的附加着色器关联的每个属性的值。

- (nullable SKAttributeValue*)valueForAttributeNamed:(nonnull NSString *)key;//着色器属性的值。
- (void)setValue:(SKAttributeValue*)value forAttributeNamed:(nonnull NSString *)key;//设置附加着色器的属性值。

SKVideoNode(视频节点,提供视频播放支持)

初始化方法

- (instancetype)initWithVideoFileNamed:(NSString *)videoFile;
+ (SKVideoNode *)videoNodeWithFileNamed:(NSString *)videoFile;//根据视屏文件初始化。

- (instancetype)initWithAVPlayer:(AVPlayer*)player;
+ (SKVideoNode *)videoNodeWithAVPlayer:(AVPlayer*)player;//根据现有播放器初始化。

- (instancetype)initWithURL:(NSURL *)url;
+ (SKVideoNode *)videoNodeWithURL:(NSURL *)videoURL;//根据URL初始化。

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;//告诉您何时初始化从存档创建的视频节点。

其他

- (void)play;//播放
- (void)pause;//暂停

@property (nonatomic) CGSize size;//尺寸
@property (nonatomic) CGPoint anchorPoint;//精灵中对应于节点位置的点。

SKEmitterNode(粒子发射器节点,提供粒子效果支持)

SKCropNode(裁剪组件,使用遮罩裁剪其内部的子节点)

SKEffectNode(使用帧缓冲效果渲染节点结果,用于生成某一时刻的屏幕快照)

@property (nonatomic, retain, nullable) CIFilter *filter;//要应用的核心图像过滤器。
@property (nonatomic) BOOL shouldCenterFilter;//用于确定效果节点是否自动设置滤镜的图像中心。
@property (nonatomic) BOOL shouldEnableEffects;//用于确定效果节点是否在绘制其子项时对其应用过滤器。

@property (nonatomic) BOOL shouldRasterize;//指示是否应缓存渲染子节点的结果。
@property (nonatomic) SKBlendMode blendMode;//用于将节点的内容绘制到其父级的帧缓冲区的混合模式。
@property (nonatomic, retain, nullable) SKShader *shader;//当效果节点混合到父级的帧缓冲区时调用的自定义着色器。

@property (nonatomic, nonnull, copy) NSDictionary *attributeValues;//与节点的附加着色器关联的每个属性的值。
- (nullable SKAttributeValue*)valueForAttributeNamed:(nonnull NSString *)key;//获取着色器属性的值。
- (void)setValue:(SKAttributeValue*)value forAttributeNamed:(nonnull NSString *)key;//设置附加着色器的属性值。

你可能感兴趣的:(SpriteKit (SKNode的子类))