What is the correct way of creating a none scene class header and cpp file specifically in Cocos2d-x?
-
koko82Likes 0Problem Description
Hi All
I have seen many example of creating a scene class but not just a normal class h & cpp file. I wandering what the correct way if to create a non scene class file is it :
class Enemy : public cocos2d::Layer { public: virtual bool init(); CREATE_FUNC(Enemy); }
Then in init create your variables and execute?
or
class Enemy : public cocos2d::Layer { public: Enemy(); ~Enemy(); }
Looks like when I try then initialise this class object in a scene file its causing unexpected crashes. Probably due to the header file and cpp not being established correctly.
-
Sonar Systems adminLikes 0
For a regular C++ class check out this video
-
koko82Likes 0
Thanks for the video the question was for cocos2dx not regular c++ as cocos2dx does its own memory management. Need to understand the cocos2dx best way of implementation of a non scene class header.
Also do you always need ‘public’ after class if the class is using sprite or layer, is this standard?
class test : public Node class test : public ParallaxNode class test : public sprite class test : public layer
-
Sonar Systems adminLikes 0
What will the class contain?
-
koko82Likes 0
Specifically trying to create ParrallaxNode but set up the objects and sprites within that class. Then just apply to the main gameplay. Rather than set up on each scene.
-
Sonar Systems adminLikes 0
You should be able to just create a normal C++ class and create an instance of it.
-
koko82Likes 0
I did this last night put in a construct or and de constructo r and logged it. Something intresting happened when it loaded the first scene it created it and destroyed upon next scene. On Subsequent scsne like chapter/level select it on ly destroyed it two scenes after like it didnt register going to the next scene. Not sure why its skipping the de construto r and then applying later on. Could be the issue of the memory crashing.
-
Sonar Systems adminLikes 0
Could you show us the code so we can better understand the inner workings.
-
koko82Likes 0
There is a lot of code, too much to put on here, however I think I have found what the issue is, it looks like when you reuse a scene (ie replay level) its some how becoming desynchronised with the object created. It points to an earlier parrallax object and crashes even though its created a completely new object for the scene…. unsure why this is happening is this a cocos2dx bug? I also am using composition as stated in this article here http://becomingindiedev.blogspot.co.uk/2015/06/correct-composition-design-in-cocos2d-x.html?m=1 and using correctly retain & release on co-nstructor/de-contructor. However hasnt made a difference….
*** ParallaxEngine Object created : 0x18118b8 2. rockValleyP - 0x18118b8 *** ParallaxEngine Object created : 0x1039cb8 2. rockValleyP - 0x1039cb8 *** ParallaxEngine Object Destroyed : 0x18118b8 *** ParallaxEngine Object created : 0x10122b8 2. rockValleyP - 0x10122b8 *** ParallaxEngine Object created : 0x1067eb8 2. rockValleyP - 0x1067eb8 *** ParallaxEngine Object Destroyed : 0x10122b8 *** ParallaxEngine Object Destroyed : 0x1039cb8 *** ParallaxEngine Object created : 0x10636b8 2. rockValleyP - 0x10636b8 *** ParallaxEngine Object created : 0x10648b8 2. rockValleyP - 0x10648b8 *** ParallaxEngine Object created : 0x18444b8 2. rockValleyP - 0x18444b8 *** ParallaxEngine Object Destroyed : 0x10636b8 *** ParallaxEngine Object Destroyed : 0x10648b8 *** ParallaxEngine Object Destroyed : 0x1067eb8 *** ParallaxEngine Object created : 0x105fab8 2. rockValleyP - 0x105fab8 <--- New level replay created new object to use but doesnt and points elsewhere **** Crash Happens cant find 0x10648b8 on xcode ****
-
Sonar Systems adminLikes 0
What version of Cocos2d-x are you using?
-
koko82Likes 0
Using v3.3
-
Sonar Systems adminLikes 0
Try the latest version.
-
koko82Likes 0
Why do you think its related to a bugs, is it easy to upgrade or follow to build it new again..
v3.8?
-
Sonar Systems adminLikes 0
It could be and how much code do you already have?
-
koko82Likes 0
Sorry not with you, I have around 40 files for the current project. Do I create a new one and chuck into a new generated project. This might be a headache to do as a lot of files. You cant just load up a project as it seems cocos2dx embeds the library when you create a new project.
-
Sonar Systems adminLikes 0
Yh you need to chuck the files in.
-
koko82Likes 0
When you create a new project from command line doesnt it add the specific version libraries thats used within that?
If so you would need to transfer files. Or are you saying upon installation it, just open up project as normal...
-
Sonar Systems adminLikes 0
???????
Login to reply