Cocos2D-X Platformer tutorial Part 10 – Refactor Player

To fix the stuttering issue and making the code cleaner we are going to refactor the Player class. Instead of having the player sprite as a separate field we will extend the Sprite class.
After that we will make the necessary changes to GameScene.

  • Even we have a sprite for the player we will save its container size separately, because scaling or animating effects might change the size and break collision detection
  • There will be changes in initializing and updating the GameScene
  • Update player sprite method is removed from GameScene, it belongs to the Player class now
  • Updated to 3.9, next part will improve the scaling


mudboy January 12, 2016 at 1:27 pm

also the AppDelegate.h file needs the declaration:
virtual void initGLContextAttrs();

    metin January 12, 2016 at 2:26 pm

    It should be there since it was auto generated, but thanks will post the AppDelegate.h too

nishanth May 7, 2017 at 8:32 am

Hi metin in Player class some members are not found in below i mentioned error details kindly review it.

||=== Build: all in MyGame (compiler: GNU GCC Compiler) ===|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp||In member function ‘void GameLayer::updateScene(float)’:|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|134|error: ‘class Player’ has no member named ‘getPositionX’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp||In member function ‘void GameLayer::updatePlayer(float)’:|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|168|error: ‘class Player’ has no member named ‘getBoundingBox’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|175|error: ‘class Player’ has no member named ‘getPositionX’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|176|error: ‘class Player’ has no member named ‘getPositionY’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|185|error: ‘class Player’ has no member named ‘getBoundingBox’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|186|error: ‘class Player’ has no member named ‘getBoundingBox’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|207|error: ‘class Player’ has no member named ‘getBoundingBox’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|208|error: ‘class Player’ has no member named ‘getBoundingBox’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|218|error: ‘class Player’ has no member named ‘setPositionY’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|218|error: ‘class Player’ has no member named ‘getPositionY’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|222|error: ‘class Player’ has no member named ‘setPositionY’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|241|error: ‘class Player’ has no member named ‘setPosition’|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp||In constructor ‘GameLayer::GameLayer()’:|
/home/nishanth/projects/Platfomer/Classes/GameLayer.cpp|290|warning: ‘virtual void cocos2d::Layer::setKeyboardEnabled(bool)’ is deprecated (declared at /home/nishanth/projects/Platfomer/cocos2d/cocos/2d/CCLayer.h:207) [-Wdeprecated-declarations]|
||=== Build failed: 12 error(s), 1 warning(s) (0 minute(s), 6 second(s)) ===|

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Recent Posts

Recent Comments

Categories