Wednesday, January 20, 2016

Day 63

Core Motion and SpriteKits


Onto the third straight day of Hackathons, we are using Core Motion (using iPhone's gyroscopes and accelerometer). Naturally I thought of making games that requires tilting. To build an app like this, Xcode actually has a game development framework. We first import the Core Motion library as well as the SpriteKit framework. Core Motion allows us to use the accelerometers and gyroscope capabilities of the iPhone. So the first thing David and I did was to write a basic app that tells us the x/y/z coordinate tilt of the phone to make sure we understand how it works.

The next part was utilizing Sprite Kit. Instead of a storyboard for our UI design, we have a .sks file that's a scene for the game. We just added a picture of an asteroid and a built in object of a spaceship. The project design is whatever data we get from the Core Motion, we want to affect our game scene. Core motion is utilized by instantiating a motion manager class. We first got to move the spaceship around in the directions that we wanted via accelerometers. Now the second part is messing around with the velocity of our spaceship. 

Once we go the physics and movement of our spaceship down, we created asteroids. At this point, we don't know what the objective of our game is, we just wanted to see how to make stuff. Now, we would populate asteroids and give them a random direction and velocity. Now, we need a collision detector function that would detect collisions and alter the velocity and direction of both the spaceship and asteroid. The cool thing about this is that there are already methods to do this for you via contactTestBitMask. That function tests for if two bodies enter a shared space and run the logics of what angles and speed the two objects will have.

No comments:

Post a Comment