Original Post
Hi,
I have written a game engine which purpose is to power 2D games. The engine is written in C++ (even though some parts are written in Objective-C and Java since it runs on mobile devices), and it is very time consuming to design things like GUI and such. Add a button, start the game and realize that you have to move it a couple of pixels, shut down, make the fix, recompile and start again. You're probably familiar with the scenario and knows that it sucks.
My solution to this is to make a simple editor. The editor will support an outline (SceneGraph) with its corresponding nodes and entities such as sprites and widgets. With this editor I will be able to add sprits to the scene and position them pretty fast with the mouse and text input fields. But since the entities shouldn't be plain dead I want to be able to add a script to each and every node and entity. I can see it in front of me where you add a sprite to the scene, right-click on it and clicks on "Add Script" where a text window appears and you can write your script.
The scripting language I have begin implementing in my engine is Lua, and I have mapped some classes with tolua++ and it works fine. But now I'm stuck with some design issues...
How should I design the Lua usage? My first idea was to have one script file for each and every node and entity I add to the scene. Those files would look something like this, with functions called from C++.
The problem is that I haven't ever worked with a game engine using a scripting language so I don't really know how people wants to work with it.
So to my question.
How do game engines usually utilize scripts and are there any good sites about this I should read? Also, is my initial approach something that sounds OK or what should I think about. Just need some help to get me started.
Thanks for your time!
I have written a game engine which purpose is to power 2D games. The engine is written in C++ (even though some parts are written in Objective-C and Java since it runs on mobile devices), and it is very time consuming to design things like GUI and such. Add a button, start the game and realize that you have to move it a couple of pixels, shut down, make the fix, recompile and start again. You're probably familiar with the scenario and knows that it sucks.
My solution to this is to make a simple editor. The editor will support an outline (SceneGraph) with its corresponding nodes and entities such as sprites and widgets. With this editor I will be able to add sprits to the scene and position them pretty fast with the mouse and text input fields. But since the entities shouldn't be plain dead I want to be able to add a script to each and every node and entity. I can see it in front of me where you add a sprite to the scene, right-click on it and clicks on "Add Script" where a text window appears and you can write your script.
The scripting language I have begin implementing in my engine is Lua, and I have mapped some classes with tolua++ and it works fine. But now I'm stuck with some design issues...
How should I design the Lua usage? My first idea was to have one script file for each and every node and entity I add to the scene. Those files would look something like this, with functions called from C++.
function onCreate()
end
function onRender()
end
function onTick()
end
function onDestroy()
endThe problem is that I haven't ever worked with a game engine using a scripting language so I don't really know how people wants to work with it.
So to my question.
How do game engines usually utilize scripts and are there any good sites about this I should read? Also, is my initial approach something that sounds OK or what should I think about. Just need some help to get me started.
Thanks for your time!