NPC's or Non-Player Characters

Get some help from friends on the way.

No RPG is complete without some NPC’s or Non-Player Characters roaming around your game to help the player figure out where to go, or what’s going on. NPC’s in the kit will walk randomly around (so they can have 4 directions of artwork), and can include random lines of text to initially speak to the player on contact, and then random secondary (reminder) text to speak when the character re-contacts the same NPC.

Here’s a look at the properties for Villager in the Grassland demo level in the kit…

Before we go into discussing each property, lets look at how to add an NPC to the level.

Add an initial image for the NPC to the Asset Catalog. As usual, if you drag and drop in images to Xcode with the @2x and @3x extensions they’ll automatically find their way into the appropriate 2x and 3x slots. And the base name of the source images is used as the asset name (VillagerBase)

If you include animation sequences for the NPC walking, this base image is mainly used for sizing the character in the scene.

Next add a new Color Sprite to your level scene and texture it with the image you added. You’ll also want to Name it now too. Remember this name will match exactly the dictionary name in the NPC dictionary in the property list.

Finally, you must set a Custom Class of NonPlayerCharacter. 

You’re ready to go!

NPC Properties

  • Animation – this dictionary contains the Front, Back, Left and Right keys, each with String values that match the name of a saved action. Actions can be saved in any SKS file, but in the kit, we have a dedicated Actions.sks file for all the saved actions.  For example,you can save a sequences of animated textures, so for the NPC we would save 4 different actions, one for each directional walking sequence. To watch a video on how to save actions to an SKS file in Xcode, click here.
  • InitialSpeech – This can be an Array of String values or a single String value property. If you set this to an Array type and include multiple String items (as seen in the example below), you can randomize the text that the NPC initially says to the character. The kit will remember if you’ve previously encountered an NPC and subsequent times you contact them, will display text from the ReminderSpeech property

  • ReminderSpeech – just like the InitialSpeech property, this can be an Array or single String value. Use this property to set reminder speech when the player re-encounters the same NPC.
  • Icon – this is the name of an image in the asset catalog to show when the player contacts the NPC. This will accompany the previous two properties, so the user sees some dialogue and icon of who they are speaking to (or whatever you like). See the top image on this page for an example.
  • InfoTime – the amount of time to wait before fading out the speech text after the player has finished contacting the NPC.
  • CollidableWithPlayer – a Boolean property, YES means the NPC can collide with the player, NO means the player could walk through the NPC.
  • CollidableWithItems – a Boolean property, YES means the NPC can collide with Items (those with the custom class of WorldItem), NO means the NPC would be able to walk through Items.
  • Distance – A number value for how far the NPC will walk.
  • WalkTime – A number value for how long the NPC will walk for.
  • InitialSound – A string value with the full file name (including file extension) for a sound to play when the NPC and player initially contact each other.
  •  ReminderSound – A string value with the full file name (including file extension) for a sound to play when the NPC and player contact each other after the initial meeting. The kit won’t play this sound until at least 10 seconds after the initial sound plays.