Gaming Your Way

May contain nuts.

Flash is for video, apparently

Today was the start of the big UI push, which I've been putting off. One thing I really wanted in the game was video clips to show the different power-ups so the player could select which one they preferred and could see it in action.

As we're using a combination of Away3D and Starling, I can't use stageVideo. Because it's always displayed beneath everything means trying to cut a mask out would just be a nightmare and not even worth thinking about.

My first thought was to use a sprite sheet, just load it in on demand and update a sprites texture every frame to make a cheap and cheerful video clip.

I made my grab ( Using Screenflow, OSX only I'm afraid, but the best there is ), imported it into Flash and spat out the png frames. Nope, even with it just being 256x256 it blew the 2048x2048 texture size and it was only a short clip.

Ok, let's try FLV using the native display list. It's probably going to run like a pig but best to test these things. Unbelievably it performs well, the clip is really high quality albeit small, but it worked much better than I thought.

Cool, problem solved. Let's just get it looping and... hang on, what now ? Looping it ( Check for it to be finished via an event and then tell it to seek(0) ) makes it glitch really badly, there's a delay, sometimes a fraction of a second, sometimes a whole second. It's a 68k clip loading from a SSD, and it's not streaming quickly enough at the start. For fucks sake.

The solution I came up with was to make a feature of it ( As I'm not going to be able to fix it ).

I grabbed the last frame and used the excellent ImageGlitcher to make it look distorted on purpose. Not ideal I know, and I'm going to have to screw around doing this for every different clip and manage all that, but the best I can come up with.

I should really comment about what a fiddly pain using Flash's own perspective is and trying to align that with an image in Away3D ( Or just trying to get a grab that's loopable ), but I've been moany enough for one post.

Squize.

Luke, use the force...

The past couple of days haven't been the most productive. Some of my linked list related speed ups came back to haunt me, so lots of time spent looking at Scout and swearing.

Next week I'm going to have to crack and work on the UI, which I'm not really looking forward to as it means both design and boring coding, so today has just been simple things, code speed ups to try and replace the ones I lost due to the above mentioned weirdness and I added the force field in.

Performance wise I'm happy with the game overall, it's not always able to stick to 60fps but that's on an iPad3 so not the end of the world, and there are still some ways to try and eek out some more performance ( It's never really bad to the point of affecting the game play ).
It's going well overall, I'm just spent this week, it's been a long one with lots of bits here and there to deal with ( Fixes to the html5 game, pitches to quote for, Skype chats to have etc. ). 

Squize.

That's a bit more like bullet hell

Just a quick update today, in fact I think this grab will pretty much cover off what was added today

The bullets graze the player ship ( See those grey ones ), but don't actually hurt it yet ( The collision checks are in, they just don't call anything ), so tomorrow we'll get the player ship getting destroyed and we're that bit closer to it being a real game.

Squize.

Let's have some UI in there

The past couple of days I've been working on some of the UI aspects of the game, the level complete sequence in this case.

I thought adding a star rating would be a nice touch, adds a bit of replay ability and enables me to add a simple achievement or two. Little did I know what a complete ball ache it was going to be.

I wanted to use Away3D to display it as I wanted perspective on the panel. In the main game the camera is constantly rotating around, so I thought I'd just figure out where the camera is looking and position the panel relative to that, updating it's position every frame so it appeared static.
Simple in theory, but totally beyond me. I just couldn't figure a way out to work out where the camera was looking ( There's camera.projec()t, which I guess is the way, here's the docs for that ). After dicking around for hours, I cracked and binned that approach, the maths is beyond me.

So let's just add another view and another camera and treat it as a separate entity from the main background. Sweet, all done. Now let's add some love to our texture, a specular map and some nice lighting. Sweet, that looks awesome, I'm really pleased with it, and I dropped some lens flares and moisture effects on top using Starling, looks great. I guess I should test it on the iPad now...

...ah, it runs at less than 30fps. Bollocks.

