I need help migrating from Genome2D 1.0.255 to the current version

85 views
Skip to first unread message

Tommy Coloma

unread,
Sep 16, 2016, 8:46:17 PM9/16/16
to Genome2D
I've been trying to update the version of Genome2D that I am using in my project for a while, but I just can't quite get things right. A few methods were changed or replaced, and I have no idea how to use the updated versions. Here is all the Genome2D-related code that I am currently using. Can anyone walk me through what needs to be changed?


[ Embed( source = "/assets/complete_spritesheet.png" ) ]
public static const CompleteSpritesheet:Class;
public static var completeSpritesheet:BitmapData = new CompleteSpritesheet().bitmapData;

[Embed( source = "/assets/complete_spritesheet.xml", mimeType="application/octet-stream" )]
public static const CompleteSpritesheetXML:Class;
public static var completeSpritesheetXML:XML = XML( new CompleteSpritesheetXML() );

public var genome:Genome2D;
public var context:IContext = null;
private static var texture:GTexture;

public function GenomeMigration102()
{
       var config:GContextConfig = new GContextConfig(new Rectangle(0,0,stage.stageWidth,stage.stageHeight), stage);
 
       
        genome = Genome2D.getInstance();
       genome.autoUpdateAndRender = false;
   
        genome.onInitialized.addOnce(genome2DInitializationCompleted);
 
       genome.init(config);
}


private function genome2DInitializationCompleted():void
{
       trace( "Genome2D version" + Genome2D.VERSION + " initialization completed" );
 
        mouseEnabled = false;
       mouseChildren = false;
 
       GTextureAtlasFactory.createFromEmbedded( "textures", CompleteSpritesheet, CompleteSpritesheetXML );
       context = Genome2D.getInstance().getContext();
       addChild( new InitializeGenome2D() );
}



[Inline]
private final function genome2DLoop( e:flash.events.Event ):void
{
      var colorInHex:uint = 0xFF8000;
      Genome2D.getInstance().getContext().begin( ( ( ( colorInHex & 0xFF0000 ) >> 16 ) / 255 ), ( ( ( colorInHex & 0xFF0000 ) >> 16 ) / 255 ), ( ( ( colorInHex & 0xFF0000 ) >> 16 ) / 255 ), 1 );
      mainLoop();
      Genome2D.getInstance().getContext().end();
}

[Inline]
private final function mainLoop():void
{
      // do blitting stuff
}


private static function blitHelper( imageName:String, x:Number, y:Number ):void
{
       texture = GTexture.getTextureById( "textures_" + imageName );
       texture.setFilteringType(GTextureFilteringType.NEAREST);
       texture.pivotX = 0 - ( texture.width / 2 );
       texture.pivotY = 0 - ( texture.height / 2 );
       R.context.draw( texture, x, y, R.currentScale, R.currentScale);
}

public function blitRectangle( x:Number, y:Number, width:Number, height:Number, colorInHex:uint = 0xFF8000, a:Number = 1 ):void
{
       context.drawColorQuad( ( x + ( width / 2 ) ), ( y + ( height / 2 ) ), width, height, 0, ( ( ( colorInHex & 0xFF0000 ) >> 16 ) / 255 ), ( ( ( colorInHex & 0x00FF00 ) >> 8 ) / 255 ), ( ( colorInHex & 0x0000FF ) / 255 ) );
}

sHTiF

unread,
Sep 17, 2016, 12:04:19 PM9/17/16
to Genome2D
Can you mark lines that are problematic? I am not sure about all the things that changed and don't know what exact version you are using.

I can definitely say that drawColorQuad is obsolete function there are no color draws anymore as it was better to simply use single color textures so just create a small texture filled with a color and just call normal draw() method.

Tommy Coloma

unread,
Sep 19, 2016, 4:55:28 AM9/19/16
to Genome2D
OK. For starters, GTextureAtlasFactory does not seem to exist any more. Is there a new equivalent?

GTextureAtlasFactory.createFromEmbedded( "textures", Spritesheet.CompleteSpritesheet, Spritesheet.CompleteSpritesheetXML );

I might be able to figure the rest out with what you have in the docs page. If not, I'll return with more questions.

Thanks.

sHTiF

unread,
Sep 19, 2016, 10:38:43 AM9/19/16
to Genome2D
Oh sure there is GTextureManager now and embedded is no longer supported due to multiplatformity so you will need to create the BitmapData from your embedded assets yourself first then create a texture from it and then add all the subtextures.

// Create a bitmap data from your embedded asset
var bitmapData:BitmapData = new EmbededAsset();

// Create a texture from that bitmap data
var texture:GTexture = GTextureManager.createTexture("texture", bitmapData);

