Custom player class

Custom player class
0.0 0



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 “” 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/’
This error is because im using:
Player**player = new Player;
And Player is a class that inherit Entity that inherit CCSprite, look:
#ifndef Player_H
#define Player_H
#include “Entity.h”
#include “…/GameObjects.h”
class Player : public Entity
virtual Player\ ;
#ifndef\ Entity_H
#define\ Entity_H
#include\ “cocos2d.h”
class\ Entity\ :\ public\ CCSprite
\ Entity;
\ virtual
Entity ;
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?



add to declaration


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.



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

It works. Thanks!