设为首页 加入收藏

TOP

运用GamePlayKit的GKEntity及GKComponent 的iOS游戏开发实例(二)
2019-09-03 02:41:01 】 浏览:313
Tags:运用 GamePlayKit GKEntity GKComponent iOS 游戏 开发实例
[SKTexture] let spriteComponent: SpriteComponent init(entity:GKEntity,textures:[SKTexture]) { self.spriteComponent = entity.component(ofType: SpriteComponent.self)! self.textures = textures super.init() } // 翅膀拍动 func startAnimation(){ let flyAction = SKAction.animate(with: textures, timePerFrame: TimeInterval(0.02)) let repeatAction = SKAction.repeatForever(flyAction) spriteComponent.node.run(repeatAction) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }

在场景GameScene加入管理器Entity对象

func setupEntityComponent(){
        let penguin = PenguinEntity(imageName: "penguin01") // 企鹅属于worldNode的子层级; let penguinNode = penguin.spriteComponent.node penguinNode.position = CGPoint(x: 320, y: 500) penguinNode.zPosition = 5 worldNode.addChild(penguinNode) // penguin有移动的功能 penguin.moveComponent.startWobble() // 有拍打翅膀的功能 penguin.animationComponent.startAnimation() } 

以上就是应用GKEntity来管理三个组件GKComponent的运用实例。

源码传送门:https://github.com/apiapia/FlyingPenguinSpriteKitGameTutorial
更多游戏教学:http://www.iFIERO.com

补充:英文够好的话,建议上苹果的官网看看 GameplayKit的案例代码:

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS Swift WisdomKeyboardKing 键.. 下一篇iOS资源大全中文版

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目