// Create all the subtextures on that texture according to atlas data
GTextureManager.createSubTextures(texture, assetXml);


Hope it helps.

Tommy Coloma

unread,
Sep 21, 2016, 1:57:30 PM9/21/16
to Genome2D
I put a static GContext variable in R.as 

public static var context:GContext = null;

and instantiate it during startup.

R.context = Genome2D.getInstance().getContext();

Then I use it for blitting in my main game loop.

R.context.draw( texture, x, y, R.currentScale, R.currentScale);

However, GContext does not exist any more either. How is this done in the current version of Genome2D?

Tommy Coloma

unread,
Sep 21, 2016, 4:25:13 PM9/21/16
to Genome2D
I cheated for now and just made R.context of type Object. My next issue is that the following doesn't work:

GTextureManager.createSubTextures(Spritesheet.texture, Spritesheet.completeSpritesheetXML );

I can't figure out how to convert an XML to Xml. My assets are embedded in Spritesheets.as using the following:

[Embed( source = "/assets/complete_spritesheet_starling.png" ) ]

public static const CompleteSpritesheet:Class;
public static var completeSpritesheet:BitmapData = new CompleteSpritesheet().bitmapData;
 
[Embed( source = "/assets/complete_spritesheet_starling.xml", mimeType="application/octet-stream" )]

public static const CompleteSpritesheetXML:Class;
public static var completeSpritesheetXML:XML = XML( new CompleteSpritesheetXML() );

How do I make the Xml conversion using the above? Everything I try results in a "null object reference"

sHTiF

unread,
Sep 21, 2016, 5:56:11 PM9/21/16
to Genome2D
GContext is now IGContext, in Haxe its actually an interface which all the platform dependent contexts needs to implement but since by compilation to SWC its clear that only Flash related context GStage3DContext is the only viable one I use macros to natively compile/typedef the GStage3DContext to IGContext instead of keeping the interface/implementation due which would result in interface function call overheads. So since you are using SWC just use IGContext class inside it.

sHTiF

unread,
Sep 21, 2016, 5:58:43 PM9/21/16
to Genome2D
You can't use flash native XML anymore since Genome2D doesn't use it internally, obviously due to multiplatformity since flash native XML is Flash target dependant.

Genome2D now uses Xml which is Haxe xml implementation that is platform independent, it is compiled into the Genome2D SWC and you can use it instead of the Flash native XML.

Check out the API here http://api.haxe.org/Xml.html

Its pretty simple to create a valid Xml instance just load your file and parse the string using Xml.parse(fileData);

Tommy Coloma

unread,
Sep 23, 2016, 8:08:23 PM9/23/16
to Genome2D
Alright. I (hopefully) have one last issue. Since drawColorQuad is now obsolete, I have been trying to use the draw() method as you had suggested. I added a white 1x1 pixel image to my spritesheet, created a texture using that, and tried manipulating it as shown down below:

01: var newWidth:uint = width * R.currentScale;
02: var newHeight:uint = height * R.currentScale;
03: var newX:int = x * R.currentScale;
04: var newY:int = y * R.currentScale;
05:
06: texture = GTextureManager.getTexture( "textures_" + "pixel_texture_white" );
07: texture.filteringType = GTextureFilteringType.NEAREST;
08: var rectangle:Rectangle =  new Rectangle( 0, 0, newWidth, newHeight ) ;
09: texture.region = rectangle;

10: R.context.draw( texture, (x +  ( width / 2 ) ) * R.currentScale,(y + ( height / 2 ) ) * R.currentScale  );

What I was trying to do was create a 1x1 texture and then expand its width and height to newWidth and newHeight using what's in lines 8 and 9, but that doesn't work as expected. How do I expand the 1x1 texture to create a solid rectangle?


On Saturday, September 17, 2016 at 9:04:19 AM UTC-7, sHTiF wrote:

Tommy Coloma

unread,
Sep 24, 2016, 6:41:01 PM9/24/16
to Genome2D
Damn. I finally figured it out. The answer was right in front of my face. For some reason I missed the fact that scaleX and scaleY were parameters in draw(). As usual, I over-complicated things. Here's how I did it -

08: //var rectangle:Rectangle =  new Rectangle( 0, 0, newWidth, newHeight ) ;
09: //texture.region = rectangle;
10: R.context.draw( texture, (x +  ( width / 2 ) ) * R.currentScale,(y + ( height / 2 ) ) * R.currentScale, newWidth, newHeight );

sHTiF

unread,
Sep 28, 2016, 4:12:07 PM9/28/16
to Genome2D
Glad to hear you figured it out, I hope you finished the migration without further issues.
Reply all
Reply to author
Forward
0 new messages