Post not yet marked as solved
Post marked as unsolved with 0 replies, 457 views
Hi,First, I'm sorry for my level of English.I know how to program in swift and I think to know how to use SpriteKit. I try to develop a game (a little bit like Factorio). And after many tests I find myself stuck.I'm afraid I do not use SpritKit properly.Here is my simplified architecture :class GameScene: SKScene{
var g = Data()
override func didMove(to view: SKView) {
print("Hello")
backgroundColor = SKColor.white
let home = Home()
home.crea(G: &g)
addChild(home)
}
override func update(_ currentTime: TimeInterval) {
if(tsomeAction){
let cell = Cell()
cell.crea(G: &g)
addChild(cell)
g.cells.append(cell)
}
if(g.cells.count>0){
for i in 0...g.cells.count-1{
if(g.cells[i].goal == 2){
g.cells[i].UpdateColision(G: &g)
}
if(g.cells[i].goal == 0){
g.cells[i].UpdateGoal(G: &g)
}
else if(g.cells[i].goal == 1){
g.cells[i].UpdateStock(G: &g)
}
else if(g.cells[i].goal == 2){
g.cells[i].UpdateMove(G: &g)
}
}
}
}
}And this is one exemple of func in class Cellfunc UpdateMove(G: inout Data) { // goal 2
var angle = Float()
let dx = goalPoint.x - self.position.x;
let dy = goalPoint.y - self.position.y;
angle = atan2f(Float(dy), Float(dx));
self.zRotation = CGFloat(angle)
self.position = CGPoint(x:self.position.x + cos(self.zRotation) * 1,y:self.position.y + sin(self.zRotation) * 1)
}For me this architecture is realy simple to use. But maybe is not the best way to optimise FPS ?I would like to add some child to the Cells (exemple : the food collected...) But I think it's to heavy to use SKSpriteNode for this. What do you think ?You have to imagine the game with thousands (if possible) "Cells" on the map.