Game Development Reference
In-Depth Information
Creating the New Player CCB
Let's start with the basics. Right-click the
Prefabs
folder in SpriteBuilder to add a new
file. Name the document
PlayerSoftBody.ccb
, and change its type to
Sprite
before creat-
ing it.
In the new
PlayerSoftBody.ccb
, select the root node, and on the
Item Properties
tab
change the Sprite frame to
SpriteSheets/Global/player.png
. Then switch to the
Item Code
Connections
tab and enter
SoftBodyDrawNode
as the custom class of the root node.
For this and the following steps, it's best to have physics debug drawing enabled. This
will be very educational because you can observe the behavior of the otherwise invisible
parts of the soft body—both circumference bodies and the joint connections. Open
GameScene.ccb
, and select its root node. On the
Item Properties
tab, you'll find the famil-
iar
_drawPhysicsShapes
setting. Set its value to
1
to enable physics debug drawing.
Now open
Level1.ccb
, and repeat the following steps for any other Level CCB file you
want to play with the new soft-body player:
1.
Locate the player object in the level and select it. Use the Timeline in case
selection on the stage proves difficult. On the player's
Item Properties
tab,
change the
CCB File
property from
Prefabs/Player.ccb
to
Prefabs/Player-
SoftBody.ccb
. This level will then use the new soft-body player.
2.
In Xcode, right-click the
Source
group and select
New File
. Create yet an-
other Objective-C class, and name it
SoftBodyDrawNode
. Be sure to set the
subclass to
CCSprite
, since the
SoftBodyPlayer.ccb
is a CCB file of type
Sprite
. For now, leave the class empty as is—you only need the class right
now to avoid
CCBReader
errors when testing the app.
You can test it out by publishing and running the app. If the player in the specified level
appears frozen in place, you've correctly replaced it. The player won't move at the mo-
ment because it doesn't have physics enabled.
Adding Center and Circumference Bodies
This new player needs a soft outer shell, so to speak. Instead of using one large circle
shape, you now have to approximate the circular shape using several smaller bodies, also
with a circle shape. I call these the
circumference bodies
. For the size of this player, a total
of eight circumference bodies are needed, plus an additional body at the center.
Search WWH ::
Custom Search