views:

89

answers:

2

Hey Guys,

My question is as easy as that: What is the best method to create character for example in Cocos2D?

Here's an example: I want to create an enemy of my "Ninja". The enemy has a strength of 0.5 and a speed of 50. How would you implement this? A subclass of CCSprite or CCLayer or something completely different?

I tried with NSObject, but that's not really what I was looking for.

I hope you understand what I mean?

A: 

Look here - http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial

Saurabh
Thank you for the link. But he's doing it only with sprites. Add the sprite run an action on it. But I need to store some values in my characters (which can be different for every single character). The new class should also have some action. For example an action "die", so that the character dies with some animations...
Sandro Meier
A: 

It's neither wrong nor right to start with a subclass of either CCSprite or NSObject. Which one will suit you better depends on how you structure your game.

You could of course subclass CCSprite to create a "Ninja" class and add to your ninja propertys like health, strength and so forth. But if your game features several game characters that use the same set of properties, you might want to create a universal "GameCharacter" subclass of CCSprite in between, which you could then subclass further, adding the properties and methods that are specific to a single character.

If not all game objects are based on CCSprites for example, then you might want to start with a NSObject subclass and add a CCSprite (or some other cocos class) as a property.

As for the actions: If you start with a subclass of CCSprite, for example, you could just implement a method die which would instantiate the actionobjects and let self run them. You could then either call die directly or call it from another method of the same class which manages hitpoints and calls die once the hitpoints drop below zero.

However, I suggest you browse the web for some basic game design tutorials. You'll have a hard time if you don't plan things thoroughly right at the start...

Toastor
Thank you very much for your explanation. That really helped me. Now I know, that none of the methods is wrong. I'm not completely new to game design I just didn't know which way I should do it with cocos2d. :-D
Sandro Meier