TestProject* testProject = (TestProject* ) (CCDirector::sharedDirector()->getRunningScene());
testProject-> ** PROBLEM HERE **
}`
No available functions are coming up to access. As if *testProject was never casted to anything. By default at the top of main.cpp there is the line: #include "TestProject.h"
How do I call functions from main.cpp to TestProject.h or something similar like HelloWorldScene.h
The setup is exactly like HelloWorldScene. The issue is not so much finding the correct layer (thanks for the tag fix), the issue is the casted object is not being recognized in the file while coding and then when I run the file i get a fatal signal 11. It’s like main.cpp is not recognizing TestProject.h or any of its functions.
class TestProject : public cocos2d::CCLayer
{
...
};
You are subclass CCLayer, not CCScene.
CCDirector::sharedDirector()->getRunningScene() returns a CCScene object so you can’t cast it to TestProject* as TestProject is a subclass of CCLayer.
As for the functions, you are using a static method. TestProject::testLinkage* is a static method. You don’t have to use the>* accessor to invoke it. All you have to do is include the TestProject.h file in main.cpp and invoke it by typing TestProject::testLinkage. Like so: main.cpp
<pre> #include “TestProject.h”
void Main::doSomething {
// Call static method from TestProject class.
TestProject::testLinkage;
// Get Test project instance.
// TIP: I suggest you divide this line into two. It makes it more readable.
cocos2d::CCScene * currentScene = cocos2d::CCDirector::sharedDirector> getRunningScene();
TestProject * testProject = ( TestProject * ) currentScene > getChildByTag;
// Invoke non-static method in TestProject instance
testProject> invokeNonStaticMethod();
}
I get what you are saying about not being able to cast the scene object as layer etc. The issue is that even just typing TestProject::testLinkage() does not work. Typing TestProject:: ** - Once the menu pops up there is no option for the testLinkage. What I’m getting at is that it seems like its ignoring that TestProject.h is included or something.
For instance I can hop into AppDelegate.cpp and easily type
It’s either your IDE is hating you right now or the main.cpp file is somewhere else and not properly linked in your project. You might want to do some restarting or something. This happened to me some times too but restarting the machine does the trick most of the time. You could also try to Clean your project (in XCode it’s Product > Clean or command shift K )
Maybe thats the issue, what would be the proper way to link this to the xCode project. I was just double clicking it and editing it. I am not really on top of certain files get utilized in terms of what needs to be where for android/ios/cocos2dx to work together nicely.