Problem while extending CCSprite

Problem while extending CCSprite
0.0 0


Hey guys,

So, I was following a tutorial from a book for an Android & iOS game. I am using cocos2d-x v2.2 on OS X 10.8

I came across a problem while extending the CCSprite class. Whenever I create an object from this class, the project stops running on Android. Eclipse refuses to build it. I have narrowed down the problem (as described below), but I have no idea how to fix it.


#ifndef __GAMESPRITE_H__
#define __GAMESPRITE_H__
#include "cocos2d.h"

using namespace cocos2d;

class GameSprite : public CCSprite {



    static GameSprite* gameSpriteWithFile (const char* pszFileName);
    virtual void setPosition(const CCPoint &pos);
    float radius();


#endif // __GAMESPRITE_H__


#include "GameSprite.h"

GameSprite::GameSprite(void) {
    _vector = ccp(0,0);

GameSprite::~GameSprite(void) {


GameSprite* GameSprite::gameSpriteWithFile(const char* pszFileName) {
    GameSprite* sprite = new GameSprite();
    if (sprite && sprite->initWithFile(pszFileName)) {
        return sprite;
    return NULL;


Now, in my HelloWorld.cpp file, I create an instance of this class as follows: (This causes Eclipse to throw an error)

GameSprite * player1;
player1 = GameSprite::gameSpriteWithFile("myPic.png");
player1->setPosition(ccp(_screenSize.width*0.5, player1->radius() * 2));

This works flawlessly in iOS. The sprite gets added to the screen at the right position. But when I try to build this project for android using Eclipse, I get an error message saying that: “Your project contains error(s). Please fix them before running your application”.

When I remove this chunk of code (above) from my HelloWorld.cpp file, the app runs on Android without any issues.

As far as I feel, there is an issue with the GameSprite::gameSpriteWithFile method in the GameSprite.cpp file. But I cannot figure out what is the problem and how could I go about fixing it.

Any help guys?



Solved it.

I had to add my GameSprite.cpp class to the file. It is located here:

Eclipse couldn’t find my newly created class hence it wasn’t building it.

So, my new file looks something like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \