search instagram arrow-down

Archives

Critter Crosshair Defense: CloudKit Setup

The setup for this tutorial involves defining record types (i.e. the schemas for your data models) and uploading the relevant game assets and configuration data.  The first recordType that is relevant to this project is CharacterABC (the letter suffix is used for namespacing and could just as easily be prepended to the beginning of the word).  This recordType basically stores all of the data that will be necessary for configuring the sprite node of a character (e.g. the name of the node, anchor point, zPosition, zRotation, defaultTexture, lightingBitMask, shadowCastBitMask, shadowedBitMask).

characterABC

Another important recordType is PhysicsConfiguration, which is fairly self-explanatory and stores all of the data needed to configure the physics body for each game character.  Hence, it has record fields for the bitmask variables that will be used to configure the collision/contact properties of the physics body (i.e. categoryBitMask, collisionBitMask, contactBitMask), boolean properties usually associated with a SpriteKit physics body  (i.e. affectedByGravity, allowsRotation, isDynamic) and other decimal values for such properties as linearDamping, angularDamping, angularVelocity, velocity charge, density, friction, restitution).  In addition, the physics configuration has a CKReference field (i.e. a reference to a CharacterABC game object, which is the game character for which the physics properties in question are being defined).

physicsConfiguration

The other recordType is AnimationTextureABC, which is a wrapper for a single image file that is combined with other images to generate the series of textures needed for a specific animation.  It has record fields for order (i.e. the order in which the texture occurs in the series of textures used to generate an animation), orientation (i.e. left-facing or right-facing), animationName (the name of the texture animation in which this image will be used to generate a texture animation), and character (i.e. a reference to the game character  with which this animation texture is associated).

animationTextureABC

Please note that since CloudKit does not have Boolean values, Int64 fields are used to represent Boolean values instead, where “1” is “true” and “0” is “false.”  Also, custom enum types are represented via the corresponding rawValue type – hence, the “Orientation” enum, as defined in the project, has an integer rawValue and is represented in the record type with an Int64 record field.

Now that the record types are defined, it’s necessary to upload the relevant records and character data. Below are the records for all the characters in the game:

characterRecords

Each of these records corresponds to one of the five characters in the game, shown below:

In addition, the video screenshot below shows how the data is entered for an example character, in this case “wingman:”

You can create additional characters as needed. Each character has a to-one relationship with a PhysicsConfiguration, which is why each PhysicsConfiguration has a reference to a character object, and to-many relationship to the animation textures, whereas a given texture animation can only belong to a single game character.

Advertisements
%d bloggers like this: