因為pause需要載入時間的關係,
跑去gamesald官方論壇找了一堆資料,
發現了一個老外寫的"31 Optimization Tips"(31個優化gamesalad開發遊戲的tip),
實際花了些時間看完後覺得非常有幫助,
可以有效的優化gamesalad開發的遊戲執行效能,
當然這也不是萬靈丹,
不要期待做到其中的一兩條或全部做到就能讓遊戲完美運行,
畢竟開發遊戲的變數很多,
有可能即使全部做到但是結果卻仍然差強人意,
就還是要想別的辦法,
只能說這些tip盡量去滿足,
對遊戲的效能及載入時間會有幫助的。
原文連結(英文),底下有其他老外的討論也有很多值得一看的建議,
31 Optimization Tips
底下針對我覺得是比較重要的部份,
並且容易被忽略的部份簡單做一下中文翻譯,
Hello GameSalad Community,
One thing that I know we all care about is performance. Even with the new LUA-Free engine coming soon, we would all still like our games to be fast now. I have made a list of 31 optimization tips to use in your games that I have collected after searching through the forums, coming up with some myself, and exploring GameSalad help websites. I did this so you only needed to go to one thread instead of taking the amount of time it took me to find it all.
Here it is.
1. Uncheck "Preload Art" on as many actors as you can.
盡可能取消actor裡"Preload Art"(預載圖片)的選取
2. Uncheck "Movable" for every actor that doesn't have the "Accelerate", "Change Velocity", "Collide", "Move", "Move to", or any of the rotate behaviors.
取消不需要進行移動或是物理引擎運算("Accelerate", "Change Velocity", "Collide", "Move", "Move to")的actor裡"Movable"的選取
3. Use the "Interpolate" behavior instead of the "Move", "Move to", and "Change Size" behaviors whenever possible.
盡可能使用Interpolate(插值)而不要用Move或Move to,Change Size等function
4. Use the "Rotate" behavior instead of animations.
5. Turn every attribute under the physics tab in the actor editor to 0 on actors who do not need it.
關掉不需要的物理參數如果你用不到的話就設為0(預設通常不是0)
6. If the actor is not going to be seen, change their "Visible" attribute to false.
如果actor不需要被看見,
直接把Visble設為false(我之前都習慣設alpha=0,比較耗資源)
7. Instead of using the "Change Image" behavior, use "Change Attribute" and change the self.Image to the desired image's name.
如果要更換actor裡的圖片的話,
使用Change Attribute裡去執行 change the "self.Image",
不要直接用Change Image這個behavior
8. Images should be the same size as the actor using them and double the size if you are using Resolution Independence.
9. Change any image that is about 10 pixels more than 8, 16, 32, 64, 128, 256, 512, or 1024 to which ever of these numbers are closest.
這個很重要!
保存你的圖片尺寸為8,16,32,64,128,256,512或1024的寬或高,
保存你的圖片尺寸為8,16,32,64,128,256,512或1024的寬或高,
保存你的圖片尺寸為8,16,32,64,128,256,512或1024的寬或高,
因為很重要所以要說三次!(最近好流行這個梗^^")
如果它們很接近比如寬或高是130,
那在系統中會直接判斷它們需要佔用256的資源,
所以寧可稍微縮小2px,
視覺上感覺不出差別,
但對於系統使用該張圖片佔用的資源就直接從256降為成128!
10. If an image file is large or is a background, have the actor that uses the image use the suggestion in number 7 instead of having the actor start initially with the image.
11. All images should be 72dpi.
12. Save all images as PNG-24 or PNG-8
13. Save all images as PNG-8 unless they have any transparent or translucent object in them.
14. Don't use the color changer within GameSalad unless necessary.
15. All images should be divisible by 4.
16. Make sure your image creator is set to 8-bits/channel.
17. Don't use the "Display Text" behavior wherever possible.
18. Try not to use so many global attributes and use tables wherever possible.
少用全域變數,盡量多把全域變數放在table裡.
19. Try not to use timers. See http://forums.gamesalad.com/discussion/44707/timers-are-for-chumps-gs-optimization-tips/p1
盡量少用timer,有很多替代方式,
這裡提到的是參考另一個討論串不用timer的做法,也很值得一讀,
這邊我簡單提一下最常用的需要在幾秒後執行某功能的延遲timer做法,
主要就是用actor內建的time屬性,
同時新增一個actor內的自定變數,比如叫startTime,
功能是當做時間戳記,
當需要使用timer的時候,
就設定startTime to self.time,
埋一個時間戳記在當時的時間,
然後就可以設定當self.time > startTime(時間戳記)+XX秒的時候做你想做的事,
這是最基本的需要在固定時間延遲幾秒的after timer的做法,
因為每個actor都有內建一個會不斷記數的time,
利用這一點去做,
就可以減少timer的使用,
當然還是有非用timer不可的時候,
就盡量能少用就少用。
關於時間戳記還有其他用法這一篇就不詳提。
20. Limit constrains and if you do need to use it, make sure that they are on the top of your code.
如果有用到constrains,記得擺在所有code的最上面最優先執行
21. Make your own pause instead of using the behavior. See http://gshelper.com/stop-motion-on-custom-pause-gamesalad-tutorial/
22. If an actor is not being used again in the same scene, destroy it.
如果actor在場景中不會再被用到就把它destroy掉
23. If you have a game that goes on forever like Jetpack Joyride, Temple Run, or Jay & Silent Bob in Too Fat to Fly, make sure you either move or destroy actors that pass you by using these rules:
Landscape gameplay: If attribute game.MainCharacterPositionX > self.Position.X + (game.Screen.Size.Width/2)+(self.Size.Width/2), then destroy or move.
Portrait gameplay: If attribute game.MainCharacterPositionY > self.Position.Y + (game.Screen.Size.Hight/2)+(self.Size.Hight/2), then destroy or move.
24. You do not have to recycle actors that would be destroyed in the first place, like bullets.
25. Use music at your own risk because it will decrease performance.
26. Delete all unused rules, groups, behaviors, actors, attributes, images, and sounds.
刪除所有用不到的rules, groups, behaviors, actors, attributes, images, and sounds.
27. Don't save more than 3 attributes at once.
不要同時儲存超過3個attributes
28. Don't update all Game Center Achievements/Leaderboards at once unless their is no movement in the scene at that time.
在遊戲靜止畫面的時候在做更新Game Center Achievements/Leaderboards的動作
29. Make an initial scene that looks like your splash screen to load attributes and log in to Game Center
在遊戲啟動的靜止畫面(如show logo)時做登入Game Center的動作
30. If you can, unlock actors to constrain to the actor directly. See: http://gshelper.com/gamesalad-performance-tip-1-2/
如果需要使用constrain的話,
一般的標準做法是會建一個全域變數,
然後先把主actor的變數跟全域變數做constrain,
另一個需要constrain的actor再去跟全域變數constrain,
我也一直是這樣做的,
但這邊提到盡可能的使用actor直接constrain另一個acotor,而不是多透過一個全域變數.
原來可以在場景上直接兩個actor直連constrain!
(這個簡單又好用,但很容易被忽略)
可參考以下影片
31. Test your game using Instruments to see the memory, cpu, frame rate, leaks, battery usage, and a lot more.
After using these all in my game, it runs at more than 60 fps on the original iPad constantly.
gamesalad是一套很好上手方便使用的開發工具,
但是它最大的弱點就是效能很容易爆掉,
導致不是FPS太低就是讀取時間太長,
所以製作的時候要隔外注意手持裝置的系統資源消耗的情形,
盡可能的把各個小細節都處理好以節省資源,
當初讀完這篇,
有些是我自己之前就已經有發現注意到的,
有些則是讓我有"原來還能這樣用?!"的感覺,
非常的受用,
因為製作pause讀取問題而卡製作進度一段時間,
才去更深入的瞭解研究這些細節,
也算是因禍得福的額外收獲吧!
很好的分享,,其它沒有翻譯的要點,是不是相對來說對效能影響比較沒這麼重要呢??
回覆刪除其實每個都是小細節,
刪除每一項都很重要,
只是單一做了某一項的話影響不大,
要累積很多才會有比較明顯的效果,
翻譯出來的是我個人覺得比較容易被忽略的:)