Does NME (or haxe?) support importing resources from an SWC file?

From what I read about haxe it doesn't support it, but it supports SWF, although it won't compile for platforms other than flash. Does NME implement any way to import resources from an SWC or SWF file, and if so, does it keep compatibility between differe…

Viewing 1 to 15 (15 Total)
Does NME (or haxe?) support importing resources from an SWC file?

mlopes

mlopes
Total Posts: 42
Joined: November 20, 2011

From what I read about haxe it doesn't support it, but it supports SWF, although it won't compile for platforms other than flash. Does NME implement any way to import resources from an SWC or SWF file, and if so, does it keep compatibility between different targets?

Cheers,
Marco Lopes

Tags:
Posted on December 21, 2011 at 11:25 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

You can add a -swf-lib flag to embed assets from an external SWF file. An SWC is actually a ZIP which contains a SWF inside. You can only use this for the Flash target, so the best way to include cross-platform assets is through images and sprite sheets. One of the things we are brainstorming are ways to improve the workflow, so it would be great if you had any suggestions or ideas

Posted on December 21, 2011 at 12:04 PM

mlopes

mlopes
Total Posts: 42
Joined: November 20, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Hi,

For my specific case, the solution I was thinking about, was to define a different "assets folder" using the if target attribute on the assets tag for each target.
The problem with this one is that there's no way, that I know of, to change the assets folder to compile for iPhone 3GS using the images for 320 × 480, compile for iPhone 4(S) using the images for 640 × 960.The same goes for Android.
To minimize the problem of Androids having a potentially infinite number of resolutions, I was thinking about supporting 3 resolutions, 320x480 for mobile, 640x960 for HD mobile/pads and 480x720 for flash/desktop.

On the top of my head, the only solution I can think of, is to be able to use the resolution on if attributes, but even then, compiling two resolutions for 1 target would require manual changes on the nmml file.

Cheers,
Marco Lopes

Posted on December 21, 2011 at 4:21 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

These are two other ways you may be able to handle it:


1.) Custom variables in your NMML

In addition to variables like "flash" or "android", you can define your own. You can either set them using <set name="myvariable" />, or you can add -Dmyvariable to the command-line when you are compiling your NME project. With this method, you could have custom variables to define which asset size you wish to embed.


2.) String-based names in your code

The above approach works if you will have separate application packages for each set of assets, but what if you need multiple resolutions in the same package? The easiest way is to embed everything you need, and to use a helper class or function to generate the string for the path you will need. For example:

Assets.getBitmap ("assets/images/" + imageQuality + "/Background.png");

Posted on December 21, 2011 at 4:52 PM

mlopes

mlopes
Total Posts: 42
Joined: November 20, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

The first solution, mixed with the already existing if and unless seem good. To me it seems cleaner and more elegant that the second one and prevents those issues from slipping into the code of our application and causing us to be writing code not for what we want to do but to solve platform problems.
Also it helps to separate the application from the compilation options and helps the code to be more reusable as it isn't bound with an issue that may be part of an application but not from another.

Cheers,
Marco Lopes

Posted on December 21, 2011 at 5:14 PM

Huge

Huge
Total Posts: 547
Joined: October 07, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Hi,
I think a good way to go here is to use the gm2d library to convert your swf to bitmaps at runtime. This library is not 100% yet, but it is getting there.
It seems to me that vector (or at least resolution independent) solutions are becoming more important since there are quite a number of resolutions that could be supported.
Hugh

Posted on December 21, 2011 at 7:25 PM

mlopes

mlopes
Total Posts: 42
Joined: November 20, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Didn't knew about gm2d library, but the question here is, how ready/stable and how fast is it? Games usually need a quite large number of images, won't that take to long to convert and won't it force the resulting png's to be all in memory at the same time?

How does Apple react to iOS app's that have swf files among their resources, wouldn't that be an obstacle for their approval?

Cheers,
Marco Lopes

Posted on December 22, 2011 at 1:15 AM

aholla

aholla
Total Posts: 31
Joined: November 03, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Can you use "-swf-lib" with NME, if so how? In FlashDevelop would it be in "Pre-Build Command Line or though Additional Compiler Options?

The reason I ask is because I wanted to use Nape Physics engine but the lib comes as a swf or swc. If you can use "-swf-lib", would the code work with hxcpp?

Posted on December 22, 2011 at 4:14 AM

postite

postite
Total Posts: 39
Joined: October 02, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

there is something on the way from philippe priou apparently

http://haxe.1354130.n2.nabble.com/NME-Using-SWF-td6871223.html#a710...

Posted on December 22, 2011 at 6:11 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

aholla:

You should be able to add the "-swf-lib" flag to an NMML project file, like this:

<compilerflag name="-swf-lib=/path/to/lib.swf" />

Also, there is an up-to-date haxe port of Box2D, and I believe there is also a haxe version of Nape, too, FYI.

Posted on December 22, 2011 at 10:05 AM

aholla

aholla
Total Posts: 31
Joined: November 03, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

@singmajesty Thanks for the info, you've actually just solved another of my problems! Also I have implemented your version of Box2D, thanks for the port, I am currently testing a few different engines, so far I prefer Box2D over Physaxe (documentation is better and the speed is quite similar) and I am currently testing Nape, so far it's faster in my tests but I can't get it to do anything in javascript.

I have only just realised about "<compilerflag>". Is there any way, to wire Flash Develope's "Additional Compiler Options" into this?

Thanks


@postite I did see that post, will have to wait and see I guess.

Posted on December 22, 2011 at 11:00 AM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Should SWF/SWC assets work with the html5 (leash) target as well? I have seen from the old haXe list (http://haxe.1354130.n2.nabble.com/NME-Using-SWF-td6871223.html) that this is to work with flash and cpp targets, but I have not seen html5 discussed. I had played with gm2d and I know its swf support has been integrated into NME, but gm2d did not generally have provisions for html5.

I will play around with it.

Posted on January 03, 2012 at 7:18 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

I didn't mention HTML5, because I'm not sure how byte manipulation works in Javascript. Can you read or write binary formats directly?

That would be the first hurdle. Afterward, I'm not if Jeash supports all of the shape drawing commands, which are used when loading SWF shapes or static fonts.

If there are limitations to using the format in HTML5, directly, we may consider creating some type of standalone application written in NME, which could parse SWFs and export them to another format...

Posted on January 03, 2012 at 7:28 PM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

Ah OK, makes sense.

Similar to you I have not directly manipulated bits in JavaScript, but I know it is possible (see "Performance of Javascript (Binary) Byte Arrays in Modern Browsers" athttp://blog.n01se.net/?p=248 for example).

I agree it might be better for there to be an NME intermediary.

What does spaceport.io do behind the scenes, I wonder? convert everything to bitmap sprite sheets?

Posted on January 03, 2012 at 7:37 PM

grumpytoad

grumpytoad
Total Posts: 63
Joined: November 21, 2011

Re: Does NME (or haxe?) support importing resources from an SWC file?

jeash handles Binary data using normal arrays, implements the IEEE754 RFC to emulate doubles, and works around 31-bit Integer operations.

In future the implementation may switch to typed arrays, if I see more people actually using the code.

The swf would need to be retrieved using a binary URLLoader, or by serializing a ByteArray object in CPP and unserializing it in js.

I am not too keen on adding the swf code directly to jeash, though I do not see any reason that it would not work with jeash, it does need some legwork though.

Posted on January 07, 2012 at 2:28 PM