DMT - Basic tutorial

Full source code for the example project is on gitHub.

What is DMT?

In short, DMT will lets create texture atlases from vector based assets at run-time.
I'll show you a very simple example on how to do that, and what are the benefits of DMT.
Next time we'll talk about Dimethyltryptamine, for now let's do some code :-)


Creating a project

For this example we'll use Flash-Builder 4.7, but this can be done with any other IDE.

Create an ActionScript Mobile AIR Project, name it HelloDMT. You can also use Desktop AIR, it doesn't really matters, as long as you use AIR. AIR is important here because the basic DMT API uses the file-system to save the texture atlases and some more data. To use DMT on pure Flash projects you'll have to use a more advance DMT API.


Basic Starling setup

Lets create a very basic Starling app.
  • First include Starling.swc in your project (Download from here)
  • Edit the HelloDMT.xml, and set the renderMode to direct. To be able to use the Stage3D.
  • Create your Starling main class, Main.as (Inherit from starling.display.Sprite)
  • And on HelloDMT.as use this code:
package
{
 import flash.display.Sprite;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 
 import starling.core.Starling;
 
 public class HelloDMT extends Sprite
 {
  private var m_starling:Starling;
  
  public function HelloDMT()
  {
   super();
   
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
   
   Starling.multitouchEnabled = true;
   Starling.handleLostContext = true;
   
   // initialize Starling
   m_starling = new Starling(Main, stage);
   m_starling.simulateMultitouch  = false;
   m_starling.start();
  }
 }
}

Vector Assets

Most artists create their vector game/app assets in Flash or Illustrator. To be able to use these assets, you must give it a linkage name, so we will be able to create it on run-time.
In our example we will use a simple Square, Triangle, and Circle assets that I've created, as you can see they all share the same LeftEye and RightEye assets (Download swf or fla).
The library looks like this:


Create assets folder under the main project and put the HelloDMT-Assets.swf in that folder, so we can embed it in our project.


The DMT library

Clone the code from gitHub, or just download it.
On the main directory you can see 4 folders:
  1. libs: This contains the Starling.swc, and XTDCommon.swc. Starling you should know, and XTDCommon is another open-source library (gitHub) with some useful utilities (You'll see soon)
  2. Samples: This folder contains an example project with the examples of the DMT library.
  3. DMT: This is the full source-code of the library.
  4. swc: Contains the compiled swc, in case you don't want to include the code in your project.
Copy the DMT.swc & XTDCommon.swc to your project, and include it just like you did with Starling.swc.
Your project tree should look like this:



Loading the assets

Before we can start using our assets, we must load them into our Application Domain.
There are few ways to load swf assets into your application domain. You can load from external file, remote url, or embed the swf. In our example we'll embed the swf and load it into our application domain, so we can create our three assets.
  [Embed(source="/../assets/HelloDMT-Assets.swf", mimeType="application/octet-stream")] 
  private var AllAssetsClass:Class;


To load the embedded assets into our application domain we'll use a utility class named AssetsLoaderFromByteArray, available on XTDCommon library (Told you we'll use it).
Using this class we can shorten our code of loading the assets and registering them on the application domain.

private var _assetsLoader  : AssetsLoaderFromByteArray;

private function loadAssets():void
{
  var assetsByteArrays : Vector.<bytearray> = new Vector.<bytearray>;
  assetsByteArrays.push(new AllAssetsClass());
  _assetsLoader = new AssetsLoaderFromByteArray(assetsByteArrays);
  _assetsLoader.addEventListener(Event.COMPLETE, onAssetsReady);
  _assetsLoader.initializeAllAssets();
}

protected function onAssetsReady(event:Event):void
{
  sendVectorAssetsToDMT();
}  


Lets examine the code:
I've defined a private variable _assetsLoader in the type of AssetsLoaderFromByteArray.
Created a function loadAssets, which will handle the loading process.
The AssetsLoaderFromByteArray class excepts a Vector of ByteArrays (SWFs that you embedded) and loads them all into the current ApplicationDomain. Once the assets are loaded and ready (Listening to Event.COMPLETE), we can start working on the DMT side, and start the rasterization process (Converting Vectors to Textures).


