SpriteKit의 여섯 캐릭터를 학급화하고 무적의 시간을 갖도록 하겠습니다.
데미지를 입은 몇 초간 깜박임, 무적 시간 달성
그래서 우선 기본 캐릭터를 만드는 반.
import Foundation
import SpriteKit
class BaseUnit: SKSpriteNode {
var hitPoint : Int = 0
var attackPoint : Int = 0
}
다음은 플레이어가 조작하는 용의 레벨에 따라 제작됩니다.status 속성을 설정합니다.import Foundation
import UIKit
import SpriteKit
class DragonUnit: BaseUnit {
var status : String = ""
override init() {
let texture = SKTexture(imageNamed: "charImage1.png")
super.init(texture: texture, color: nil, size: texture.size())
hitPoint = 40
}
required override init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
또 다른 적의 반을 만들었어요.import Foundation
import UIKit
import SpriteKit
class EnemyUnit: BaseUnit {
override init() {
let random : Int = Int(arc4random() % 4)
var color : UIColor!
switch random {
case 0 :
color = UIColor.redColor()
case 1 :
color = UIColor.yellowColor()
case 2 :
color = UIColor.greenColor()
case 3 :
color = UIColor.brownColor()
default :
color = UIColor.blueColor()
}
super.init(texture: nil, color: color, size: CGSizeMake(50, 50))
hitPoint = 0
attackPoint = 10
}
required override init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
게임화면 클래스에서 드래곤을 호출하는 곳을 수정했습니다. override func didMoveToView(view: SKView) {
//キャラ画像
// let dragonImage = UIImage(named: "charImage1.png")
// let texture = SKTexture(image: dragonImage!)
// let dragon = SKSpriteNode(texture: texture)
let dragon = DragonUnit()
충돌 시 이벤트 중 적과 용이 충돌했을 때 수정 //衝突時のイベント
func didBeginContact(contact: SKPhysicsContact) {
// キャラと敵が衝突した場合
if((CollisionMember.Dragon.toInt() == contact.bodyA.categoryBitMask ||
CollisionMember.Dragon.toInt() == contact.bodyB.categoryBitMask ) &&
(CollisionMember.Enemy.toInt() == contact.bodyA.categoryBitMask ||
CollisionMember.Enemy.toInt() == contact.bodyB.categoryBitMask)){
// ダメージを点滅で表現
let dragon: DragonUnit = childNodeWithName("dragon") as DragonUnit
if (dragon.status != "damaged"){
dragon.status = "damaged"
let enemy: EnemyUnit = childNodeWithName("Enemy") as EnemyUnit
dragon.hitPoint -= enemy.attackPoint
// 点数を減算
// let myPointLabel: SKLabelNode = childNodeWithName("pointLabel") as SKLabelNode
// myPointLabel.text = String(myPoint)
//
if(dragon.hitPoint > 0){
myLabel.text = "Ouch!"
// ドラゴンの点滅
let blank = SKAction.sequence([SKAction.fadeOutWithDuration(0.2),
SKAction.fadeInWithDuration(0.2)])
let repeat = SKAction.repeatAction(blank, count: 10)
dragon.runAction(repeat, completion:{
dragon.status = ""
self.myLabel.text = "Hello World"
})
} else {
myLabel.text = "Game Over!Good bye"
}
}
// 敵の方を消す
if(contact.bodyA.categoryBitMask == CollisionMember.Enemy.toInt()){
contact.bodyA.node?.removeFromParent()
} else {
contact.bodyB.node?.removeFromParent()
}
}
부딪혔을 때 status에damaged를 설정합니다.깜빡이는 이벤트가 끝날 때 status에 공백을 설정하기 전에 피해를 입지 않습니다.피해를 입으면 적의 공격력이 감소됩니다.0 이하면 게임이 끝났지만 현재 대응하는 이벤트가 없습니다.다음은 시작화면과 끝화면을 표시하는 곳에 도전한다.
또 이번에는 다른 용의 이동 방법과 자동 화염 분출을 변경해 무작위로 적의 캐릭터가 나오는 것 이외에 적을 격파하면 득점을 하는 할애다.
Reference
이 문제에 관하여(SpriteKit의 여섯 캐릭터를 학급화하고 무적의 시간을 갖도록 하겠습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/rnsm504/items/7980ccd30a28c7b69858텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)