###OC
-系列
- 本系列Demo 是对SceneKit框架的解读与练习,具体知识来自于<3D iOS Games by Tutorials>一书和许海峰大神的系列文章.这里提供OC版的学习笔记和系列Demo
- 学习笔记地址
- OC代码地址
###Swift
--系列
- Hello SceneKit与渲染循环学习笔记_之_Hello SceneKit
- Hello SceneKit与渲染循环学习笔记_之_physics物理效果
- Hello SceneKit与渲染循环学习笔记_之_Render Loop渲染循环
关键代码:
- 1
/**
创建粒子
@param color 粒子的颜色
@param geometry 粒子发射器
@return
*/
- (SCNParticleSystem *)creatParticleSystemWithColor:(UIColor *)color geometry:(SCNGeometry *)geometry{
// 创建粒子 直接使用系统的粒子 具体创建在笔记中有介绍
SCNParticleSystem *particleSystem = [SCNParticleSystem particleSystemNamed:@"Rain.scnp" inDirectory:nil];
// 设置粒子颜色 保证粒子的颜色与发射器几何体的颜色是一致的
particleSystem.particleColor = color;
// 指定发射器的形状 此处将传来的几何体作为粒子的发射器
particleSystem.emitterShape = geometry;
return particleSystem;
}
- 2
// 5.0创建一个粒子
SCNParticleSystem * parrticleSystem = [self creatParticleSystemWithColor:color geometry:geometer];
// 5.1 将该粒子 添加到节点上 有时候会发现 粒子未出现在屏幕中 可能的原因之一是 粒子的大小问题(我就遇到了)
[geometerNode addParticleSystem:parrticleSystem];
关键代码:
// 1.0获取触摸点
UITouch *touch = [touches allObjects].firstObject;
// 2.0触摸点 在scnView的位置
CGPoint location = [touch locationInView:self.scnView];
NSArray *hitResultsAray = [self.scnView hitTest:location options:nil];
// 4.0取出SCNHitTestResult
SCNHitTestResult *hitResults = [hitResultsAray firstObject];
if (hitResultsAray.count) [self delewithLifeAndClickNum:hitResults.node];