I've just spent the last hour or so removing all the sexy love I'd added in there, it still looks pretty good ( The grab above is from the cut right back down version ) but it was painful to do.
In my other recent iPad project I found that scaling images seems to cause a real hit on the first time, I don't know why, mipmaps being created on the fly ? Which means that you have to display your meshes scaled up but hide the textures with alpha=0, wait one frame, hide the meshes and restore the textures, that makes it skip that initial performance spike.

All in all a lot more painful than it should have been, but it does look good in motion, those stars fly into it and have a little impact shudder and as you can see a shower of particles. When I get some sound in there the impact should feel nice and weighty.

And that's what my last two days have been.

Squize. 

Messing up scale - big time

I've been doing 16h coding shifts for the last couple of days (shipping deadline ahead) so I couldn't face touching the prototype game afterwards, which means no update on that this post.

Anyway, after Christmas I decided to rebuild the CSH22 MOC I've done some time ago (the original post is here). One thing I noticed while building the model with "real" Lego parts that the base and the roof (which looked OK as digital model) are not very stable or buildable, the obvious conclusion was to redo them before building the model.


The old base, without roof.

That said, it took the better part of 5 evenings to redesign the base and the roof, keeping an eye on stability and making it buildable. To say I went a bit over the edge with it, barely covers the amount of new parts - roughly 760 to be precise - adding up to 1254 parts for the whole model.


The new base, again without roof. The pool is all new, too.

Yesterday the last bag of parts finally arrived (Lego Pick-A-Brick is your friend here) and so while having my morning coffee I started to build the base plate and was - mildly - surprised how fucking big it is. For some odd reason I always have that with Lego models, wondering how I could have underestimated the size by that much.


That's a) a bad picture and b) 32.5cm x 31.0cm of base-plate goodness.

Oh. Well.

To end this post with something to look forward to, next post will be about messing up a game's items with exposing values to the Unity editor and how something I call the "ItemFactory" saved the whole enterprise.

... and now: there's a deadline ahead, ahoy.

-- Oliver / nGFX

Starling optimising

I was on client work so no progress yesterday. Today I thought I'd have another look at what I could do with Starling to try and save some cycles here and there.

We use sprite pooling like everyone else in the world. Rather than add/removeChild them, I just set visible=false as it should be quicker.

Because we have a ton of possible objects, even if they're not visible, I had a look at DisplayObjectContainer.render(). This loops through all the display objects running a check first to see if they're worth plotting ( i.e if visible=true, alpha>0, scaleX/Y>0 etc. ) and if so calls their render method to actually display them.


Now if we've got 500 particles running, but not displayed, it felt a little redundant still looping through them all just to not plot them, so I altered the visible method to spit the display object into one of two different Vectors, visibleChildren and hiddenChildren. If you change the visibility it's moved from one Vector to the other, which is a little costly and I want to look at that again. But, it means for our render loop we're now only looping through objects we know are visible, so it's a shorter loop and we've removed that extra visibility check which would happen for every object.

Other savings included lots of little things, for example there's a check to see if when you alter a x position has it actually changed. 99 times out of a 100 it will have, so there's no need for a check there every time.
Also because I use alpha a lot for the particles / explosions I had a look what could be saved there too, mainly "inlining" methods ( Not the compiler inline option, as that seems to break the Starling code ), VertexData.setAlpha was a really costly call before I cut it right back.

Just to make it clear, this isn't a criticism of Starling, it's a great piece of code which has to be all things to all people, and anyone can always look at someone else's code and speed it up, there's nothing clever about that.
In a perfect world I'd make my own Stage3D engine from the ground up, but I really don't know how many more Flash projects I'm going to do so I think it would be wasted time and just be a vanity thing.

Squize. 

They explode and everything! Oh and linked lists in AS3

Did some work on the game Saturday and Sunday, which wasn't the plan as I had the html5 game to amend, but I got in the zone and really enjoyed it.

I altered the equaliser effect to the colour you see there, and after taking this grab I added another fainter layer on top to fake some HDR light bleeding.

The main push then was finally adding the explosions / particles / points. This was my big worry with the whole 60fps thing, and I managed to get there with some sly tinkering.

