標籤:NVisionXR iOS Android Vuforia ARKit
本章節將介紹如何往情境裡添加粒子效果。開啟上一章節的代碼
1、添加標頭檔#import ''NVWorldParticles.h''
2、將粒子的資源檔拖入到UserRes.bundle目錄下(本章節的資源在教程下面有)
3、關於製作粒子檔案,這邊就不做敘述了,請看教程
《NVisionXR引擎基本介紹 http://www.arvrschool.com/read-7381》 )
4、點擊粒子檔案,查看材質名,然後在UserRes.material中配置材質路徑,如:
在onCreate方法中執行個體話粒子,如:
代碼:
NVWorldParticles *snow = (NVWorldParticles *)[[self getWorld] getObjectByName:@"snow"]; if (!snow) { snow = (NVWorldParticles *)[[self getWorld] createObject:PARTICLES objectName:@"snow"]; // 設定粒子指令碼名 [snow setTechnique:@"snow"]; // 設定粒子在空間中座標 [snow setPosition:NVPosition(0.0, 20.0, 0.0)]; }
在onStrat方法中將粒子附加到情境中,如
代碼:
NVWorldParticles *snow = (NVWorldParticles *)[[self getWorld] getObjectByName:@"snow"]; if (snow) { [snow attachTo:self]; // 粒子系統開始播放 [snow start]; }
在onStop方法中將粒子從情境中移除,如
代碼:
NVWorldParticles *snow =(NVWorldParticles *)[[self getWorld] getObjectByName:@"snow"]; if (snow) { // 控制粒子系統結束 [snow stop]; [snow dettach]; }
運行項目,可以看到如效果:
粒子效果就添加成功了,大家可以自己嘗試著使用粒子編輯器做一個酷炫的粒子效果載入到情境中。
NVisionXR_iOS教程八 —— 情境中添加粒子