Initialize DMT

To use DMT we will create an instance of DMTBasic, and listen to Event.COMPLETE (We can also listen to Event.PROGRESS to get processing/loading progress) Now, if we have cache, we can start the processing right away. if we don't have cache we should first load the assets and rasterize them.
private var _dmtBasic   : DMTBasic;

private function initDMT():void 
{
  _dmtBasic = new DMTBasic("HelloDMT", true);
  _dmtBasic.addEventListener(flash.events.Event.COMPLETE, dmtComplete);
  if (_dmtBasic.cacheExist() == true)
    _dmtBasic.process(); // will use the existing cache
  else
    loadAssets();
}


Get ready for the Rasterization

In the case that we don't have cache, we will create the three vector assets, add them to DMT, and start the processing.
private function addVectorsToDMT():void 
{
  var square : DisplayObject = new (ApplicationDomain.currentDomain.getDefinition("Square"))
  square.name = "square";   
 
  var circle : DisplayObject = new (ApplicationDomain.currentDomain.getDefinition("Circle"))
  circle.name = "circle";

  var triangle : DisplayObject = new (ApplicationDomain.currentDomain.getDefinition("Triangle"))
  triangle.name = "triangle";

  _dmtBasic.addItemToRaster(square);
  _dmtBasic.addItemToRaster(circle);
  _dmtBasic.addItemToRaster(triangle);
  _dmtBasic.process(); // will rasterize the given assets  
}
I've given each asset a name, so later we will be able to ask DMT for these specific assets by name.



Game on!

After the cache was loaded, or after the rasterization is complete, DMT will fire the Event.COMPLETE, in this event listener we can be sure that we have our Starling assets ready to use.
In this example I've created all three assets, and put them on the stage, I've also rotated the eyes of the Triangle to show that the eyes are not baked into the texture.
Pay attention that we used the names that we gave the assets.
protected function dmtComplete(event:Event):void
{
  var starlingSquare : Sprite = _dmtBasic.getAssetByUniqueAlias("square") as starling.display.Sprite;
  starlingSquare.x = 100;
  starlingSquare.y = 100;
  addChild(starlingSquare);

  var starlingCirlce : Sprite = _dmtBasic.getAssetByUniqueAlias("circle") as starling.display.Sprite;
  starlingCirlce.x = 100;
  starlingCirlce.y = 300;
  addChild(starlingCirlce);

  var starlingTriangle : Sprite = _dmtBasic.getAssetByUniqueAlias("triangle") as starling.display.Sprite;
  starlingTriangle.x = 100;
  starlingTriangle.y = 500;
  addChild(starlingTriangle);
   
  starlingTriangle.getChildByName("right_eye_instance").rotation = Math.PI/2;
  starlingTriangle.getChildByName("left_eye_instance").rotation = -Math.PI/2;
}

This is how the Texture will look like, as you can see the left and right eyes were created once because they are actually the same assets with the same linkage.


