Portals in the Platform Games tvOS and iOS Starter Kit
As of Build 1.4, you can now include a Portals dictionary in each level dictionary. The first level in the demo now looks like this…
Inside are three dictionaries, each with a name that matches a Portal in the level. The arrows in the image below point to two of those Portals….
Portal Setup Checklist
Setting up a Portal in the scene so it can have custom properties is a 3 step process (this assumes the sprite representing your portal is already in the scene).
- Name it! Very important as this name must match exactly the name in the property list. Without the name, the property list won’t know which portal you’re referring to.
- Give it a physics body so it can collide with the character. Note that portals don’t necessarily need to be static doors, they could be anything (bouncing widgets maybe).
- Give it a Custom Class of “Portal”, see the image below for reference.
Portal Properties to go to other levels
Portals can take the players somewhere within the current level or to another level altogether. Before Build 1.4 (and still true) to go to the next level you simply needed to put a sprite in the scene with a Custom Class of “Portal” and the kit would automatically send the player(s) to the next level in the main Levels array (circled in the image below)….
The properties described below, could do that as well, but you can also send players to a new level outside of the main Levels array! So for example, they could go to any level inside of the SecretLevels array (pointed to in the image above).
- Levels – a String value for the name of the Array with the level to go to. For example, “Levels”, “SecretLevels”, etc. This can be whatever you want, just as long as it matches an Array in the property list.
- LevelToLoad – the index, starting at 1, for the level you want to load in that array. For example, 1 is the first level. 2 is the second and so on.
Below you can see some of those properties as they look in the unfolded Dictionary for PortalToSecretLevel….
The demo level in the kit includes a portal on the far left to go to a secret level if the score is over a certain amount (more on that later).
Portal Properties to go somewhere in the current level
Jumping around within the current has some advantages over starting a new level, especially for bonus or secret levels. Because the level maintains it’s current state, enemies will stay dead, past coins / ammo / etc, will stay picked up, and you can even prevent players from going through the same portal twice. Here are the main properties to jump around within the level…
- NodeToMovePlayerTo – The name of a corresponding placeholder (empty) node in the scene to move the player to. For example, “PortalJump” would move the player to the node named “PortalJump”. This actually doesn’t need to be an empty placeholder, it could be any object with the same name.
- NodeToMoveCameraTo – The name of a corresponding placeholder (empty) node in the scene to move the camera to.
- OneTimeUse – A boolean value of YES or NO value to make the portal usable again or just once. Setting YES makes it so the portal can only be used once. By default this is NO.
- MovesBothPlayers – A boolean value of YES or NO to move both players if one player touches the portal. By default this is NO.
Take a look at some of the example properties for PortalToCoins….
Other Portal Properties
- TextureAfterUse – the name of the image asset to use for the portal after entering it.
- ShowLevelPassedImage – A YES or NO value to show the LevelPassed image when entering the portal. By default this is NO. You will only want to set this to YES if going through the Portal completes the current level.
- AddToLevelsPassed – A YES or NO value, similar to the previous property, in that it should only be used if going through the Portal completes the level. Setting this to YES, will increment up an NSUserDefault for the number of levels passed. This number is used in the Home menu (or other menus) to determine if a button can go to an already-passed level. By default this value is NO.
Restricting Access to Portals
You can prevent players from entering portals with the following properties…
- RequiresEnemiesKilledOver – the number of enemies that must be killed before the portal will be active. By default this value is -1, which means the property is ignored. So if you want to essentially shut off this option, but not delete the key, set it to -1.
- RequiresScoreOver – the amount the score must exceed before the portal will be active. By default this value is -1, which means the property is ignored. So if you want to essentially shut off this option, but not delete the key, set it to -1.