Here is the way generally followed to sub-class a CCSprite.
public class CharacterSprite extends CCSprite
{
// Add new custom fields or methods here,
// or override the specific methods of CCSprite
// that you want to extend the functionality of.
}
From your question I can understand that you are inheriting CCSprite not to extend the functionality. Usually this should be avoided. There is no need to override the public static CharacterSprite sprite(String fileName) method as it will be already there in the super class.
So a call like this will do: CharacterSprite.sprite("sample.png"). This will return a sprite you desire!
In fact, There are two ways you can make CharacterSprite class which you desire.
Inheriting CCSprite. Do this only if you are really over-riding any functionality of the existing CCSprite (for example, if you want to draw with multi-texturing , override draw and have your code).
Have CCSprite instance as an attribute (member) of CharacterrSprite class. This is the better way if you are "not re-defining" the functionality of CCSprite.
For example, the second case will be like this:
class CharacterSprite
{
Position m_pos;
// ...
CCSprite m_sprite; // The sprite instance.
CharacterSprite(String filename)
{
m_sprite = new CCSprite(filename);
}
}
// Usage:
CharacterSprite _character = new CharacterSprite("character.png");
Now add _character.m_sprite to the current scene/layer.