Updating a 2.5D game to graphics 2

I’m gonna sorta keep an update here today while I attempt to update my game as quickly as possible.
I have a demo ready and waiting to go for updating.

http://www.youtube.com/watch?v=8q5l_DzVWak

Note this is pre graphics 2, IE what I’m starting with).

Not sure why, just think it might be interesting to see the pitfalls that I encounter and to see how quickly I can do it.

I should elaborate on what I need to achieve first:

  1. Make sure it actually works! No idea what may have broken. Luckily this isn’t a complete project, just the core game engine test, so hopefully very few non-game related bugs will appear.

  2. Ideally it will look the same (ok, better) as it does now, but using quads instead of my current method of splitting each track section into a ton of slivers that I set the width on.

That’s it really!

So, from here on in, will be actual updates as I get to grips with it.

Oh that’s nice, it embedded the vid!

Corona is installed happily alongside my other versions, and I head over to the alpha docs. I was not impressed :wink:

So will have to download the fishies demo to see how to actually distort these wee images.

At least my original code actually runs in the new corona. Granted it looks like rubbish and there is distortion all over the shop, but it runs! I am guessing the distortion comes from removing the registration points, so my first task will be to factor this in and get it looking and running how it did before.

Immediately got caught out by the simulator only running properly on the first monitor - heart attack avoided!

Button locations fixed (x, y being middle now instead of left and top - not sure how I feel about this change yet. Well, I always hated top and left as the parameter names, but making them be in the center… guess I’ll get used to it).
Realised that if I don’t accelerate, I can move left and right without graphics going wrong. So yeah, the changing of image properties is what is making them go hay-wire.
Also - background colour was yellow not green. Fix = divide the RGB components by 255 to put them into 0-1 range. Easy!

Hmmm sprites are going a bit wrong. I am wondering if setting their width and height is not working properly…

OK given up on that since I believe I’ve encountered abug - so, direct to the quad things then, must look at the demo now!

Stab in the dark - the object path value - here we go. In fact to check I have the rotation correct, I’m simply going to replace my width and height settings (which seem to go wrong) with the path stuff, should help me understand the ordering and rotation (fingers crossed top left and clockwise, as that’s what I’ll set up for first).

Ok I have the ground sorta working (road and scenery is disabled for now). Values are a bit weird though - am thinking this is because of the offset stuff again, treating 0, 0 as the center…

A few tweaks and I have my bars scrolling along properly, hurrah! Encouring, now for the road sections…

Bit confused though - I can specify the Y values of the path in absolute screen coords, but the X ones not, they are relative. Hope this is just me doing something wrong:

[lua]                        – Long hand!

                        sprite.path.x1 = 0

                        sprite.path.x2 = screenWidth

                        sprite.path.x3 = 0

                        sprite.path.x4 = -screenWidth

                        

                        sprite.path.y1 = oldScreenY

                        sprite.path.y2 = oldScreenY

                        sprite.path.y3 = screenY

                        sprite.path.y4 = screenY[/lua]

I am beginning to suspect that a sprite’s X and Y values are recalculated after setting the path, to maintain it in the center. Time to track down that offset help methinks, hopefully there is a way to disable it because the simplest means of controlling the shape is to dump the sprite at X,Y = 0,0 and then just set the path corners in screen coordinates.

Looks like I got my ordering wrong. Seems like x1, y1 is top left but it goes counter-clockwise. Probably my memory at fault here, I did think OGL ordering was clockwise but clearly not!

Oh dear me I think I have twigged it. The path values are offsets from the normal size of the image used.

My terrain lines are images as wide as the screen, but 1 pixel high. I couldn’t work out why if I set all the X values to 0, it was filling the screen still. OK… they are relative. I am err… not sure why they’ve done that but I can work with it now I know.

NOW onto the track sections.

I should point out that if I place two distorted rectangles touching along an edge (IE sharing 2 corners) - no matter what I do to distort the pair together, the joined edge never shows gaps - this is awesome (thanks OGL!) and prevents sparklies, something I had to factor in before with my other hacked method.

Track sections in as rectangles, about to make them quads and viola, lovely track!

Making the path relative to the size of the image though is really striking me as odd.

The path is essentially a list of offsets, rather than definitive coordinates.

This means every time I want to draw an image and distort it, I need to know the width and height of the source image, which is rather frustrating:

[lua]                            sprite.path.x1 = left

                            sprite.path.x2 = left

                            sprite.path.x3 = right - size.width

                            sprite.path.x4 = right - size.width

                            sprite.path.y1 = oldScreenY

                            sprite.path.y2 = screenY - size.height

                            sprite.path.y3 = screenY - size.height

                            sprite.path.y4 = oldScreenY[/lua]

And we can haz road! Looking extremely nice and fluid!

I have noticed a bug with the sprites - if I turn on the road tilting (for when you go around corners) the track disappears - I imagine this is down to some sort of culling issue with rotated quads. Not a killer for now though, I just disable it.

An addition to the previous message - they only vanish if the images are rotated more than a slight amount clockwise - anticlockwise they don’t vanish.

Scenery is in but goes rather majorly wrong when you start to move down the road. I am wondering them going off screen affects things, or if having the sprite drawn above left of its registra… sorry - anchor, causes problems.

Will try offsetting by a couple of 1000 pixels now to see if that helps at all.

Nothing gets drawn when I try offsetting, so now I’m going to try moving the sprite’s X and Y to the top left and make everything relative to that - just in case it helps.