impf. EntityManager
This commit is contained in:
parent
21b7fc00f7
commit
6127f89e78
@ -18,6 +18,7 @@
|
||||
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; };
|
||||
11036111244B3D6A008610AF /* MenuScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 11036110244B3D6A008610AF /* MenuScene.sks */; };
|
||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; };
|
||||
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; };
|
||||
11738A3B24508F68004426F1 /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11738A3A24508F68004426F1 /* Unit.swift */; };
|
||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
@ -57,6 +58,7 @@
|
||||
110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
11036110244B3D6A008610AF /* MenuScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = MenuScene.sks; sourceTree = "<group>"; };
|
||||
11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
|
||||
116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = "<group>"; };
|
||||
11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = "<group>"; };
|
||||
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
@ -123,6 +125,7 @@
|
||||
110360DF244B101B008610AF /* Assets.xcassets */,
|
||||
110360E1244B101B008610AF /* LaunchScreen.storyboard */,
|
||||
110360E4244B101B008610AF /* Info.plist */,
|
||||
116060F6245C57D2004E5A36 /* EntityManager.swift */,
|
||||
);
|
||||
path = GoldWars;
|
||||
sourceTree = "<group>";
|
||||
@ -293,6 +296,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
110360D9244B101A008610AF /* GameScene.swift in Sources */,
|
||||
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
|
||||
11738A3B24508F68004426F1 /* Unit.swift in Sources */,
|
||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
||||
|
37
GoldWars/GoldWars/EntityManager.swift
Normal file
37
GoldWars/GoldWars/EntityManager.swift
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// EntityManager.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Aldin Duraki on 01.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
import GameplayKit
|
||||
|
||||
class EntityManager {
|
||||
|
||||
var entities = Set<GKEntity>()
|
||||
let scene: SKScene
|
||||
|
||||
init(scene: SKScene) {
|
||||
self.scene = scene
|
||||
}
|
||||
|
||||
func add(_ entity: GKEntity) {
|
||||
entities.insert(entity)
|
||||
|
||||
if let spriteNode = entity.component(ofType: SpriteComponent.self)?.node {
|
||||
scene.addChild(spriteNode)
|
||||
}
|
||||
}
|
||||
|
||||
func remove(_ entity: GKEntity) {
|
||||
if let spriteNode = entity.component(ofType: SpriteComponent.self)?.node {
|
||||
spriteNode.removeFromParent()
|
||||
}
|
||||
|
||||
entities.remove(entity)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user