Best practices

  • Instead of doing what I did in this example, created and added items one by one. You can do this:
    • Design your level/screen in Flash-Pro into one asset.
    • Make sure that all the children are with instance names (So you'll be able to access them).
    • Give it a linkage name, say "Level1".
    • Load this asset the same as we did in this example.
    • Re-position and re-scale the children to best fit the screen-resolution.
    • Call the DMT process() function.
    • Your level is ready as Starling objects with all the inner children positioned/scaled and accessible.
    • Because we use cache, this process will be done once, and DMT will load the textures and data next time.
  • Listen to DMT Event.PROGRESS, and show the user a "Loading..." message. if DMT doesn't have cache show the user "First time Loading, please wait..."
  • The third parameter of the DMT constructor is the cache version. In case that you've updated your game, and your game has changed assets. You want DMT to clear the previous cache, and create a new one, just increase the version.
  • Don't use huge vector assets, remember that the current limit is 2048x2048.
  • DMT will rasterize each frame in a MovieClip, so be smart about it.
  • You can checkout our game (Android, iOS, Amazon), and see for yourself, everything there was done with DMT, and it fits perfectly on ALL possible resolutions with crisp graphics!



Conclusion

DMT is quite easy after few minutes, and it gives you fast and powerful technique in just few lines of code.
You can animate the inner children, just like you would in the flash timeline, but in code.
No more stretched/squashed textures!


Troubles, Solutions, and some notes

  • Most of the first time users of DMT forget about the cache, they add assets, ask DMT to process them, and get an error when asking DMT to create these new assets... DMT will use the old cache if exists. So while in development don't use cache, until the late stages of your game/app.
  • Where is the Cache saved? The answer to that is "Depends on what device", on Windows it's under C:\Users\USER_NAME\AppData\Roaming\DATA_NAME, on Android and iPhone it's on a temp folder that will not get saved to the app cloud data (As noted by Apple)
  • If you want DMT to stop "digging" into your assets display-tree and stop rasteraizing. you can do two things:
    • When you call dmtInstance.process, the second parameter is the maxDepth, use that as an overall limit. DMT will not rasterize deeper children.
    • To stop "digging" into a specific instance, name it "stop_raster", and DMT will raster this instance as it is, and not its children.
  • dmtInstance.getAssetByUniqueAlias is returning starling.display.DisplayObject, but you want MovieClip? If you are sure that your assets was a movieClip, just cast it to MovieClip.
  • MovieClips are rasterized as is, DMT will lot try to rasterize each frame's children.
  • Make sure that you use linkage name to your assets that you re-use, DMT will detect the same assets (As you saw in this example) as will not re-rasterize them.
  • Be sure to checkout the DMT source code, there are some example projects there.

Related Posts

73 comments

  1. I wonder why you are using a swf instead of a swc for assets
    I have run this test, is it a good way to do it ?


    package
    {
    /**
    * ...
    * @author YopSolo
    */
    import com.xtdstudios.DMT.DMTBasic;
    import flash.events.Event;
    import starling.display.Sprite;

    public class Game extends Sprite
    {
    private var _dmt:DMTBasic;

    public function Game()
    {
    _dmt = new DMTBasic("HelloDMT", true);
    _dmt.addEventListener(flash.events.Event.COMPLETE, _dmtComplete);
    if (_dmt.cacheExist() == true)
    _dmt.process(); // will use the existing cache
    else
    raster();
    }

    private function _dmtComplete(e:Event):void
    {

    var starlingCirlce : Sprite = _dmt.getAssetByUniqueAlias("circle") as starling.display.Sprite;
    starlingCirlce.x = 100;
    starlingCirlce.y = 300;
    addChild(starlingCirlce);
    }

    private function raster():void
    {
    var circle:Circle = new Circle();
    circle.name = "circle";
    _dmt.addItemToRaster( circle );
    _dmt.process();
    }
    }

    }

    ReplyDelete
    Replies
    1. Did this work for you? I am doing it exactly as you have typed, but all the starling sprites are coming out "TypeError: Error #1009: Cannot access a property or method of a null object reference" when I try to call _dmtBasic.getAssetByUniqueAlias("square") as starling.display.Sprite

      Delete
    2. Do a trace(_dmtBasic.getAssetByUniqueAlias("square")) and see what is the object type that you get from dmt... it might be Sprite, Image or a MovieClip...
      The best thing would be is to use DisplayObject.

      Delete
  2. Sure, you can use whatever why you see fit to get your assets available. You can even create you assets with code only. It doesn't matter.

    ReplyDelete
  3. Hi,
    I have created four movieclips inside one movieclip in flash pro.
    I have converted it using DMT.
    I am able to access that four movieclips in Starling.
    But I want starling button effect on that four movie clip.
    Is it possible to convert (DMT processed objects) to Starling button.
    Any suggestion for me?

    ReplyDelete
  4. Starling Button is just addition of Touch Events on a DisplayObject, just create your own Class and copy the touch events code from Starling button...

    ReplyDelete
    Replies
    1. thanks a lot Gil for your replay. I had managed it through touch event phase.

      Delete
  5. How can I re-position and re-scale the children to best fit the screen-resolution, before call the DMT process() function?
    How can I access to textures to use the starling.contentScaleFactor?

    ReplyDelete
    Replies
    1. There's no need for contentScaleFactor...
      The best practice is to layout your display objects according to the current resolution/DPI and only them send the to DMT to process.

      For example:
      Your game health bar is 50% of the screen width, and placed at the middle of the screen.
      All you have to do is to resize it to 50% of the screen width, change the height in the same ratio, and you got the asset to give to DMT.

      This needs to be done once per resoution, DMT keeps a chache.

      Hope this helps.
      Gil

      Delete
    2. Thank you Gil for the quick answer.

      Ok, the example is perfectly explained.

      Only one more question: in the folder bin is the SWF, using your library I get this error:

      VerifyError: Error #1014: Class flash.filesystem::File could not be found.

      at com.xtdstudios.DMT::DMTBasic()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTBasic.as:36]

      It is about the cache?
      No problem with Air version.

      Once again great work and thank you.

      Victor

      Delete
    3. Please clone the DMT and XTDCommon repositories, and compile it with the sources files, you will be able to see the location of the error. this would give us a much better view of the problem.

      You can contact me directly: gil[shift-2]xtdstudios.com and I'll help you with your specific problem.

      Delete
    4. In Flashdevelop " Add to library" to DMT.swc and XTDCommon.swc.

      Starling 1.3
      Air 3.7
      Flex 4.6.0

      So the air version has no problem, but in the swf I get the next error:

      VerifyError: Error #1014: Class flash.filesystem::File could not be found.

      at com.xtdstudios.DMT::DMTBasic()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTBasic.as:36]
      at com.coolpixelshow.games.starlingTest::LibraryDMT/initDMT()[C:\Users\Biktor\GameDev\as3\projects\starlingTest\src\com\coolpixelshow\games\starlingTest\LibraryDMT.as:27]
      at com.coolpixelshow.games.starlingTest::LibraryDMT()[C:\Users\Biktor\GameDev\as3\projects\starlingTest\src\com\coolpixelshow\games\starlingTest\LibraryDMT.as:22]
      at starling.core::Starling/initializeRoot()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:338]
      at starling.core::Starling/initialize()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:314]
      at starling.core::Starling/onContextCreated()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:519]

      I tried differents paths to add the libraries with the same results.

      Delete
  6. Hi Gil,
    I'm trying your sample code but I get the following runt-time error:


    ReferenceError: Error #1065: Variable flash.display::PNGEncoderOptions is not defined.
    at com.xtdstudios.DMT.persistency.impl::ExternalAssetsGroupPersistencyManager()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\persistency\impl\ExternalAssetsGroupPersistencyManager.as:51]
    at com.xtdstudios.DMT::DMTAbsAPI()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTAbsAPI.as:55]
    at com.xtdstudios.DMT::DMTBasic()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTBasic.as:36]
    at com.xtdstudios.dmt.demo::HelloDMT()[/Users/axl/Documents/Adobe Flash Builder 4.6/DMT Test/src/com/xtdstudios/dmt/demo/HelloDMT.as:32]
    at com.xtdstudios.dmt.demo::ExamplesManager/nextExample()[/Users/axl/Documents/Adobe Flash Builder 4.6/DMT Test/src/com/xtdstudios/dmt/demo/ExamplesManager.as:59]
    at com.xtdstudios.dmt.demo::ExamplesManager()[/Users/axl/Documents/Adobe Flash Builder 4.6/DMT Test/src/com/xtdstudios/dmt/demo/ExamplesManager.as:39]
    at starling.core::Starling/initializeRoot()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:338]
    at starling.core::Starling/initialize()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:314]
    at starling.core::Starling/onContextCreated()[/Users/redge/Development/starling/starling/src/starling/core/Starling.as:519]


    It seems that PNGEcoderOptions Class doesn't exists!!

    What can I do?
    Thanks

    ReplyDelete
    Replies
    1. PNGEncoderOptions was introduced in AIR 3.3, you are probably using older version of AIR

      Delete
    2. Gil, I'm having the same issue with Air 3.9 (beta) . Any ideas?

      Delete
    3. Please contact me directly at gil [at] xtdstudios [dot] com with explenation

      Delete
    4. Seems like my Flash Player version was off. So the testing enviroment wasn't letting me test.

      Delete
  7. Hi Gil,
    can I embed Bitmap in a MovieClip into swf library?

    When I try to do that I get the following error:


    ArgumentError: Error #2015: Invalid BitmapData.
    at flash.display::BitmapData/ctor()
    at flash.display::BitmapData()
    at com.xtdstudios.DMT.atlas::AtlasGenerator/generateBitmapData()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\atlas\AtlasGenerator.as:159]
    at com.xtdstudios.DMT.atlas::AtlasGenerator/copyBitmaps()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\atlas\AtlasGenerator.as:240]
    at com.xtdstudios.DMT.atlas::AtlasGenerator/process()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\atlas\AtlasGenerator.as:274]
    at com.xtdstudios.common.threads::RunnablesList/process()[C:\Users\gil\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\threads\RunnablesList.as:63]
    at com.xtdstudios.common.threads::BasePseudoThread/onTimer()[C:\Users\gil\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\threads\BasePseudoThread.as:54]
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()


    I simply get the Hello-DMT sample project, import in my Flash Builder IDE and it works fine. Then I opened the HelloDMT-Assets.fla and I added a bitmap image to the Circle Layer 1.
    I exported the swf and I disabled the DMT cache. When the app runs in the AIR emulator I get the error.

    What is the problem?
    Thanks

    ReplyDelete
    Replies
    1. Please send your fla to gil[shift-2]xtdstudios.com

      Delete
    2. Same here... I created a new fla. Imported vector from an Illustrator file, it added to the library as a bitmap, then I created a movieclip and added the bitmap to it. Gave MC an id, and exported as swf. Using your sample project: HelloDMT I made it point to my new swf file, and I get the same error. Any ideas what this could be? Thank you.

      Delete
    3. I've found the bug and fixed it. I've updated DMT and the HelloDMT gitHub repositories.
      The problem was that DMT was using an old cache, when asked not to use cache at all.

      Delete
    4. Thanks Gil,
      I tried with your DMT library and HelloDMT updated but i get the same error!!

      Delete
    5. Only changing the dataName param on DMTBasic constructor it works!

      Delete
    6. Cache issue are very problematic:

      - I made a new fla with new MovieClip inside.
      - I changed the Embed declaration pointing the new swf file I made.
      - I tried to take off the cache, change cache version number, change name data string.
      - finally I got the following error:


      Error: assetDef was not found, base_box_sx_MC
      at com.xtdstudios.DMT.starlingConverter::StarlingConverter/convert()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\starlingConverter\StarlingConverter.as:192]
      at com.xtdstudios.DMT::DMTBasic/getAssetByUniqueAlias()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTBasic.as:110]
      at Main/dmtComplete()[/Users/alessioprosperi/Downloads/HelloDMT-master/src/Main.as:70]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at com.xtdstudios.DMT::DMTAbsAPI/onTexturesReady()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTAbsAPI.as:215]
      at com.xtdstudios.DMT::DMTAbsAPI/onGenerateComplete()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\DMTAbsAPI.as:207]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at com.xtdstudios.DMT::AsyncAssetsGroupBuilderImpl/onAssetsGroupReady()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\AsyncAssetsGroupBuilderImpl.as:194]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at com.xtdstudios.DMT::AssetsGroup/markReady()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\AssetsGroup.as:233]
      at com.xtdstudios.DMT::AsyncAssetsGroupBuilderImpl/processAtlases()[C:\Users\gil\Adobe Flash Builder 4.7\DMT\DMT\src\com\xtdstudios\DMT\AsyncAssetsGroupBuilderImpl.as:180]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at com.xtdstudios.common.threads::PseudoThread/dispatchEvent()[C:\Users\gil\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\threads\PseudoThread.as:51]
      at com.xtdstudios.common.threads::PseudoThread/notifyCompletion()[C:\Users\gil\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\threads\PseudoThread.as:41]
      at com.xtdstudios.common.threads::BasePseudoThread/onTimer()[C:\Users\gil\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\threads\BasePseudoThread.as:69]
      at flash.utils::Timer/_timerDispatch()
      at flash.utils::Timer/tick()


      It seems that the new MovieClips are not present!

      If you need my project files to test this issue let me know.

      Delete
    7. I also have the very same problem when trying to change cache version number... changing the dataname works fine but the problem is that the old textures will stay on sdcard. anyone else having this problem?

      Delete
    8. When you're in the development process, don't use cache... or, if you still want cache, you shouldn't care about previous texture, the end user will not have them...

      Delete
  8. Thanks for the fix... still have an issue here though. I'm doing this:

    1. Added a new MC to the HelloDMT fla

    2. Added this code to Main.as

    var rectangle : DisplayObject = new (ApplicationDomain.currentDomain.getDefinition("Rectangle"))
    rectangle.name = "rectangle";

    _dmtBasic.addItemToRaster(rectangle);


    then in dmtComplete function I added this at the end:

    var starlingRectangle : Sprite = _dmtBasic.getAssetByUniqueAlias("rectangle") as starling.display.Sprite;
    starlingRectangle.x = 300;
    starlingRectangle.y = 100;
    addChild(starlingRectangle);

    Once I run the project, and we get to this point, starlingRectangle is null... but I get no errors from dmt... it simply does not pull out "rectangle"

    Any idea what could be wrong? Thank you so much for the help

    ReplyDelete
    Replies
    1. This is a common mistake :-)
      You've told DMT that you want to rasterize a DisplayObject with NO child objects, so DMT will create a Starling Image class (Starling images can not hold children)
      If you've given Starling an object with Children (Like in the above example) DMD would have created a Sprite with child Images.

      According to your code, I see that you are trying to convert what DMT produced to a Sprite (as starling.display.Sprite), your rectangle is probably just an a starling.display.Image

      Delete
  9. I followed your example above, created my own SWF with vector graphics in it with symbol 'Head' (also included in the AS Linkage) but while testing in Air, the symbol won't be found. Any ideas whats happening ?


    Error message:

    ReferenceError: Error #1065: Variable Head is not defined.
    at flash.system::ApplicationDomain/getDefinition()
    at code::App/addVectorsToDMT()
    at code::App/onAssetsReady()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.xtdstudios.common.assetsLoader::BaseAssetsLoader/onComplete()

    ReplyDelete
    Replies
    1. Are you sure that you added a Linkage to it?
      Contact me directly: gilamran [at] gmail [dot] com

      Delete
  10. Thank you for this, it helped me heaps!
    Tried flash movie converter, dynamic texture atlas, and a bunch of other implementations but this is the ONLY converter at runtime that maintains full clip hierarchy and allows resizing/manipulating before rasterizing to texture. I love it!

    ReplyDelete
  11. What about TextField objects into MovieClip? Саn I access it after DMT convert?

    ReplyDelete
    Replies
    1. Any DisplayObject will be rasterized into Bitmaps, so DMT will convert your TextField, but it will be a Bitmap, so you can't change the text.

      Delete
    2. Thx. How do you think why Adobe (or Gamua) do not develop analog of Flash Pro IDE for gpu render (Starling) with full support of sprites/movieclips/textfields?

      Delete
  12. Hi Gil,

    I have a short question about forcing DMT to cast certain UI elements to certain types.
    For example I have many static images in my swf and DMT converts them as StarlingSpriteProxy but I would need them as StarlingImageProxy.

    Is there a way to force DMT to use StarlingImageProxy format or any way to cast StarlingSpriteProxy to StarlingImageProxy?

    Thanks for your answer in advance.

    Kind regards,
    Zsolt

    ReplyDelete
    Replies
    1. You should name all the children that you don't want DMT to dig into as "stop_raster" instance name.

      I've mentioned it in the "Troubles, Solutions, and some notes" section.

      Delete
    2. Thanks Gil for the answer, but I cannot rename the children as they are just drawing objects without any id.

      Delete
    3. If you asset contain only graphical objects DMT will convert it into an Image, You MUST put all graphical objects in MovieClips, so DMT can separate them.

      Hope this helps.
      If you still having problems, contact me directly (give me your email) and I'll debug your issue.

      Delete
    4. Thanks for your help in advance.
      Please send me a reply to velykovits at gmail and I will send you the code.

      Delete
  13. Hi, just wanted to see if you have any other games besides that match 3 you had a year ago?

    ReplyDelete
    Replies
    1. We are working on MemoryCards 2 :-)
      It will be much much more than a memory game!

      Delete
  14. Wondering how to use DMT with assets bigger than 2048x2048. Tried splitting it into 2 bitmapData, but even thou they are two different bitmaps, DMT seems to think its the same asset an load the half part twice. Any idea?

    ReplyDelete
    Replies
    1. The 2048 is AIR's limitation.
      To make DMT recognize assets they must have a unique linkage in the library.

      Delete
    2. But i can set the 3dContext To BASELINE_EXTENDED.

      I'm only targeting on device.

      Delete
    3. The latest version of DMT support 4096x4096, just use BASELINE_EXTENDED (Starling support "auto" in the constructor to find the best profile possible)

      Delete
  15. Good news! DMT now support 4096x4096 textures, pull

    ReplyDelete
  16. I'm trying to use DMT for a non-AIR project, but it seams to be uncompatible, is there a trick or a version for non-AIR environment ?

    ReplyDelete
    Replies
    1. Try to take the latest DMT, and the latest XTDCommon.
      If you still can't do it, contact me directly.

      Delete
  17. Hi Gil,

    For a strange reason I cannot use RenderTextures with StarlingImageProxy or StarlingSpriteProxy.

    If I draw the image that I get after the DMT conversion, the rendertexture remains empty.

    Do you know what can cause this phenomena?

    If I draw a conventional starling image it works fine.

    Thanks for your answer in advance.

    Kind regards,
    Zsolt

    ReplyDelete
  18. I don't understand your question, please contact me directly

    ReplyDelete
  19. I built SWCs from the latest version of DMT & XTDCommon and put them into this sample code(and the same MovieClip swf), because I wanted to test this library for the flash web app that I've been working on. (so I turned the cache mode off)

    And the result is like this :

    ReferenceError: Error #1065: Variable Square is not defined.
    at flash.system::ApplicationDomain/getDefinition()
    at Main/addVectorsToDMT()[C:\Users\home\Adobe Flash Builder 4.7\HelloDMT\src\Main.as:53]
    at Main/onAssetsReady()[C:\Users\home\Adobe Flash Builder 4.7\HelloDMT\src\Main.as:48]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.xtdstudios.common.assetsLoader::BaseAssetsLoader/onComplete()[C:\Users\home\Adobe Flash Builder 4.7\XTDCommon\src\com\xtdstudios\common\assetsLoader\BaseAssetsLoader.as:121]

    I got same errors that Vlad posted above. It seems the getDefinition cannot find the linkage of the MovieClips.

    Any help would be appreciated.

    ReplyDelete
    Replies
    1. Did it work before? Did you include the SWF in the project?
      Can you send me your project (Zipped) by email?

      Delete
    2. Thanks, It works like a charm!
      Really appreciated.

      Delete
    3. I'm having the same issue with the swf file GilAmran provided in this tutorial.
      Would you pls let me know how did you fixed it?

      Thanks a lot!

      Delete
  20. Hi Gil
    Starling has a delay that textures are uploaded to GPU memory.
    Will DMT has the same issue?

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Gil, do I have to use Flash? I'd like to just load up my high res images and spritesheets into starling, resize, run through DMT and display. Instead of dealing with movieclips. Is this possible or am I totally missing the point of DMT? :/

    ReplyDelete
  23. Gil, do I have to use Flash? I'd like to just load up my high res images and spritesheets into starling, resize, run through DMT and display. Instead of dealing with movieclips. Is this possible or am I totally missing the point of DMT? :/

    ReplyDelete
  24. If you are using high res images, use the Flash display tree to construct your scene with your images, and let DMT convert it to textures.

    But you are missing the point of DMT, the only reason to go this way is to save GPU memory, on images that you can't draw in vectors.

    ReplyDelete
  25. Hi Gil, how can i scale a circle 2 times bigger?

    ReplyDelete
    Replies
    1. Just make sure that it's scaled 2 times (scaleX = 2 and scaleY = 2) before you send it to DMT.

      Delete
  26. [Embed] tag not work on iOS, how to fix it?

    ReplyDelete
    Replies
    1. Ok, i use AssetsLoaderFromExternalURL.

      Thanks

      Delete
  27. I scaled the objects before sending to DMT to process:

    var obj : flash.display.DisplayObject = new (ApplicationDomain.currentDomain.getDefinition(item));
    obj.name = item;

    // scale before rasterizing
    obj.scaleX = obj.scaleY = _dmtScaleFactor;

    _dmtBasic.addItemToRaster(obj);

    The generated texture atlas is correct, however, when I do getAssetByUniqueAlias(name), it returns a starling DisplayObject with doubled size and blurry texture.

    My stage size is 480x320, my viewport is 640x960, the swf graphics were designed in 640x960 resolutions.

    Would you pls help?

    ReplyDelete
    Replies
    1. Your viewport should be the same as the stage size.
      Starling is probably re-sizing your assets

      Delete
  28. Hi Gil,

    When using getAssetByUniqueAlias I keep getting:
    [Fault] exception, information=ArgumentError: Texture cannot be null

    Up until this point everything works; what could be the reason that I am unable to fetch my assets?

    Thanks!

    ReplyDelete
    Replies
    1. Ah yes, of course, sorry!
      I'm using FlashDevelop 5.0.2.2 and compiling to AIR for mobile.
      Tracing has shown that the swf file is loaded and the assets added to DMT, but after that I can't seem to get them out again.

      In the dmtComplete function, which is called when DMT is done, I'm calling initStarling to start initializing Starling.
      A listener is added to starling
      myStarling.addEventListener(starling.events.Event.ROOT_CREATED, onRootCreated);

      Inside the onRootCreated, I use
      _dmtBasic.getAssetByUniqueAlias("bgMain")

      But it says:
      [Fault] exception, information=ArgumentError: Texture cannot be null

      In order to add this asset, I've used:
      var bgMain:flash.display.DisplayObject = new (ApplicationDomain.currentDomain.getDefinition("background_main"));
      bgMain.name = "bgMain";
      _dmtBasic.addItemToRaster(bgMain, "bgMain");

      I hope this helps, otherwise, maybe I can send the project and if so, where do I send it to?

      Thanks a lot for your time and effort!

      Delete
    2. Please send me a simple example to gilamran [at] gmail [dot] com

      Delete
  29. Hi Gil,

    Thanks, will do and thanks again!

    ReplyDelete
  30. Hello Gil! Need your advice: how can I use DMT without AIR?

    ReplyDelete

Powered by Blogger.