Defining ObjectTypes in TorqueScript
by Samuel Cartwright · in Torque Game Builder · 04/25/2009 (8:56 pm) · 1 replies
I'm trying to make sense of this article, but so far I cannot get it working:
http://tdn.garagegames.com/wiki/Torque_2D/GenreTutorials/StrategyUnitCreation#Scripting_our_data.cs_and_objectTypes.cs
I want to have a custom ObjectType that uses the StaticSprite type as its base, and then create new sprites using something like: %coin = new t2dStaticSprite(Coin);
Am I totally of on how to use this? Should I be using datablocks instead, and if so, can someone explain what this article is talking about and where to use it?
Ideally I'd like to do something like this: %coin = new Coin();
But I assume such a thing is not possible without modifying the C++ source (I'm looking for a pure TorqueScript implementation).
Thanks,
Sam
http://tdn.garagegames.com/wiki/Torque_2D/GenreTutorials/StrategyUnitCreation#Scripting_our_data.cs_and_objectTypes.cs
I want to have a custom ObjectType that uses the StaticSprite type as its base, and then create new sprites using something like: %coin = new t2dStaticSprite(Coin);
Am I totally of on how to use this? Should I be using datablocks instead, and if so, can someone explain what this article is talking about and where to use it?
Ideally I'd like to do something like this: %coin = new Coin();
But I assume such a thing is not possible without modifying the C++ source (I'm looking for a pure TorqueScript implementation).
Thanks,
Sam
Torque Owner Samuel Cartwright
Samuel Cartwright
First, I need to create a sprite to use as a template so I can clone it to create new sprite objects with the same properties:
// -------------------------------------------------------------------- // initObjectTypes() // // This function will initialize all the object types // -------------------------------------------------------------------- function initObjectTypes() { // this will create a base sprite object which we can clone to make a // new sprite. // It will never be visible because it has not been added to the scenegraph new t2dStaticSprite( CoinTemplate ) { class = "Coin"; colour = $red; freeFall = false; imageMap = "puzzleBlock_1ImageMap"; frame = "0"; canSaveDynamicFields = "1"; Position = "-22.500 -16.197"; size = "5.000 5.000"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionCallback = "1"; }; }Then when I use it, I should create a new Sprite object using the named sprite I just created as the CopySource
Does that look like I'm on the right track?