r/futile • • Jun 15 '13

New version of Futile is out! (0.91.1)

33 Upvotes

Hey everyone! A new version of Futile is finally out.

If you've been using the development branches then you've probably already seen most of the new features, but otherwise you're about to get a ton of new stuff.

Oh also, from now on the unitypackage will no longer live in the git repo, instead I will keep it freshly updated (in-sync with master) at http://struct.ca/futile - also, there is now a new version of the unitypackage that has no demos, so if you just want to update Futile itself, this is the thing to use.


Some quick migration tips and info:

  • The Unity project in the repo has been renamed to FutileProject (it used to be BananaDemoProject)

  • Everything Futile needs is now in Assets/Futile

  • The Banana demo (and soon, more demos) are in Assets/FutileDemos

  • Before putting the new stuff in, make sure to delete everything in /Plugins: so /Futile as well as GoKit.dll, MiniJson.cs and MiniJsonExtensions.cs

  • Also make sure to delete Assets/Resources/Shaders/Futile

  • Futile element names no longer expect a .png extension, so you now say new FSprite("Banana") instead of new FSprite("Banana.png");

  • However, if you set Futile.shouldRemoveAtlasElementFileExtensions = false before initializing Futile, you can keep using extensions if you prefer that.

  • The atlasManager.LoadFont() call now requires an offsetX and offsetY parameter. These will offset text from that font everywhere (I found that BMFont files didn't give accurate enough information, so being able to tweak positions globally is very handy).

  • Futile.width is now Futile.screen.width (etc.)

  • FWatcher is now RXWatcher (more on what this is later)

  • node.MoveToTop() and MoveToBottom() are now MoveToFront() and MoveToBack()

  • FShader.Normal has been renamed to FShader.Basic (this probably won't affect many people)

  • For those who've doing advanced stuff, FFacetElementNode now is what FFacetNode was before (FFacetNode is now a more basic class), in other words, if you had a class that previously extended FFacetNode, make it extend FFacetElementNode instead.


With this github link you can see all of the commits from the old version (from back in September!) to now: https://github.com/MattRix/Futile/compare/eabd48b...3500250513


FEATURE LIST:

  • Unity 4 support

  • Support for meshes and objects made from triangles (not just quads)

  • FSliceSprite (for doing 9-slice objects)

  • FWipeSprite (for doing sprites that reveal horizontally or vertical, ex. a progress bar)

  • FRadialWipeSprite (for doing sprites that reveal circularly, ex. a circular spinner thingy)

  • FRepeatSprite (a sprite with a repeating texture)

  • FGameObjectNode (inject a custom unity object into the middle of a Futile scene)

  • FUnityParticleSystemNode (use Unity's robust particle system in Futile)

  • FParticleSystem (a very simple, super-efficient particle system designed for Futile)

  • FDebugFrameRateGraph (a fancy frame rate graph thing)

  • Lots of new convenience methods, ex. someNode.SetPosition(), someNode.SetAnchor(), someNode.GetLocalMousePosition(), someNode.GetLocalTouchPosition(someTouch) and tons more

  • MouseOver support and custom hitrects on FButtons (note: FButtons will be getting an overhaul before Futile hits 1.0)

  • New support for loading png files directly from bytedata instead of having Unity's usual huge image assets, this helps a TON with file size, especially on iOS and Android

  • FPhysics (this is still very early, but it works great if you understand how Unity's physics work)

  • RXRandom (get random floats, ranges, vectors, select objects randomly from lists/arrays, etc.)

  • RXExtensions (fun stuff like someList.GetLastObject(), someList.Log(), etc.)

  • RXUtils (tons of handy stuff, like HSL colors, colors from hex numbers, angle deltas, etc.)


One of the coolest (but trickiest to explain) new features is something called "FNodeEnablers". These are things that only run when an FNode is on the display list. What this means is that you can now call someNode.ListenForUpdate(SomeMethodName) and SomeMethodName() will be called every update tick. Yes, this means NO MORE having to do that messy HandleAddedToStage and HandleRemovedFromStage stuff!

Here's a list of the new enabler methods:

someNode.ListenForUpdate(SomeMethodName); someNode.ListenForFixedUpdate(SomeMethodName); someNode.ListenForLateUpdate(SomeMethodName);

someNode.ListenForResize(SomeMethodName); someNode.ListenForOrientationChange(SomeMethodName);

someNode.EnableSingleTouch() [the node must implement the FSingleTouchableInterface] someNode.EnableMultiTouch() [the node must implement the FMultiTouchableInterface]

Again, you do NOT have to remove these enablers manually (unless you want to for some reason), they will automatically be enabled/disabled when the node is added and removed from the display list.


Along with this stuff, I've also started creating a suite of generic "debugging" classes, including a simple memory profiler (RXProfiler, which keeps track of how many instances are live), a logger (RXDebug) and a watcher (RXWatcher, which is really cool).

If you've been wanting to edit values at runtime, I highly recommend trying the RXWatcher. Simply call RXWatcher.Watch(someObject) and that object will show up in the Unity hierarchy, where you can tweak its values at runtime. Note: the values won't be saved, so you have to manually input the new values into your code yourself, but it's still REALLY handy for tweaking things. Oh and you can even do RXWatcher.Watch(typeof(SomeStaticClass)) if you want to edit static values at runtime.


Phew! Ok that's about it. There are a ton of new things here, so I'm sure there will be a few questions. Let me know which features you'd like more information about. I'm going to start (gradually) working on some documentation and new instructional videos in the lead up to releasing 1.0 (which probably won't be until fall).

Oh also! If you want to see the new physics stuff in action, grab this project: https://github.com/MattRix/TOJam8 (I made it at a game jam, so the code is pretty rough, but it's worth having a look at anyway).

Cheers!

-Matt


r/futile • • Mar 03 '14

Mini Metro, subway construction game built with Futile, now in open alpha

22 Upvotes

Hi everyone,

My subway layout game, Mini Metro, is finally in open alpha and playable at http://dinopoloclub.com/minimetro. Please check it out if it sounds like your thing and let me know what you think! And of course, like everything else these days, it's on Greenlight.

Thanks so much Matt for releasing Futile, it's such a great way to do this style of cross-platform development in Unity! You saved me from the silly decision of using my own engine. :)

Peter


r/futile • • Aug 12 '12

Futile tips

22 Upvotes

Just wanted to make a post with a few tips.

Feel free to comment with any tips of your own.

  • Switch textures to "advanced" and turn off mip maps

  • Make sure your max texture size is set to the same size as your image, Unity defaults to 1024x1024 for all images

  • Turn off dynamic batching and static batching, you don't need them, Futile does it for you

  • If you're developing for Android and getting weird audio, go into project settings -> audio -> and set audio to stereo (the default is mono)

  • Switch texture filtering to "point" if you want pixel perfect stuff while scaling and rotating.

  • Even if you have specific resolution settings set up, Unity will still run your stuff at scaled-down resolutions in the editor if there isn't enough room for your chosen resolution.


r/futile • • Nov 01 '12

An update on the status of Futile

19 Upvotes

Hey everyone,

I've received a few questions about what the status of Futile is, and whether I'm still working on it, etc. etc.

Long story short, yes I'm still working on Futile. For a few weeks in September I was working on a game/app/thing (using Futile) and then for the entire month of October I was completely completely knocked out by being sick with mono. I'm finally getting over that illness now, which means I'm back to working on Futile.

So what am I working on? Mainly a big new update with lots of bug fixes and new features. I'm planning on fixing everything that's been submitted to the issues list on github: https://github.com/mattrix/Futile/issues (note that if you've posted about a bug here on r/futile, I've probably put it in that issues list already).

For new features, here are some things I'm looking into:

  • Better mouse support (mouseovers, right clicks, etc.)

  • Using Futile as a UI layer on top of a normal 3D Unity game. (I know there are already people that have done this, but I want to make it easier)

  • Making text rendering more robust, right now it can sometimes be blurry in certain situations.

  • Integration with system keyboards for typing (especially on mobile)

  • Particle system support (either using Unity's built in particles, or custom Futile particles, or both)

  • 2D Physics engine support (will integrate with Unity's physics, probably as a separate system that ties into Futile)

So yeah, those are the major things. There will also be a whole lot of smaller changes that will help to streamline the process of making games with Futile.

I don't have a firm date for when this stuff will be finished, but I'm hoping for before the end of November.

Also: My wife is actually due to have a baby sometime in the next month, so that will also affect the timing of things, hah :D

The main point of this message is just to point out that yes, I am still actively working on Futile.


r/futile • • Jul 26 '13

I made a script + template for generating new Futile projects

15 Upvotes

Hi everyone:

I create a lot of Futile projects. Every time I want to prototype something quickly I found myself copying a lot of files around from existing projects just so I could get something rendering on the screen.

Matt posts some great Unity package files on the Futile site: http://struct.ca/futile/ but I have a bunch of art pipeline scripts that generate atlases for me, copy fonts into the right place, etc. I also wanted a bunch of default script files in the right place so that I could just start writing game code and not worry about initializing futile, loading atlases, etc. So I decided it was time to create a bash script that set up a project for me.

I posted about it on twitter and a bunch of people asked me to post it somewhere. You can now find it here:

https://github.com/otrain13/FutileTemplate

It's a bash script, so it's really only meant for running on a Mac. If someone wants to make a Windows script and push it to the repo, send me a push request and I'll add it.

I have no idea if it will be useful to anyone else, but it's made setting up new projects really easy for me. :) Enjoy!


r/futile • • Aug 14 '14

Mini Metro, made with Futile, now on Steam & Humble Store

14 Upvotes

I posted about Mini Metro back in March when we were up on Greenlight. Now we've finally got ourselves to beta, and went up on Steam Early Access on Monday.

http://store.steampowered.com/app/287980 https://www.humblebundle.com/store/p/minimetro_storefront

Futile saved us a ton of work early on in development. As our vertex counts have crept up and up though, we've had to rework how Futile does some things. In hindsight the neat optimisations that Matt's done for working with sprites didn't lend themselves well to the large meshes we generate. Just one of those things you don't realise until you're most the way through the project! Once we're out the door I plan on doing a write-up on how it all panned out.


r/futile • • Jul 08 '13

Nimble Quest (made with Futile) was just released on Ouya

Post image
13 Upvotes

r/futile • • Aug 17 '13

I made some Futile physics wrappers called WTPhysicsNode and WTPhysicsComponent. Makes it a lot easier to get a physics scene up and running!

12 Upvotes

I've made a lot of comments on the repo so I encourage you to clone it, test it out, and read through the comments to make sure you understand its usage.


r/futile • • Apr 23 '13

Here are some classes that will allow you to easily draw polygons in code. And also you can test for intersection between circles and polygons.

Thumbnail
wtrebella.com
12 Upvotes

r/futile • • Jul 21 '13

Took a crack and dynamic shadows. Was really rough. Anyone else care to take a crack at it?

11 Upvotes

Here is a gif showing the results. A little choppy/rough but it has potential I think:

So what I ended up starting with was raycasting and shaders. I couldn't get anything to work since I know nothing about shaders :( . HOWEVER, the rays were great for getting some raw points. Here's the process:

  1. get the four corners of whatever I'm casting a shadow on. Calculate distance to light source. you don't need the furthest point no matter what, as the shadow goes over it. The nearest point isn't needed either really. You now have the two top points of the shadow. These are the top of the rays.

  2. I wanted to have all the shadows go off the screen for now, so I calculate for each point how much the x value changes between the light source and the original point, and how much the y value changes. I just set the next point about 4 times that ratio. I do a check to make sure its bigger than the screen, and if not add a little more. These are going to be the bottom points of the shadow.

  3. Now using these four points, instead of making rays, I used them to make trapezoids from this tutorial: http://wtrebella.com/drawing-with-futile/ the top points were used to help me calculate the inset, and the bottom points were used for the width. Then I just had to calculate height from the points. The draw back to this was that angle on both sides of the generic trapezoid were the same. In the ray based shadows the top of the shadow could be a different angle than the bottom of the shadow.The rays were great calculations of the shadows, here's a video demonstrating the rays:

that's what would've looked the best.

4. rotation and centering is where it got hairy. What I ended up doing was making a "shadow" fcontainer. The fcontainer would do all the rotation in relationship to the light source, and I would physically move the sprite of the shadow back a equal amount to light source. In other words its actually centered to the light source, rotated, then the sprite is pushed back.

6. For now I just trash the light source when making a new one. It'd be more effective to REUSE the containers and sprites, but that's beyond the scope of this simple project.

The code is so sloppy and rough, maybe someone can either help me use the rays to actually make a good shadow, or use my steps but with wayyyy cleaner code. I know lighting and shadows are a popular topic, but doing it with Futile/Unity isn't 100% obvious or clear. The fps was good overall as long as you're not casting shadows on tons of objects - I tried it on enemies and the player for my platform game. It looked wayyy too odd as a shadow for that platformer, but for a top down game it might work well. It could also be improved by having a gradient as the texture, so it fades off into the distance.

-edit

btw its took a crack AT dynamic shadows. I promise I didn't take crack :)


r/futile • • Aug 20 '12

Futile 0.6 alpha is out!

11 Upvotes

I pushed all the new changes that were in development to the master on GitHub, so now the stuff I've been working on for the past week is there.

You can read the full list of commits here: https://github.com/MattRix/Futile/pull/8

You can get the actual files here: https://github.com/mattrix/Futile (the Unitypackage is up-to-date too)

To summarize the big changes:

  • Multiple stages that are transformed using GameObjects

  • stage.Follow() and stage.CenterOn() which can be used to treat stage movement like a camera

  • Breaking out screen related stuff into Futile.screen (width,height, orientation, etc.)

  • Many performance tweaks, including using more efficient loops

  • FRepeatSprite - for doing tiling backgrounds with scrolling

  • Fixing a bad bug in GoKit

  • Renamed "Helpers" to "Extras"

The only major change to the API is that now width+height will be at Futile.screen.width instead of Futile.width, and so will all the orientation stuff. It made a lot of sense to break all the screen-based functionality into a separate class.


The biggest new feature is the ability to have multiple stages. Futile.stage will still exist, but now if you want you can add stages with Futile.AddStage(someStage).

So why would you want to do that? Well basically because I did a ton of work to make the stages special. From now on any transforms you apply to them (x,y,scale,rotation) will actually get applied to the root GameObject instead of transforming the whole tree below them. Normally in Futile, if you move a parent, then all of its children will have to be transformed as well. But now for the stage, nothing will get transformed except for the GameObject(s) that everything is getting drawn into.

In more practical terms, this means that if you scroll the stage, you're going to see just as good performance as if it wasn't moving at all.

I created the concept of multiple stages so that if you want, you can use Futile.stage for your main game content (perhaps a tilemap that scrolls) and then you can create another FStage for all of your UI, or whatever. It's really up to you. Futile has all the same commands that FContainers do, except with stages, so you can AddStage(), AddStageAtIndex(), RemoveStage(), etc.

I also created a few special methods on the stage called CenterOn(), Follow() and Unfollow(). These allow you to treat the stage like a camera that will follow your objects. You can call CenterOn() to center the stage on a point automatically (use LocalToGlobal() to get the position in the correct coordinates.

Follow() allows you to make the camera follow a specific FNode at all times, and it can even follow that node's scale and rotation. Unfollow() stops the camera from following that node. I recommend creating a "cameraTarget" node that you can ease to whatever position you want to create a following camera.

It's also worth noting that you'll need your origin at 0.5f, 0.5f so the camera focuses on the center of the stage... if you still want coordinates starting somewhere else, just put a container at the root of your scene and place it at whatever position you want your origin to be.


Ok that's enough about the stage. The other thing I added is the FRepeatSprite, which is a sprite that can having a tiling texture on it. The element this uses must be a single image (using atlasManager.LoadImage()), not from an atlas. You also need to make sure its texture's Wrap Mode is set to "Repeat". Once you have it set up, you can get tiling backgrounds and you can even set the scrollX and scrollY to make it scroll as much as you want. Pretty handy for certain types of games!


Alright, so that's about it! Enjoy, and let me know if you find any issues or bugs.


Update: Just fixed a bug where the game wouldn't compile if you weren't in the editor. I also made another small change, which is that boundsRect has been renamed to textureRect to make it a bit more clear.


r/futile • • Nov 28 '13

Just so you know - Interstellaria has one week left on its kickstarter. Built 100% in Futile! Thank you MattRix!

Thumbnail
kickstarter.com
10 Upvotes

r/futile • • Jul 25 '13

TMX Tilemaps

10 Upvotes

I just posted this on an old thread but thought people might not see it. So I wanted to share my love for Futile and post it again in case it will help someone.

Hey all! I really wanted to have Futile play nice with TMX without having to create a new XML output like textur packer.

So, I wrote a method that I put in my FContainer subclass that will read the TMX file and create FSprites for each tile. CODE HERE

So now I can create tiles with the following:

FSprite tile = new FSprite(GetElementWithName("tile_" + tileGID));
tile.SetPosition(new Vector2(j * tileWidth + tileWidth/2, -i * tileHeight - tileHeight/2));
this.AddChild(tile);

Here's an example of it in action!

Hope this helps!

EDIT
As promised here is a sample project that makes use of my TMX code. It also includes some other addons I wrote (based off Matt Rix samples) for animated FSprites. And if you check the Editor folder, I wrote a class to make importing TMX files easier. CODE HERE
Enjoy!


r/futile • • Jul 29 '13

FShadowSprite

9 Upvotes

I made a quick FShadowSprite. It's designed to behave exactly like the original FSprite except it shows a shadow. Simple but useful in some situations, mainly when performances are not critical (one other option being to integrate the shadow in the graphic assets for critical sprites).

https://gist.github.com/jpsarda/6105346


r/futile • • Jan 19 '13

I just wrote a beginner's guide to drawing with Futile

Thumbnail
wtrebella.com
9 Upvotes

r/futile • • Aug 27 '12

My made-with-Futile Ludum Dare entry - Microbe Madness!

9 Upvotes

Play it here: http://struct.ca/games/madness

So even though I made Futile, I haven't made a finished game with it aside from the Banana demo project. This was a great way for me to really test it out with something a bit more interesting. In the end it worked out even better than I hoped, I didn't have to tweak anything in the engine at all, and I was able to make a pretty complete game in only 48 hours (well actually under 30 hours of real work time).

I was planning on making it just a web game, but after the time was up, I did a "build for iPad" and it worked perfectly with zero modifications, even running at 60fps on the original iPad, pretty crazy.

The source code is up at http://github.com/MattRix/Madness - it's worth noting that this is jam code, meaning that it's awful... but at least it works, right? :)


r/futile • • Jul 01 '14

Made with Futile: Watercolors - the mind painting puzzle game

8 Upvotes

Hi Reddit! This is the game I developed with my friend, Ancu! It's now available on App Store. You can also check out the promo video.

I chose to develop the game in Unity mostly because of Futile. It is easy to use and /r/futile helped answer most of my questions. So thanks MattRix for building Futile.

Also JPSarda's work helped me. The game has a pretty good horizontal scroll that is a variant of his scolling implementation. And even though I don't use it in the final design, I used FDrawingSprite a lot during prototyping.

Also ManaOrb for this great repository. You can check out the transitions in the game, they use his FSceneManager.


r/futile • • May 01 '14

BewareWolf - my TOJam game, made with Futile

Thumbnail
youtube.com
8 Upvotes

r/futile • • Feb 28 '14

Hey Matt, was Disco Zoo created in Futile?

8 Upvotes

Just curious...


r/futile • • Oct 21 '13

Comparing 2D Toolkit to Futile

8 Upvotes

Hey /r/futile!

At the end of last week, the popular 2D framework 2D Toolkit was half-off in the Unity Asset Store. I seized the opportunity to pick it up, spent the weekend poring over the documentation and creating examples to put it through its paces. What follows are my thoughts:

From a workflow perspective, both Futile and 2D Toolkit are VERY similar. You set-up the camera; create a texture atlas (or two); load sprites, tiled sprites and animated sprites from those atlases; manipulate them through code; yadda-yadda-yadda. The APIs are similar too (they're both pretty "code-centric"), and performance seems comparable (low draw counts and high frame rates were easily achievable even with lots of sprites on-screen).

The biggest difference I found is in the way you work with your imported assets. 2D Toolkit has reinvented the wheel and includes custom editors that run inside Unity itself for manipulating texture atlases, tilemaps and animations. In Futile we rely on external editors to create our assets. For the uninitiated there's TexturePacker for texture atlases, Tiled for tilemaps and Spine for animations (although you can also set-up animations by hand in code). Some might argue that having integrated editors is a plus. On the flip-side, others might argue that the editors Futile uses are industry-standard and used by COUNTLESS other game engines. You might already be using one or more of them. And each of those editors are either completely free or offer free versions.

Where 2D Toolkit starts to pull ahead in my opinion is in the physics engine support. AFAIK if you want physics in Futile, you have to code it yourself using 3rd-party physics engines. In 2D Toolkit, all sprites are just GameObjects under the hood so they naturally have support for colliders and Unity's built-in physics engine. Also, the documentation for 2D Toolkit is better than the (nonexistent) documentation for Futile. Plus, there's a ton of community support behind 2D Toolkit, so the forums are much more active. And then there are those built-in editors. Being able to do EVERYTHING right inside Unity is kind-of nice, even if 2D Toolkit's editors aren't as good as their external counterparts.

But! Futile does have the upper-hand of being free, open source AND extensible. Support for some of Futile's external editors I mentioned above (Tiled and Spine) are developed by the community. So its quite possible to add support for just about any physics engine, external editor or file format; a nice feature Futile will always have over 2D Toolkit.

<soapbox>I just wish more people knew Futile existed, I think it could easily become THE 2D Framework for Unity if it had a proper website, more examples, a developer forum and documentation. I've also never understood why it's not in the Unity asset store, it would get so much more exposure.</soapbox>

My overall impression of 2D Toolkit is that it's quite a capable framework that has great support and a large community. After all, it's one of the most popular 3rd-party Unity assets in the whole Asset Store. If you can catch it on sale it's definitely worth it. But personally, I don't think I would pay full price for it because Futile offers 90% of what 2D Toolkit does, for free. You just have to deal with a smaller community and less documentation ;)

edit: grammar


r/futile • • Jul 30 '13

FBicolorSprite

8 Upvotes

If you like simple classes, here is another FSprite class. It manages 2 colors (bottom and top) instead of one. It's not something that is used very often, but sometimes that can be useful. For example, I will use this to create a dynamic sky (day/night cycle) in the background of a game.

https://gist.github.com/jpsarda/6116940


r/futile • • Mar 06 '13

HOW TO: Exporting to Flash with Futile

8 Upvotes

Recently, I tried exporting a Futile project to Flash. Having never exported to Flash, I was expecting it to be a breeze. It wasn't. When exporting to Flash, Unity converts your scripts to ActionScript, and there are certain things that simply do not work.

I've documented the steps I took to get Futile exporting successfully to Flash so that I could post them here for anyone interested. Perhaps these changes can be merged into the dev branch of Futile, as most of the changes I made in such a way as to not effect other targets (using #if UNITY_FLASH). Issues #1 and #2 are issues that I haven't found a resolution to and have simply commented out/removed for now.

So, here we go.

1 - GoKit Tween

GoKit is included in Futile as a .dll file and was causing several build errors when exporting to Flash. As a temporary solution I removed tweening and the .dll from the project. Perhaps there is another tweening library, or a way to include GoKit, that works with the Flash export. Make sure to comment out references to GoKit in Futile (RXExtensions.cs).

2 - ArrayExtensions in RXExtensions.cs

Another quick fix was to comment out ArrayExtensions in RXExtensions.cs. Flash was having a problem with resolving T during the build process. As this class isn't used anywhere in Futile at the moment, I simply commented it out for now.

3 - FFont.cs

Line 176, 181, and 187 use String.Split in a way that Flash cannot understand. Matt used another way later on in the file that Flash was totally cool with. So I swapped them out. Here's an example:

Line 176

//string[] separators = new string[1];

//separators[0] = "\n"; //osx

//string[] lines = asset.text.Split(separators,StringSplitOptions.RemoveEmptyEntries);

string[] lines = asset.text.Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);

The style that Flash doesn't like is commented out. This should be done two more times. Note in the second line two characters are required.

Line 181

//separators[0] = "\r\n";

//lines = asset.text.Split(separators,StringSplitOptions.RemoveEmptyEntries);

lines = asset.text.Split(new char[] {'\r','\n'}, StringSplitOptions.RemoveEmptyEntries);

Line 187

//separators[0] = "\r";

//lines = asset.text.Split(separators,StringSplitOptions.RemoveEmptyEntries);

ines = asset.text.Split(new char[] {'\r'}, StringSplitOptions.RemoveEmptyEntries);

4 - FFacetRenderLayer.cs

Flash also had problems understanding Array.Resize(). The solution I found was to copy the old verts, create a new Vector of the correct size, and copy the verts back over. This has to be done for ShrinkMaxFacetLimit and ExpandMaxFacetLimit for both QuadRenderLayer and TriangleRenderLayer. Here is an example from QuadRenderLayer's Shrink function (once again, the old code is commented out):

//shrink the arrays

//Array.Resize (ref _vertices,_maxFacetCount*4);

//Array.Resize (ref _uvs,_maxFacetCount*4);

//Array.Resize (ref _colors,_maxFacetCount*4);

//Array.Resize (ref _triangles,_maxFacetCount*6);

Vector3[] oldVerts = new Vector3[_vertices.Length];

_vertices.CopyTo(oldVerts,0);

_vertices = new Vector3[_maxFacetCount*4];

oldVerts.CopyTo(_vertices,0);

Vector2[] oldUvs = new Vector2[_uvs.Length];

_uvs.CopyTo(oldUvs,0);

_uvs = new Vector2[_maxFacetCount*4];

oldUvs.CopyTo(_uvs,0);

Color[] oldColors = new Color[_colors.Length];

_colors.CopyTo(oldColors,0);

_colors = new Color[_maxFacetCount*4];

oldColors.CopyTo(_colors,0);

int[] oldTriangles = new int[_triangles.Length];

_triangles.CopyTo(oldTriangles,0);

_triangles = new int[_maxFacetCount*6];

oldTriangles.CopyTo(_triangles,0);

As you can see, this requires quite a few more lines of code than Array.Resize.

5 - Delegates & Events

This was a big problem as Futile makes use of delegates and events for a lot of different functionality, such as screen resizing, updating, and button events.

Flash doesn't seem to respond well to delegates. Here is an example of how I turned a delegate into something Flash could understand, using the SignalUpdate delegate.

(old code)

Futile.instance.SignalUpdate += HandleUpdate;

(new code)

Futile.instance.AddSignalUpdate(this);

And here's how it works.

The SignalUpdate event exists in Futile.cs. In there, I created a list of FNodes that will register for update messages.

#if UNITY_FLASH

private List<FNode> _nodesToUpdate;

#endif

I created two functions to add and remove a node from the list.

public void AddSignalUpdate(FNode nodeToAdd)

{

_nodesToUpdate.Add(nodeToAdd);

}

public void RemoveSignalUpdate(FNode nodeToRemove)

{

_nodesToUpdate.Remove(nodeToRemove);

}

And created a virtual function in FNode to respond to updates.

virtual public void HandleUpdate()

{

}

Finally, in Futile.cs's Update() function, I had to handle this list of nodes to update.

#if UNITY_FLASH

foreach (FNode node in _nodesToUpdate)

{

    node.HandleUpdate();

}

#else

if(SignalUpdate != null) SignalUpdate();

#endif

As you can see, I tried to maintain the original Futile code for non-Flash targets.

This has to be done for all events and delegates. In Futile, the following need to be handled in this manner:

Futile.cs

public event FutileUpdateDelegate SignalUpdate;

public event FutileUpdateDelegate SignalFixedUpdate;

public event FutileUpdateDelegate SignalLateUpdate;

FScreen.cs

public event ScreenOrientationChangeDelegate SignalOrientationChange;

public event ScreenResizeDelegate SignalResize;

FButton.cs

public event ButtonSignalDelegate SignalPress;

public event ButtonSignalDelegate SignalRelease;

public event ButtonSignalDelegate SignalReleaseOutside;

The other delegates are handled in the same manner. FNodes have virtual functions for each and can register for and respond to each message. It is important to maintain those lists (if you add a node to a list, you need to make sure you remove it).

You also need to make sure you handle these properly in the core Futile files as well. For instance, FButton.cs registers with the SignalUpdate delegate to handle mouse-over events. In its HandleAddedToStage function, I made the following change:

if(_supportsOver)
{
    #if UNITY_FLASH
    Futile.instance.AddSignalUpdate(this);
    #else
    Futile.instance.SignalUpdate += HandleUpdate;
    #endif
}

And did the same with the HandleRemovedFromStage function:

if(_supportsOver)
{
    #if UNITY_FLASH
    Futile.instance.RemoveSignalUpdate(this);
    #else
    Futile.instance.SignalUpdate -= HandleUpdate;
    #endif
}

There are cases like this all throughout Futile that need to be handled.

6 - MiniJSON Parsing

Finally, at this point, Futile should be building to a swf file. Unfortunately, it crashes at runtime. Using the Flash debugger, I was able to pinpoint the location to the MiniJSON parser included in Futile (when parsing our Atlas output). It makes use of the StringReader System.IO class, which Flash doesn't get along with.

Searching around, I was able to find a similar version that was designed specifically for Flash. I simply added it as a separate .cs file in the project (MiniJSONFlash - note, if you use both this and the MiniJSON parser included with Futile, you'll have to change all references to MiniJSON in the new file as they conflict with the existing file).

https://gist.github.com/GarethJones/1601919

Only one modification needs to be made to the above file. Lines 212-217 need to be uncommented, as TexturePacker uses true and false for rotated and trimmed flags. Note the new name for the class that I used so that it doesn't conflict with MiniJSON.cs.

		case MiniJSONFlash.TOKEN_TRUE:
			NextToken(json, ref index);
			return Boolean.Parse("TRUE");
		case MiniJSONFlash.TOKEN_FALSE:
			NextToken(json, ref index);
			return Boolean.Parse("FALSE");

Finally, with this new parser in place, we need to make use of the new datatypes. This parser uses System.Collections Hashtable and ArrayList, so we need to convert them in MiniJsonExtensions.cs and FAtlas.cs. The former:

public static string toJson( this Dictionary<string,object> obj )
{
	#if UNITY_FLASH
	Hashtable table = new Hashtable();
	foreach (var key in obj.Keys)
	{
		table.Add(key, obj[key]);
	}
	return MiniJSONFlash.JsonEncode(table);
	#else
	return Json.Serialize( obj );
	#endif
}
	
public static List<object> listFromJson( this string json )
{
	#if UNITY_FLASH
	ArrayList oldList = (ArrayList)MiniJSONFlash.JsonDecode(json);
	List<object> list = new List<object>();
	foreach (object item in oldList)
	{
		list.Add(oldList);
	}
	return list;
	#else
	return (List<object>) Json.Deserialize( json );
	#endif
}

public static Dictionary<string,object> dictionaryFromJson( this string json )
{
	#if UNITY_FLASH
	Hashtable table = (Hashtable)MiniJSONFlash.JsonDecode(json);
	Dictionary<string,object> dictionary = new Dictionary<string, object>();
	foreach (var key in table.Keys)
	{
		dictionary.Add((string)key, table[key]);
	}
	return dictionary;
	#else
	return (Dictionary<string,object>) Json.Deserialize( json );
	#endif
}

As you can see we simply build the object that Futile or the parser is expecting from what we get.

The last change you will (should) need to make is in FAtlas. Futile is expecting a Dictionary inside of a Dictionary, but what we get from the parser is a Hashtable inside of a Hashtable. We've changed the outer Hashtable to a Dictionary, but the second one still remains. Here's what the new FAtlas looks like:

if UNITY_FLASH

	Hashtable hashFrames = (Hashtable)dict["frames"];
	Dictionary<string,object> frames = new Dictionary<string, object>();
	foreach (var key in hashFrames.Keys)
	{
		frames.Add((string)key, hashFrames[key]);
	}

else

	// This is the old line of code.
	Dictionary<string,object> frames = (Dictionary<string,object>) dict["frames"];

endif

And there you have it. With the above changes, Futile should export and run in Flash. If you have any questions, or if anything is unclear, post below and I'll do my best to answer them!


r/futile • • Jan 29 '16

Made With Futile - Sumeiro

7 Upvotes

Hey Futilers!

My wife and I have just released our first game on the App Store. It's a number maze - so if you enjoy numbers and puzzles then hopefully you'll like it. It's been a loooong road and a huge learning experience.

Check it out: digivaux.com/sumeiro


r/futile • • Dec 09 '14

Futile Future

7 Upvotes

Hi Matt,

Many thanks for creating Futile, just getting into it, fantastic framework and looks like exactly what get on with!

I wanted to ask about the future of Futile and what plans you might have with it? Am I best taking the 'unstable' branch on GitHub for production usage as the other branches don't look like they have been touched for a while? Do you plan on getting things up to a v1.0 release? If so what goodies might be coming with that ? :)

Look forward to you're response when you have a moment and many thanks again.

Pete


r/futile • • May 16 '14

Made with Futile - Fruit Folly

7 Upvotes

Hey gang, I just completed my indiecade submission and put a video up to go along with it. I used Futile for everything, and followed the same basic layout from Matt's TOJ project for the physics. For level layouts I used SVG to create XML files and then converted them with PERL to the format I needed.

https://www.youtube.com/watch?v=KO2ZdIEMKbc

Hoping to have it out sometime this summer on iOS. (we're on twitter if you care to keep up with us @fruitfolly)

Hope you like it! -Ryan