Sprite Kit编程指南
更新时间:2023-08-18 09:40:01 阅读量: 资格考试认证 文档下载
- sprite翻译推荐度:
- 相关推荐
ios原生游戏开发
oe:本 P译自⑸pple官方的 pr/te K/t Programm/ng Gu/de》,b用C.ome
浏 g的自动P译功能作G译,h后在一t语句不n或i易造成s解的地方作局
Cu正:方便英 不好的开发者查_:如有错d之处,欢迎K家指 u正:
p时欢迎K家S注r的技mA客 .ttp: /t_mag/c/an:K家的
持lr最K的动c:
S
API
,
, , API
Sprite Kit rendering textured
Sprite Kit
Sprite Kit
Sprite Kit
Sprite Kit
Xcode Sprite Kit ”
atlases ) Sprite Kit
Core Animation
ios原生游戏开发
Sprite Kit iOS OS X “ ” 2D
Sprite Kit
CGPath
Sprite Kit
animate
。
# OpenGL Sprite Kit
ios原生游戏开发
SKView
) scenes SKScene
Sprite Kit SKScene
SKView
“ Sprite Kit” “ ” “ Sprite Kit ”
n
SKScene SKNode
”
:
SKNode Sprite Kit
SKEffectNode Core Image
layer ”
responder descending UIResponder
NSResponder
“ ” “ ” “ ”
ios原生游戏开发
bundle Sprite Kit
Sprite Kit #
Sprite Kit
Sprite Kit
)
# Sprite Kit
“ ”
p
actions SKAction
:
) ”
”
“ ” “ # ”
。
ios原生游戏开发
SKPhysicsBody
forces
。
。
hook
SKPhysicsWorld
SKPhysicsJoint
“ ”
e
“ Sprite Kit” Sprite Kit Sprite
Kit ( Sprite Kit Sprite
Kit
“Sprite Kit ” Sprite Kit
Sprite Kit
iOS iOS OS X Mac
Xcode
ios原生游戏开发
Objective-C blocks
Sprite Kit SpriteKit
Xcode Sprite Kit
SKSpriteNode Sprite Tour
Sprite Kit SpriteKit
Sprite Kit Explained Adventure
ios原生游戏开发
Sprite Kit Sprite Kit
Sprite Kit )
Sprite Kit
iOS iOS Sprite Kit OS X
( Xcode 5.0 iOS Xcode
SpriteWalkthrough ClassPrefix Sprite “ iPad
Sprite Kit
ios原生游戏开发
Sprite Kit Sprite Kit SKView
SKView SKScene
Sprite Kit )
Sprite Kit
!
1. storyboard SpriteViewController
view SKView
2. import <SpriteKit/SpriteKit.h>
3. viewDidLoad - void viewDidLoad
{
[super viewDidLoad];
SKView * spriteView = SKView * self.view;
spriteView.showsDrawCount = YES;
spriteView.showsNodeCount = YES;
spriteView.showsFPS = YES;
}
ios原生游戏开发
4.
spriteView.showsFPS
Hello !
1. HelloScene SKScene
2. #import “HelloScene.h”
3. - void viewWillAppear: BOOL animated
{
HelloScene *hello = [[HelloScene alloc] initWithSize:CGSizeMake(768,1024)];
SKView *spriteView =(SKView *)self.view;
[spriteView presentScene:hello];
}
f
Sprite Kit (chuck)
“Hello World”
ios原生游戏开发
didMoveToView:
Hello !
1. @interface HelloScene()
@property BOOL contentCreated; @end
2. didMoveToView: - self didMoveToView:(SKView *)view
{
if self.contentCreated
{
[self createSceneContents];
self.contentCreated = YES;
}
}
didMoveToView
contentCreated
ios原生游戏开发
3. createSceneContents - (void)createSceneContents
{ self.backgroundColor = [SKColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
[self AddChild [self newHelloNode];
}
SKColor color
SKColor iOS UIColor OS X
NSColor
: scale : :
(letterboxing)
4. newHelloNode - SKLabelNode * newHelloNode
{
SKLabelNode * helloNode = [SKLabelNode labelNodeWithFontNamed:@“Chalkduster”];
@helloNode.text =“Hello, World ”;
helloNode.fontSize = 42;
helloNode.position = CGPointMake(CGRectGetMidX(self.frame) CGRectGetMidY(self.frame)) return helloNode;
}
ios原生游戏开发
OpenGL ES Quartz 2D
Sprite Kit
Sprite Kit
Sprite Kit
“Hello, World ”
Sprite Kit
p p
action
Sprite Kit action
、
p !
1. newHelloNode = @“helloNode”;
monster
2. touchesBegan withEvent 、
helloNode
ios原生游戏开发
iOS UIResponder OS X NSResponder
Sprite Kit - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SKNode *helloNode = [self childNodeWithName:@“helloNode”];
If(helloNode != nil)
{
= nil;
SKAction *moveUp = [SKAction moveByX:0 y:100.0 duration:0.5];
SKAction *zoom = [SKAction scaleTo:2.0 duration:0.25];
SKAction *pause = [SKAction waitForDuration:0.5];
SKAction *fadeAway = SKAction fadeWithDuration:0.25];
SKAction *remove = [SKAction removeFromParent];
SKAction * moveSequence = [SKAction sequence:@[moveUp, zoom, pause, fadeAway, remo
[helloNode runAction moveSequence];
}
}
”
) ;
1
0
ios原生游戏开发
Sprite Kit
“Hello, World ”
Hello
!
1. SpaceshipScene SKScene
2. HelloScene @interface SpaceshipScene()
@property BOOL contentCreated;
@end
@implementation SpaceshipScene
- (void)didMoveToView:(SKView *)view
{
if(!self.contentCreated)
{
[self createSceneContents];
self.contentCreated = YES;
}
}
ios原生游戏开发
- (void)createSceneContents
{ self.backgroundColor = [SKColor blackColor]; self.scaleMode = SKSceneScaleModeAspectFit; }
3. HelloScene.m SpaceshipScene.h
#import “SpaceshipScene.h”
4. touchesBegan:withEvent runAction
runAction:completion: [helloNode runAction:moveSequence completion:^ { SKScene * spaceshipScene = [[SpaceshipScene alloc] initWithSize:self.size];
SKTransition *doors= [SKTransition doorsOpenVerticalWithDuration:0.5];
[self.view presentScene:spaceshipScene transition:doors];
}];
、
“
SKSpriteNode
ios原生游戏开发
Sprite Kit
placeholder
Sprite Kit
!
1. SpaceshipScene.m createSceneContents SKSpriteNode *spaceship = [self newSpaceship];
spaceship.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)-150)
[self addChild:spaceship];
2. newSpaceship - (SKSpriteNode *)newSpaceship
{
SKSpriteNode *hull= [[SKSpriteNode alloc] initWithColor:[SKColor grayColor] size CGSi
SKAction *hover= [SKAction sequence:@[
[SKAction waitForDuration:1.0]
[SKAction moveByX:100 y:50.0 duration:1.0]
ios原生游戏开发
[SKAction waitForDuration:1.0]
[SKAction moveByX:-100.0 y:-50 duration:1.0]];
[hull runAction:[SKAction repeatActionForever:hover];
return hull;}
” ” ”
”
)
client
3. newSpaceship SKSpriteNode *light1= [self newLight];
light1.position = CGPointMake(-28.0 6.0);
[hull addChild:light1];
SKSpriteNode *light2= [self newLight];
Light2.position = CGPointMake(28.0 6.0);
[hull addChild:light2];
4. newLight
- (SKSpriteNode *)newLight
ios原生游戏开发
{
SKSpriteNode *light = [[SKSpriteNode alloc] initWithColor:[SKColor yellowColor] size:C
SKAction *blink= [SKAction sequence:@ [
[SKAction fadeOutWithDuration:0.25]
[SKAction fadeInWithDuration:0.25]];
SKAction * blinkForever = [SKAction repeatActionForever:blink];
[light runAction:blinkForever];
return light;
}
。
Sprite Kit
。
f !
1. newSpaceship
ios原生游戏开发
hull.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:hull.size];
2. newSpaceship hull.physicsBody.dynamic = NO;
。
3. createSceneContents SKAction * makeRocks = [SKAction sequence:@ [
[SKAction performSelector:@selector(addRock) onTarget:self]
[SKAction waitForDuration:0.10 withRange:0.15]
]];
[self runAction:[SKAction repeatActionForever:makeRocks];
”
4. addRock static inline CGFloat skRandf() {
return rand()/(CGFloat)RAND_MAX;
}
ios原生游戏开发
static inline CGFloat skRand(CGFloat low, CGFloat high) {
return skRandf()*(high - low) + low;
}
- (void)addRock {
SKSpriteNode *rock = [[SKSpriteNode alloc] initWithColor [SKColor brownColor] size:CG rock.position = CGPointMake(skRand(0, self.size.width),self.size.height-50);
= @“rock”;
rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
esPreciseCollisionDetection = YES;
[self addChild:rock];
}
。
。 。
, Sprite Kit
5. didSimulatePhysics
- (void)didSimulatePhysics
ios原生游戏开发
{
[self enumerateChildNodesWithName:@“rock” usingBlock:^(SKNode *node, BOOL *stop){ if (node.position.y <0)
[node removeFromParent];
}]; }
Sprite Kit
OS X OS X
delegate 、
、 。
!!
正在阅读:
Sprite Kit编程指南08-18
外貌作文之写金桔外貌的作文05-21
2017年河北省保定市高考数学二模试卷(理科)含答案05-18
2016-2022年中国污水处理行业集中度调查及十三五投资价值评估报05-26
这件事真让我惭愧作文500字07-14
基于PLC的自动扶梯控制系统设计(本科毕业优秀论文)07-02
读《中国医德》有感11-01
首批28个新能源汽车试点城市推广计划全览06-01
钓鱼真有趣作文700字06-23
- 梳理《史记》素材,为作文添彩
- 2012呼和浩特驾照模拟考试B2车型试题
- 关于全面推进施工现场标准化管理实施的通知(红头文件)
- 江西省房屋建筑和市政基础设施工程施工招标文件范本
- 律师与公证制度第2阶段练习题
- 2019-2020年最新人教版PEP初三英语九年级上册精编单元练习unit6训练测试卷内含听力文件及听力原文
- 小升初数学模拟试卷(十四) 北京版 Word版,含答案
- 认识创新思维特点 探讨创新教育方法-精选教育文档
- 00266 自考 社会心理学一(复习题大全)
- 多媒体在语文教学中的运用效果
- 派出所派出所教导员述职报告
- 低压电工作业考试B
- 18秋福建师范大学《管理心理学》在线作业一4
- 中国铝业公司职工违规违纪处分暂行规定
- 13建筑力学复习题(答案)
- 2008年新密市师德征文获奖名单 - 图文
- 保安员培训考试题库(附答案)
- 银川市贺兰一中一模试卷
- 2011—2017年新课标全国卷2文科数学试题分类汇编 - 1.集合
- 湖北省襄阳市第五中学届高三生物五月模拟考试试题一
- 编程
- 指南
- Sprite
- Kit