set zPosistion on all Nodes
update host and peer Label Nodes
This commit is contained in:
parent
bf8ce0c477
commit
b2f84bc3f4
@ -14,7 +14,6 @@ class DefaultBaseComponent: GKComponent {
|
||||
var spriteNode: BaseNode
|
||||
var labelNode : SKLabelNode?
|
||||
|
||||
|
||||
init(texture: SKTexture, position: CGPoint) {
|
||||
spriteNode = BaseNode(texture: texture, size: CGSize(width: 80, height: 80))
|
||||
spriteNode.position = position
|
||||
@ -26,7 +25,7 @@ class DefaultBaseComponent: GKComponent {
|
||||
labelNode?.verticalAlignmentMode = .center
|
||||
labelNode?.fontName = "AvenirNext-Bold"
|
||||
labelNode?.fontSize = 15
|
||||
labelNode?.position = CGPoint(x: position.x + 20 , y: position.y - 40 )
|
||||
labelNode?.position = CGPoint(x: position.x + 30 , y: position.y - 50 )
|
||||
labelNode?.zPosition = spriteNode.zPosition - 1
|
||||
}
|
||||
|
||||
|
@ -18,43 +18,34 @@ class PlayerInfoComponent: GKComponent {
|
||||
|
||||
var peerLabel:SKLabelNode
|
||||
var peerUnitsLabel:SKLabelNode
|
||||
|
||||
|
||||
|
||||
var host: GKPlayer?
|
||||
var peer: GKPlayer?
|
||||
|
||||
init(size: CGSize) {
|
||||
var host: String?
|
||||
var peer: String?
|
||||
|
||||
if MatchmakingHelper.sharedInstance.isServer {
|
||||
host = GKLocalPlayer.local.displayName
|
||||
peer = MatchmakingHelper.sharedInstance.mpMatch?.players[0].displayName
|
||||
|
||||
host = GKLocalPlayer.local
|
||||
peer = MatchmakingHelper.sharedInstance.mpMatch?.players[0]
|
||||
} else {
|
||||
host = MatchmakingHelper.sharedInstance.mpMatch?.players[0].displayName
|
||||
peer = GKLocalPlayer.local.displayName
|
||||
|
||||
host = MatchmakingHelper.sharedInstance.mpMatch?.players[0]
|
||||
peer = GKLocalPlayer.local
|
||||
}
|
||||
|
||||
|
||||
hostLabel = SKLabelNode(text: host)
|
||||
hostUnitsLabel = SKLabelNode(text: "500")
|
||||
peerLabel = SKLabelNode(text: peer)
|
||||
hostLabel = SKLabelNode(text: host?.displayName)
|
||||
hostUnitsLabel = SKLabelNode(text: "500" )
|
||||
peerLabel = SKLabelNode(text: peer?.displayName)
|
||||
peerUnitsLabel = SKLabelNode(text: "500")
|
||||
|
||||
super.init()
|
||||
|
||||
hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95)
|
||||
hostLabel.horizontalAlignmentMode = .left
|
||||
|
||||
peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95)
|
||||
peerLabel.horizontalAlignmentMode = .right
|
||||
|
||||
hostUnitsLabel.position = CGPoint(x: size.width * 0.05, y: size.height * 0.9)
|
||||
peerUnitsLabel.position = CGPoint(x: size.width * 0.95, y: size.height * 0.9)
|
||||
|
||||
setColor(labelNodes: [hostLabel,hostUnitsLabel,peerLabel,peerUnitsLabel])
|
||||
}
|
||||
|
||||
func update(){
|
||||
hostUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: host!))"
|
||||
peerUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: peer!))"
|
||||
}
|
||||
|
||||
func setColor(labelNodes: [SKLabelNode]) -> Void {
|
||||
|
@ -37,10 +37,13 @@ class Base: GKEntity{
|
||||
addComponent(TeamComponent(team: team!, player: player!, position: spritePos))
|
||||
self.unitCount = 500
|
||||
}
|
||||
|
||||
if ownershipPlayer == GKLocalPlayer.local {
|
||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(unitCount)"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func doPlayerMoveTypeToBase(base: Base, playerMoveType: PlayerMoveType, units: Int) -> [GKEntity]{
|
||||
base.changeOwnership = true
|
||||
base.ownershipPlayer = self.ownershipPlayer
|
||||
|
@ -150,13 +150,18 @@ class EntityManager {
|
||||
let snapBase = self.getSnapshotBaseById(baseId: base.baseID, snapshotModel: snapshotModel)
|
||||
var getOwnerBySnapBase: GKPlayer? = nil
|
||||
base.unitCount = snapBase.unitCount
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)"
|
||||
|
||||
if snapBase.ownership != nil {
|
||||
getOwnerBySnapBase = MatchmakingHelper.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
||||
} else {
|
||||
entity.removeComponent(ofType: TeamComponent.self)
|
||||
}
|
||||
if getOwnerBySnapBase != nil {
|
||||
if getOwnerBySnapBase == GKLocalPlayer.local {
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)"
|
||||
}else {
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = ""
|
||||
}
|
||||
base.changeOwnership = true
|
||||
base.ownershipPlayer = getOwnerBySnapBase
|
||||
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||
@ -174,6 +179,9 @@ class EntityManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHUD()?.component(ofType: PlayerInfoComponent.self)?.update()
|
||||
|
||||
}
|
||||
|
||||
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
|
||||
@ -254,8 +262,6 @@ class EntityManager {
|
||||
return entities.filter{$0 is HUD}[0]
|
||||
}
|
||||
|
||||
|
||||
|
||||
func getSnapshotModel() -> SnapshotModel {
|
||||
let bases = entities.filter{$0 is Base}
|
||||
var snapBase: [BaseEntityModel] = []
|
||||
@ -271,4 +277,13 @@ class EntityManager {
|
||||
func getTimer() -> TimerComponent {
|
||||
return entities.filter{$0 is HUD}[0].component(ofType: TimerComponent.self)!
|
||||
}
|
||||
func getUnitSum(by player: GKPlayer) -> Int{
|
||||
let bases = getBasesByPlayer(for: player)
|
||||
|
||||
var sum = 0
|
||||
for base in bases {
|
||||
sum += base.unitCount
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ class HUD: GKEntity {
|
||||
anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30))
|
||||
|
||||
addComponent(PlayerInfoComponent(size: size))
|
||||
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
@ -46,7 +46,7 @@ class GameScene: SKScene{
|
||||
isMoveTouch = false
|
||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBase!.position
|
||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBase!.position
|
||||
|
||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.labelNode?.position = CGPoint(x: currentDraggedBase!.position.x + 30, y: currentDraggedBase!.position.y - 50)
|
||||
addAttackDetails(touchLocation: touchLocation)
|
||||
}
|
||||
else {
|
||||
@ -152,6 +152,7 @@ class GameScene: SKScene{
|
||||
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50)
|
||||
}
|
||||
|
||||
func showNearestBases(base: Base){
|
||||
|
Loading…
Reference in New Issue
Block a user