Custom player class

Hi,

Im creating a simple game and i create first version with last version of cocos2d and xcode. In this part i dont have problem and the game runs ok.

But when i compile to android using “build_native.sh” the same code that works on xcode doesnt works on android, because i get exception:

Compile++ thumb : cocos2dcpp_shared <= Player.cpp
jni/…/…/Classes/entities/Player.cpp: In constructor ‘Player::Player()’:
jni/…/…/Classes/entities/Player.cpp:6:20: error: cannot call constructor ‘Player::Entity’ directly [~~fpermissive]
jni/…/…/Classes/entities/Player.cpp:6:20: error: for a function-style cast, remove the redundant ‘::Entity’
make: ***** Error 1
make: Leaving directory `/Users/paulo/Documents/workspaces/cpp/cocos2d-x/projects/flyforcoins/proj.android’
This error is because im using:
Player**player = new Player;
And Player is a class that inherit Entity that inherit CCSprite, look:
**PLAYER:*
<pre>
#ifndef Player_H
#define Player_H
#include “Entity.h”
#include “…/GameObjects.h”
class Player : public Entity
{
public:
Player;
virtual Player\ ;
#endif
</pre>
ENTITY:
<pre>
#ifndef\ Entity_H
#define\ Entity_H
#include\ “cocos2d.h”
USING_NS_CC;
class\ Entity\ :\ public\ CCSprite
{
public:
\ Entity;
\ virtual
Entity ;
#endif
</pre>
So the question is:
~~ How i can correct it, if i cannot use NEW in my class?

I try it too:

>Player *player = Player::create();

But i got error, because “::create” is a method from CCSprite and this method return a CCSprite that is incompatible with Player :frowning:

How to solve it or what is the best metod to create custom Entity classes for games using cocos2d-x?

Thanks!

add to declaration

CREATE_FUNC(Player);

must help

What I usually do is create an abstract Entity class that inherits from CCSprite as you did, then inside all the classes that inherit from it I create the static method “create()” using CREATE_FUNC() and then inside bool init() I call the needed init function of CCSprite, for example initWithFile.

Hi,

Thanks for the answer, im doing it now as you say.

It works. Thanks!