sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Cannot subclass CCSprite without generating error. #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Create a subclass of CCSprite for example 'MySprite'. 
Now add 'MySprite.sprite('texture.png')'.
You get the error Type mismatch: cannot convert from CCSprite to MySprite. 

Original issue reported on code.google.com by docherty...@gmail.com on 17 Nov 2010 at 10:56

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
adding a static method 'sprite' to my subclassed CCSprite class fixed this 
issue, thanks for your help zhouweikuan.

Original comment by docherty...@gmail.com on 23 Nov 2010 at 4:56

GoogleCodeExporter commented 8 years ago
Try to add "public" in front of sprite inte CCSprite class.

Original comment by amirs...@gmail.com on 28 Nov 2010 at 10:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
All properties/variables that are used and you want to subclass should be 
protected or public. If variables have so called default scope like

CCSprite sprite;

then it will not be seen/accessible in subclass (class that extends that 
class). Therefore if you have class that can be extended by users then make all 
variables at least protected.

Also in Android it takes more time to call a method then to access variable 
directly. Add public to variables so that we can access them without 
getPropertyName() or setPropertyName(parameter)

Original comment by amirs...@gmail.com on 29 Nov 2010 at 12:15

GoogleCodeExporter commented 8 years ago
Best of all is to remove this obj-c style creation and use constructors 
directly.

Original comment by opengen...@gmail.com on 14 Dec 2010 at 9:18