images without taml?
by Matthew Warner · in Torque 2D Beginner · 01/05/2016 (6:24 pm) · 10 replies
So I have been looking for a way to just load an image without the need for a taml file. It seems quite silly to need a taml file to let my game know theres a image named the exact same thing right next to it. I have tried looking through the ImageAsset and AssetManager files and I see absolutely no way I can assign the path of the image to be drawn without the need to have a taml file. Aside from this my only idea is to just manually do it in OpenGL.. is there anyone that has any kind of advice into where a better place to look would be?
About the author
#2
01/06/2016 (7:35 am)
If we start with the "why", we might be able to give you more of answer. If you are trying to render a game object image, Sprite, then why do you feel the need to bypass TAML? Is there a purpose behind raw image loading?
#3
01/06/2016 (9:07 am)
I am trying to render images which are not to be interpreted as objects. It's somewhat problematic to have double the number of files due to the environment I'm working on limiting the number of files I use. I guess I could also just use 1 super massive image and just take shapes out of that to bypass my file count restriction but its completely stupid to need to manage an entire object.. just for an image.. =/
#4
Out of pure curiosity, why is file count a restriction?
01/06/2016 (9:15 am)
That sounds like you need a GUI, not a game object (Sprite). GUIs can use raw images just fine without a TAML file.Out of pure curiosity, why is file count a restriction?
#5
01/06/2016 (9:38 am)
Web-end based loop limit exceed problems. Probably should just deal with that then try and do this. I can check GUI's but I'm not 100% sure its what I'm looking for. Alternatively is there any way to load an asset then overwrite the image file path for it? Because when I tried that I could clearly see in my debugger the variable changed but it still showed the old image.
#6
Sure. Once you have a handle to the asset, you simply call the appropriate method. For example, an ImageAsset has two ways to change the path:
Is that how you are changing the file path?
01/06/2016 (10:15 am)
Quote:is there any way to load an asset then overwrite the image file path for it
Sure. Once you have a handle to the asset, you simply call the appropriate method. For example, an ImageAsset has two ways to change the path:
%imageAsset.setImageFile(%theNewPath); %imageAsset.ImageFile = %theNewPath;
Is that how you are changing the file path?
#7
01/06/2016 (10:36 am)
Well I was working with code that I wrote in c++. And this is what I was trying, but it was not working.ImageAsset *myImage = new ImageAsset();
myImage->setAssetName("ToyAssets:pics1");
myImage->setImageFile("pics2.png"); // hoping that it would change to this image
myImage->setCellCountX(128);
myImage->setCellCountY(32);
myImage->setCellWidth(16);
myImage->setCellHeight(16);
myImage->refreshAsset();
myImage->registerObject();
// ends up showing the pics1 instead... :(
static_cast<ImageFrameProvider*>(this->tiles[x + y * 64])->setImage(myImage->getAssetName(), newtile);
this->tiles[x + y * 64]->setPosition( Vector2( x, -y ));
this->tiles[x + y * 64]->setSize( Vector2( 1, 1 )); // width and height
this->tiles[x + y * 64]->setVisible(true); // Make the object visible to the scene
this->tiles[x + y * 64]->setCollisionCallback(true);
//this->tile[x + y * 64]->createPolygonBoxCollisionShape(2, 2);
this->tiles[x + y * 64]->setBodyType(b2_staticBody);
this->tiles[x + y * 64]->registerObject();
pScene->addToScene(this->tiles[x + y * 64]);
#8
That asset needs an AssetManager to work properly. ImageAsset creation in C++ isn't standard practice, but there is an example in the SkeletonAsset class:
The important bit is AssetDatabase.addPrivateAsset.
01/06/2016 (10:57 am)
Your code is bypassing the AssetManager. Have a look at the refreshAsset method:void AssetBase::refreshAsset( void )
{
// Debug Profiling.
PROFILE_SCOPE(AssetBase_RefreshAsset);
// Finish if asset is not owned or is not initialized.
if ( mpOwningAssetManager == NULL || !mAssetInitialized )
return;
// Yes, so refresh the asset via the asset manager.
mpOwningAssetManager->refreshAsset( getAssetId() );
}That asset needs an AssetManager to work properly. ImageAsset creation in C++ isn't standard practice, but there is an example in the SkeletonAsset class:
ImageAsset* pImageAsset = new ImageAsset();
const char* imageFilePath = expandAssetFilePath(currentPage->name);
// Point to the raw file (png or jpg)
pImageAsset->setImageFile( imageFilePath);
// Enable Explicit Mode so we can use region coordinates
pImageAsset->setExplicitMode( true );
spAtlasRegion* currentRegion = mAtlas->regions;
// Add it to the AssetDatabase, making it accessible everywhere
mImageAsset = AssetDatabase.addPrivateAsset( pImageAsset );The important bit is AssetDatabase.addPrivateAsset.
#9
Edit:
That worked perfectly. Thank you again.
01/06/2016 (11:05 am)
Alright, thanks. I will take a look at that and see if it helps.Edit:
That worked perfectly. Thank you again.
#10
01/08/2016 (1:47 pm)
Great! Glad your code is working now. You can find more information about the asset system on the T2D GitHub pages/wiki.
Torque Owner Richard Ranft
Roostertail Games
The best advice is to either use what's there because it works pretty danged well. If you hate that idea, then you're going to want to start working on your own resource management system - you can use the current AssetManager as a template....
If you're on about this because you don't want to manually create all of those file, there is a piece of script in this resource that can be used to generate TAML files for simple assets (non-celled images and sounds). I also didn't want to manually create all of those files....