Proper scenekit architecture for multi level/screen games

泪湿孤枕 提交于 2019-12-23 04:52:52

问题


I'm new to scenekit, so when I started my first project I noticed it's slightly different from spritekit. Although not ideal, I used to use 1 gameviewcontroller and 1 gamescene in spritekit to code my entire game. (YES, this includes a menu, game/levels, settings, etc...)

I'm now wondering since I'm using SCNScenes (which are just loaded from the viewcontroller), I do not want my 1 view controller to be swamped with code. What is the best way to layout a game? Should i have 1 viewcontroller per SCNScene? (switching to a different view controller for: main menu, game level 1, game level 2, game level 3, game over, settings, etc..)

This may not have been worded perfectly, but i appreciate the help!

Aidan


回答1:


My typical layout for games with multiple levels, maps, interactive game play menus:

MainMenuVC SelectLevelVC, SelectMapVC, etc.

GameVC (Hud, score, in-game menus), DefenseVC (like an overlay, choose weapon)

EndWaveVC, EndGameVC

GameControl() - Timers, array iteration, check wave completed, nextWave, cleanup, etc.

Data - shared instance (arrays, switches) for data shared between VC’s and game objects

BaseObjects such as (defenses, explosions, sounds, movement, targeting)

GameNodes (all node creation and storage, model loading, particle loading, camera, lights)

I landed here though many iterations. There are some tradeoffs, but by separating VC’s from data and scenekit things can stay pretty clean. It also enhances the ability to do threading and timers in only a few places when needed.

The sharedInstance of Data allows game objects to iterate through arrays to find targets and objects, such as a defense trying to find an enemy and vice versa. When game objects need to start talking to each other, this is usually where game design starts going off the tracks. So, I iterate loops via timers in GameControl, sharing Data, and that keeps it pretty clean. Since I’m doing loops in one place, I can avoid trampling other objects while they are updating and also get some clean measurements of timing and control FPS.

Hope that helps.



来源:https://stackoverflow.com/questions/58103566/proper-scenekit-architecture-for-multi-level-screen-games

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!