In the third installment of our SceneKit With Swift tutorial, you’ll animate your Geometry Fighter game while learning about SceneKit physics.
By Chris Language.
To color your random object, you modify materials on geometry; this line gets the first available material of geometry and sets the diffuse property’s contents to a random UIColor. The random() method on UIColor is another helper defined as an extension inside the game utilities.
Note: The takeaway here is that you can assign a UIColor to the diffuse property’s content in order to change the object’s color.
Finally, build and run your game to see a beautifully colored object:
Wouldn’t it be neat if you could spawn more than one object? You’ll fix this…in the next part of this series! :]
Where to Go From Here?
You’re making excellent progress, and you’re more than halfway through your first SceneKit game! If you’re flexible (unlike me), give yourself a pat on the back.
At this point, you should keep reading on to the fourth part of this tutorial series, where you’ll learn how to make geometry spawn over time using the Scene Kit render loop.
If you’d like to learn more, you should check out our book 3D iOS Games by Tutorials. The book teaches you everything you need to know to make 3D iOS games, by making a series of mini-games like this one, including a games like Breakout, Marble Madness, and even Crossy Road.
In the meantime, if you have any questions or comments about this tutorial, please join the forum discussion below!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.