Questions about converting a game from TGB 1.7.5 to T2D 2.0
by Amjad Yahya · in Torque 2D Beginner · 08/05/2013 (4:57 am) · 9 replies
I'm trying to convert my game from TGB 1.7.5 to T2D 2.0, so I need to know some things before I do that:
1- How to preload all my assets on start-up?
2- What is the function that returns user profile folder? i.e. the place where player's profile is saved for Windows, Mac and iOS. I want to be able to use TamlWrite() to save files to the user's directory.
1- How to preload all my assets on start-up?
2- What is the function that returns user profile folder? i.e. the place where player's profile is saved for Windows, Mac and iOS. I want to be able to use TamlWrite() to save files to the user's directory.
About the author
#2
2. I've just let TamlWrite leave files in the default folder where the exe or app is located so far. I see in the platform filespace there is the getUserDataDirectory function.
Edit: @Richard - pretty sure there is no preload field for assets. Definitely nowhere to be found on AssetBase.
08/05/2013 (6:48 am)
1. Typically you let the asset manager handle the loading and unloading of assets. Assets are loaded when they are assigned to an object for the first time. Have you noticed some sort of performance issue to cause a need for explicit control? The asset manager guide on the wiki has a lot of good information on how assets are handled. 2. I've just let TamlWrite leave files in the default folder where the exe or app is located so far. I see in the platform filespace there is the getUserDataDirectory function.
Edit: @Richard - pretty sure there is no preload field for assets. Definitely nowhere to be found on AssetBase.
#3
And since this writes out to .taml as follows :
You can write your Scene's preloads in Taml directly by replicating the above example.
@Mike : I found this knowledge in an old email sent by Melv, I'll update the AssetManager Guide to reflect the changes!
08/05/2013 (9:09 am)
While there is no "preload" field specifically, there is a Console function for preloading an asset before creating a sceneScene.addAssetPreload(AssetID);
And since this writes out to .taml as follows :
<Scene>
<Scene.AssetPreloads>
<Asset Id="@asset=ToyAssets:Particles1" />
<Asset Id="@asset=ToyAssets:Particles2" />
<Asset Id="@asset=ToyAssets:Particles3" />
<Asset Id="@asset=ToyAssets:Particles4" />
<Asset Id="@asset=ToyAssets:Particles5" />
<Asset Id="@asset=ToyAssets:Particles6" />
</Scene.AssetPreloads>
</Scene>You can write your Scene's preloads in Taml directly by replicating the above example.
@Mike : I found this knowledge in an old email sent by Melv, I'll update the AssetManager Guide to reflect the changes!
#4
08/05/2013 (3:35 pm)
Oooh - they moved it....
#5
If I understand asset loading correctly, then something like this:
would be pointless since the asset is loaded when it is assigned to the sprite during the TamlRead import. Does that sound right?
@Simon: I can update the Asset Manager guide if you want. Keep working on the CompositeSprite guide. :)
08/05/2013 (10:56 pm)
Interesting. Would not have thought to look there.If I understand asset loading correctly, then something like this:
<Scene>
<Scene.AssetPreloads>
<Asset Id="@asset=ToyAssets:Particles1" />
</Scene.AssetPreloads>
<Sprite
Image="ToyAssets:Particles1"
Frame="0" />
</Scene>would be pointless since the asset is loaded when it is assigned to the sprite during the TamlRead import. Does that sound right?
@Simon: I can update the Asset Manager guide if you want. Keep working on the CompositeSprite guide. :)
#6
Defining the sprite will obviously allow you to place it where you want, set its blending colour, frame, etc. but it should load the Sprite as well...
I guess Asset Preloading is mostly useful when generating things at runtime such as enemies.
Hope that makes sense. It's 2:20 am and I just finished Dear Esther...weird mood.
08/05/2013 (11:24 pm)
Your logic makes sense to me although I must admit I'm not 100% sure.Defining the sprite will obviously allow you to place it where you want, set its blending colour, frame, etc. but it should load the Sprite as well...
I guess Asset Preloading is mostly useful when generating things at runtime such as enemies.
Hope that makes sense. It's 2:20 am and I just finished Dear Esther...weird mood.
#7
I don't want to preload assets when the scene loads, I want them to be loaded when the game starts, so I think using
would serve me better.
also getUserDataDirectory() is the one that I need.
Another question: how can I declare an image asset at run-time rather than using a taml file?
I tried something like this:
and then I assign it to a sprite
I get this error: Asset Manager: Failed to acquire asset Id 'Game:logo1' as it does not exist.
Any thoughts?
08/06/2013 (3:53 am)
Thank you all.I don't want to preload assets when the scene loads, I want them to be loaded when the game starts, so I think using
Scene.addAssetPreload(AssetID);
would serve me better.
also getUserDataDirectory() is the one that I need.
Another question: how can I declare an image asset at run-time rather than using a taml file?
I tried something like this:
%image = new imageAsset(); %image.AssetName="Game:logo1"; %image.ImageFile="^Game/assets/splash/logo1.jpg";
and then I assign it to a sprite
%clone.Image = "Game:logo1";
I get this error: Asset Manager: Failed to acquire asset Id 'Game:logo1' as it does not exist.
Any thoughts?
#8
If you want to declare and use an asset at runtime, and you do not want to eventually persist it, you can declare it a private asset. The AssetManager guide gives you an example in TorqueScript on how to use private assets.
08/06/2013 (4:34 am)
Scene.addAssetPreload has the same effect as loading from TAML, you need to have already created your scene since that method belongs to it. To explicitly load an asset you can use AssetDatabase.acquireAsset(assetId). By doing it that way you also need to manually release the asset when you are done with it, otherwise it will stay in memory. But this is exactly why you should just let the asset manager handle things for you, to save all the micromanagement hassle.If you want to declare and use an asset at runtime, and you do not want to eventually persist it, you can declare it a private asset. The AssetManager guide gives you an example in TorqueScript on how to use private assets.
#9
08/10/2013 (10:50 am)
Thanks Mike, private asset is exactly what I need.
Torque Owner Richard Ranft
Roostertail Games
2) getUserHomeDirectory().