PS: cocos2d has many good tutorials abroad. highoncoding.com is also one of them. After reading their crazy koala tutorials published in August 17, they mainly used the LevelHelper and SpriteHelper tools, there is also the SneakyInput joystick and a little box2d. In fact, zilongshan people have also translated text
PS: There are a lot of good tutorials abroad on cocos2d. http://highoncoding.com/is also one of them. They will be available in August 17.
PS: There are a lot of good tutorial websites for cocos2d abroad. http://highoncoding.com/is one of them. They will be available in August 17!
Http://highoncoding.com/Articles/868_Implementing_Kraazy_Koala_Using_Cocos2d__LevelHelper_and_SpriteHelper_Part__3.aspx
Hanging monkeys with Joints :( Hanging Monkey with Joints :)
Monkeys are not just sitting there, they are hanging upside down on trees or wandering on branches like Tarzan. With the power of joints, we can achieve the same effect in our games. Creating joints in LevelHelper is very simple. You only need to select the type of joint to be created, and then select the bodies it contains! A joint can only be used for one physical body. This means that the body genie is either static or dynamic. Although we can create a joint between the tree and the monkey, we will use different methods here. The block here will be invisible, so it will not make our tree ugly. We will explain the reasons for our practice in this article.
The following screen shows how to create a joint between the block and the monkey. Make sure that joint is static and monkey is dynamic.
When you use LevelHelper to run a level, you will find that the current monkey's wandering from left to right is like a monkey.
NOTE: If LevelHelper does not load your latest changes, first close SceneTester and then test the level again. There is a bug in SceneTester, which cannot get the latest changes.
Banana launching :( Shooting Bananas :)
Currently, monkeys are unarmed, but this is changed. We will provide unlimited bananas to monkeys. Bananas are thrown out within a given interval, which is arranged through the NSTimer class, as shown in the following code:
[NSTimer scheduledTimerWithTimeInterval:8.0 target:self selector:@selector(throwBanana:) userInfo:nil repeats:YES];
The preceding Code triggers the throwBanana method every 8 seconds. The throwBanana method is implemented as follows:
-(void) throwBanana:(NSTimer *) timer{ banana = [loader createSpriteWithName:@"fruit_banana_100" fromSheet:@"KoalaSheet" fromSHFile:@"KoalaSpriteHelper"]; banana.tag = BANANA; [banana transformPosition:CGPointMake(monkey.position.x - 100, monkey.position.y)]; banana.visible = TRUE; float randomXForce = ((arc4random() % 3) + 0.15) * -1; float randomYForce = ((arc4random() % 3) + 0.15) * 1; [banana body]->ApplyLinearImpulse(b2Vec2(randomXForce,randomYForce), banana.body->GetWorldCenter());}
Explosive: (Dynamites :)
Pineapple cannot kill a monkey! We need explosives! In this section, we will use the path options provided by LevelHelper to create an explosive fuse. We will put an explosive under the tree and then blow up the monkey.
Drag the explosive from the genie icon view and place it under a tree. Create a path from the koala to the explosive, as shown in the following figure:
In order to make besell have a path, you only need to select this box in the right pane. Get a unique name "DynamiteLine" for besell ".
At this time, we have established an explosive line, and we will ignify it. Drag the spark (fire) genie from the genie asset view and place it next to the beginning of the explosive line.
The "fire" Genie path is set along the explosive line. Set the "fire" Genie attribute as follows:
If you run the level in LevelHelper, you will see that the fire genie started along the path and nothing happened when it reached the end. When the fire genie reaches the end of the path, we need to trigger some form of notification. This is the role of nsicationicationcenter. The following code uses nsicationicationcenter to notify you how to arrange the arrival of the path endpoint.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firePathHasEnded:) name:LHPathMovementHasEndedNotification object:fire]; -(void)firePathHasEnded:(NSNotification*) notification{ LHSprite *dynamite = [loader spriteWithUniqueName:@"dynamite"]; CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init]; explosion.position = dynamite.position; [self addChild:explosion]; CCParticleFire *fire = [[CCParticleFire alloc] init]; fire.position = dynamite.position; [self addChild:fire]; [monkey removeAllAttachedJoints];}
The firePathHasEnded method achieves some explosive effects and ensures that monkeys fall into the sea of burning fire!
Download Code: (Download Code :)
FirePathHThe complete code of crazy koala can be downloaded from Github through the following link:
Kraazy Koala Source Code
Conclusion: (Conclusion :)
In this three-part tutorial series, we learned how to use cocos2d LevelHelper, SpriteHelper, and Kobold2d for a complete game. The game covers many different aspects of the LevelHelper and SpriteHelper frameworks. We really hope you like this series of tutorials.