Building an entire game in C++ instead of scripting
by Celso Duran · in iTorque 2D · 09/27/2011 (1:30 pm) · 3 replies
I'm currently using iTorque 2D on Mac. I am interested in developing my game entirely in C++ (I know all the pros and cons of using script, but I still prefer C++). My question is where do I begin? Where is the game engine's main loop or where would I implement all my call backs? Is there a tutorial out there that can help me? I haven't been able to find one, only things I've found is how to use objects made in C++ within Torquescript (this is not what Im looking for).
Any help will be greatly appreciated.
Any help will be greatly appreciated.
About the author
I am owner of Dream Bytes, a game development company.
#2
If you decide to try iTorque with C++ here are some tips:
Go on the TDN and look around. There is at least one article that shows how to build a class that can be accessed by script.
t2dSceneGraph::renderView
Hook your "main loop" function in your C++ class instead of the script call to onUpdateScene
t2dSceneObject::onScriptCollision
Hook your collision callback in your C++ class instead of the script call to onCollision
Loading resources in script and passing pointers to the C++ code worked well.
Here is one example of how to pass a pointer from script to C++:
ConsoleMethod( MyCPPGame, AddAnimatedSprite, void, 3, 3, "()" )
{
t2dAnimatedSprite* sprite = dynamic_cast<t2dAnimatedSprite*>(Sim::findObject(argv[2]) );
return object->AddAnimatedSprite( sprite );
}
..alternatively checkout Cocos2D-x
09/27/2011 (2:37 pm)
I went down this road a few months ago and honestly I can't say it was worth it. iTorque just isn't setup for complete C++ integration. Script until there is a bottleneck and dump that code to C++.If you decide to try iTorque with C++ here are some tips:
Go on the TDN and look around. There is at least one article that shows how to build a class that can be accessed by script.
t2dSceneGraph::renderView
Hook your "main loop" function in your C++ class instead of the script call to onUpdateScene
t2dSceneObject::onScriptCollision
Hook your collision callback in your C++ class instead of the script call to onCollision
Loading resources in script and passing pointers to the C++ code worked well.
Here is one example of how to pass a pointer from script to C++:
ConsoleMethod( MyCPPGame, AddAnimatedSprite, void, 3, 3, "()" )
{
t2dAnimatedSprite* sprite = dynamic_cast<t2dAnimatedSprite*>(Sim::findObject(argv[2]) );
return object->AddAnimatedSprite( sprite );
}
..alternatively checkout Cocos2D-x
#3
http://www.garagegames.com/community/forums/viewthread/124415/2#comment-800104
Technically, the t2dSceneObject owns the Component, but with the C++ Components, you control the "Owner" backwards through the Component (for example, in its onUpdate() function, which is inherited from SimComponent).
Alternatively, you could override t2dSceneObject, t2dStaticSprite, or t2dAnimatedSprite to create your own objects, but you probably would need to make some changes to the TGB editor in order to use it with your new objects. I haven't done this yet, so I can't really go into more detail about it.
09/30/2011 (7:01 pm)
I approached this using C++ Components (also called Behaviors). All my Torque projects are written almost entirely in C++, and, while it was a lot of work, the performance increase over scripts made it worth it. It was also a lot easier to debug, of course. I haven't looked at the most recent documentation, so there could be a lot more info about them now, but I posted a long comment on a thread a while back that you could use as a starting point:http://www.garagegames.com/community/forums/viewthread/124415/2#comment-800104
Technically, the t2dSceneObject owns the Component, but with the C++ Components, you control the "Owner" backwards through the Component (for example, in its onUpdate() function, which is inherited from SimComponent).
Alternatively, you could override t2dSceneObject, t2dStaticSprite, or t2dAnimatedSprite to create your own objects, but you probably would need to make some changes to the TGB editor in order to use it with your new objects. I haven't done this yet, so I can't really go into more detail about it.
Torque 3D Owner Pedro Vicente
Space Research Software LLC
Check out this
Torque Minimal Template -- Part 2. A C++ start function