My first attempt was to split the particles up into two arrays ( Well Vectors, but that's such a confusing term when talking about Flash ), and run each particle in the two different arrays every other frame, so even though the game is 60fps, the particles actually only run at 30fps. This kind of load balancing really helps.
I'll be honest, I did notice the difference at first, but only because I was really looking for it, in real life they don't look like I'm cheating.

I'm not running a silly amount for each explosion, only around 60 particles, which doesn't sound much but when you've got 3 or 4 explosions at once they really help fill the screen.

After that I cracked and changed the code over to using linked lists to handle the explosions and particles. Normally I have code like this for my mainloop

var cnt:int=0;
var explosion:Explosion;
	
for each (explosion in activeExplosions){
	if(explosion.mainloop()=="dead"){
		activeExplosions.splice(cnt,1);
		explosionsPool.unshift(explosion);
	}
	cnt++;
}

Where we just loop through all the active explosions, any dead ones are removed and pushed back into their pool.

With a linked list ( I think technically I used a "Double linked list" but really who cares about the proper terms ) you store the first and the last object, your Head and Tail, and then each object has a reference to it's next and previous neighbours.

If the Head isn't null you call it's main loop and when it's finished it looks to see if it has a next neighbour, if so it calls it's main loop and so on. It removes the overhead of running a loop and changing the size of the array by inserting and removing from it. It has a slight cost when you want to remove it as it has to tell it's next and previous neighbours it's not longer there and update their next and previous pointers, but it's a handful of conditional statements.

I'm away from the game for another day or two now, but when I get back to it I'll be looking to change the player bullets to a linked list, I'm not sure if that will be possible as the baddies all expect to know about the player bullets so passing them an array is a nice easy way to do that, then I'll add the baddie shooting routines.

Squize.

Work stopped play

A bit of client work has come up this week, so I've not managed to touch DN8 today.

One thing I did mange to do yesterday though was to give the particles some colour, I'm really pleased with them.

They're a lot more colourful than in the original game, they have a nice 8Bit colour wash feel to them. Rather than going the tint route of the original, which is expensive, I just created a 260 frame tween in the Flash IDE and got it to spit all the frames out as pngs, dropped them into Texture Packer and the game just picks the next one in an array every time we need to plot one.

I think unfortunately that's where I'm going to have to leave the game for a couple of days, there's too many other moving parts work wise right now to be able to try and claw some free time back to work on it, which is kind of annoying as next up would be some explosions and all the particles which go with them. Oh well.

Squize.

Thursday I don't care about you...

Quick update today, as it's Friday and I'm sure we've all got places to be.

The first level baddies are in now, and the particles which show their path.

You can shot them to earn points, but no explosions yet ( That's the next big thing ). I noticed the frame rate drops slightly when the path is onscreen, so I'm going to have to look at that as well ( It's not too bad right now, but when we have a silly number of bullets running every little saving helps ).

Basically I'm trying to get all the costly in terms of CPU / GPU stuff in as quickly as possible and then optimise that so we keep as close to the magic 60fps as possible. I'm lucky in a way that I've got an iPad3 to test on, it's the slowest device out there ( iPad 1 doesn't count, that's really not worth targeting ).

Hopefully Mondays update should have more in the way of particles, as they always look good.

Squize.

We have the pow pow pow

Only the 2nd day of trying to update the progress on DN8 iOS and I'm struggling already ( I had fuck all sleep last night and then an early morning, I'm dead on my feet. I always know when I'm working early as everyone I chat to on IM says "Who's that ?" or "Shit the bed ?" or a combination ).

So, basic title screen in place with a play button and rollOver, the majority of the HUD done ( Working scores and everything ) and a player sprite which you can move around and it has the tilt animation in there.

And guess what ? Bullets too.

I don't think I've actually used any of the original code in this yet, which was the plan, but with looking at the baddies I think some copy and pasting is going to happen there as I really can't remember what I did.

Before I go, I got caught out with a couple of Starling things. Adding a blend mode to an image forces a draw call, as does using alpha. I know there's that whole starlingStage.alpha=0.999; work around, but it feels like that will be costly to do it on every child clip, so I've got a few specific container sprites that I add the blend mode to and use that alpha trick, so I've just got to remember not to use alpha in anything outside of those.

That's probably gibberish isn't it, so time to stop.

Squize.