Sandro Meier
Sandro Meier

Reputation: 3051

Cocos2D game element design

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?

Upvotes: 1

Views: 644

Answers (1)

Toastor
Toastor

Reputation: 8990

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...

Upvotes: 2

Related Questions