Be a Supporter!

2D Isometric Race Game rendering pb

  • 365 Views
  • 7 Replies
New Topic Respond to this Topic
GdabZ
GdabZ
  • Member since: Jan. 5, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
2D Isometric Race Game rendering pb Feb. 1st, 2013 @ 01:53 PM Reply

Hello fellow developers,

I'm currently coding a 2D game. You can find a preview version here, very early state :
http://pixelshaped.com/help/35fps.html
http://pixelshaped.com/help/60fps.html

The problem I'm facing is : framerate, although fixed at 35 or 60 fps and not moving from there, appears very inconsistent to the eye.

I've tried blitting but my sprites are a little bit too big for it to be efficient (but I was rotating them on the fly with a Matrix, I still havent tried to rotate them first, store them and use them rotated, maybe this is the solution).

On the version you can see, there are only Sprites. I have no memory problem since I use a pool class to instantiate all the Sprites I need when the scene is loading. I tried cacheAsBitmap statement with no improvement (it was even worse because of the pixelsnapping)

The only solution left is Stage 3D, with Starling, but I can't use it because I need to export to Flash 9/10 max, due to the weaker market share of Flash 11.3+...

Am I fuc*ed ?

How would you do that ?

P.S. :
Game class : http://pastebin.com/mH1xscqw
Pool class : http://pastebin.com/B7CG6Ukp

Thanks a lot !

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to 2D Isometric Race Game rendering pb Feb. 1st, 2013 @ 02:15 PM Reply

35 fps is a weird number...try 30. 60fps works fine for me, just a skip every now and then, but that's just Flash.

Most people are up to fp11+ by now, mainly since browsers auto-update/notify. No reason to make your game perform worse to hit that 3-7% of people who have never updated anything on their computers.

Can't remember if it was 93 or 97% fp11+ browser penetration

You don't have to cast array elements to use them, and a vector might perform better; it'll at least make debugging easier since it can only hold one type of thing.

GdabZ
GdabZ
  • Member since: Jan. 5, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to 2D Isometric Race Game rendering pb Feb. 1st, 2013 @ 08:01 PM Reply

At 2/1/13 02:15 PM, MSGhero wrote: 35 fps is a weird number...try 30. 60fps works fine for me, just a skip every now and then, but that's just Flash.

Most people are up to fp11+ by now, mainly since browsers auto-update/notify. No reason to make your game perform worse to hit that 3-7% of people who have never updated anything on their computers.
Can't remember if it was 93 or 97% fp11+ browser penetration
You don't have to cast array elements to use them, and a vector might perform better; it'll at least make debugging easier since it can only hold one type of thing.

Thanks for your input. I'm aware of the Vector type, wich I use when my arrays are too big or when optimizing. But here I just have three small Arrays which have no incidence on the rendering at all.

Do you have market share studies on flash player version ? Adobe's ones seem far too optimistic. And as my clients are still using IE8, I'm far from relying on auto update...

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to 2D Isometric Race Game rendering pb Feb. 1st, 2013 @ 08:58 PM Reply

At 2/1/13 08:01 PM, GdabZ wrote: Do you have market share studies on flash player version ? Adobe's ones seem far too optimistic. And as my clients are still using IE8, I'm far from relying on auto update...

Ha, I guess if you know your specific market, it might be wise to cater to them. I don't remember where I saw it, maybe something on bytearray or something from a presentation I found online, but I remember it said 93-97% have 11+

64base
64base
  • Member since: Apr. 18, 2012
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to 2D Isometric Race Game rendering pb Feb. 2nd, 2013 @ 03:30 AM Reply

This needs optimising:

public function dismiss(_sprite:Sprite):void {
                       
                        var tempInt:int = poolArray.indexOf(_sprite);
                        if (tempInt > -1) {
                               
                                // HERE--> poolArray.push(poolArray.splice(tempInt, 1)[0]);
                                numberInUse--;
                        }
                       
                        //trace(name + " (dismiss) : Sprites in use " + String(numberInUse) + "/" + String(poolArray.length));
                }

In conjunction to this:

for (i = tempInt-1; i >= 0; i--) {
                               
                                tempSprite = nuagesArray[i] as Sprite;
                                if (tempSprite.x > 1150) {
                                       
                                        //HERE -->nuageLayer.removeChild(tempSprite);
                                        //HERE -->nuagesArray.splice(i, 1);
                                        nuagesPool.dismiss(tempSprite);
                                }
                               
                                tempSprite.x = tempSprite.x + 2*speed;
                        }

and this:

tempInt = treeArray.length;
                       
                        for (i = tempInt-1; i >= 0; i--) {
                               
                                tempArray = treeArray[i];
                                tempSprite = tempArray[0] as Sprite;
                                if (tempSprite.x > 1150) {
                                       
                                        // HERE--> tempArray[2].removeChild(tempSprite);
                                        //HERE--> treeArray.splice(i, 1);
                                        if (tempArray[1]) {
                                               smallTreePool.dismiss(tempSprite);
                                        }else{
                                                bigTreePool.dismiss(tempSprite);
                                        }
                                }
                               
                                tempSprite.x = tempSprite.x + speed;
                        }

Use splice sparingly and I suggest you recycle objects rather than add and then remove them every frame (if that is what is happening)


.

GdabZ
GdabZ
  • Member since: Jan. 5, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to 2D Isometric Race Game rendering pb Feb. 2nd, 2013 @ 06:22 AM Reply

At 2/2/13 03:30 AM, 64base wrote: This needs optimising:

public function dismiss(_sprite:Sprite):void {

var tempInt:int = poolArray.indexOf(_sprite);
if (tempInt > -1) {

// HERE--> poolArray.push(poolArray.splice(tempInt, 1)[0]);
numberInUse--;
}

//trace(name + " (dismiss) : Sprites in use " + String(numberInUse) + "/" + String(poolArray.length));
}

In conjunction to this:

for (i = tempInt-1; i >= 0; i--) {

tempSprite = nuagesArray[i] as Sprite;
if (tempSprite.x > 1150) {

//HERE -->nuageLayer.removeChild(tempSprite);
//HERE -->nuagesArray.splice(i, 1);
nuagesPool.dismiss(tempSprite);
}

tempSprite.x = tempSprite.x + 2*speed;
}

and this:

tempInt = treeArray.length;

for (i = tempInt-1; i >= 0; i--) {

tempArray = treeArray[i];
tempSprite = tempArray[0] as Sprite;
if (tempSprite.x > 1150) {

// HERE--> tempArray[2].removeChild(tempSprite);
//HERE--> treeArray.splice(i, 1);
if (tempArray[1]) {
smallTreePool.dismiss(tempSprite);
}else{
bigTreePool.dismiss(tempSprite);
}
}

tempSprite.x = tempSprite.x + speed;
}

Use splice sparingly and I suggest you recycle objects rather than add and then remove them every frame (if that is what is happening)

Thank you ! How would you use splice less ? The only other option is to use linked elements instead of Arrays or Vectors, no ?

And for now, I removeChild my Sprites only when they disappear from the animation. They wait in the pool to be addChilded again. Is this what you call recycle ? I've always heard keeping them addChilded offscreen wasa bad practice... ?

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to 2D Isometric Race Game rendering pb Feb. 2nd, 2013 @ 09:14 AM Reply

Dont use addChild, instead change visible to false


RangeError: Error #1125: The index 4 is out of range 4.

GdabZ
GdabZ
  • Member since: Jan. 5, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to 2D Isometric Race Game rendering pb Feb. 2nd, 2013 @ 04:01 PM Reply

Hi guys,

Finally had some time today to tweak the animation :
http://pixelshaped.com/help/test.html

What I did not change :
_ still using vector graphics instead of bitmaps
_ nothing is cachedAsBitmap

What I did :
_ gotten rid of Array and Vector type everywhere there is iteration and need to use the splice method. I've used a LinkedList Class instead (credit goes to Alkemi), where basically every node has a next/prev property and you can iterate through objects fetching the next property of the previous object. Deletion is much faster. Ask if needed.
_ fixed the framerate at 60fps

Whay I got :
_ small memory print, no growth
_ 60fps theoretical framerate. My tests in different player versions show :
___ That it runs like crap (to the eye, the stat graph is perfect) in the debug standalone player
___ That it runs fine in Chrome
___ That it runs fine in IE, except when the mouse is moved (this will not be my input, but still, any ideas on how to solve that ?)
___ That it runs with many hiccups in Firefox (once again, to the eye only)

My next move :
_ trying blitting, with copyPixels()
___ my clips will have to be scaled and rotated before being put in squared bitmapdatas, so that I don't have to do that on the fly in every frame.
___ As everything will already be rotated, I will have to make everything go 30° (for now I only use the x axis, and my main clip, containing everything else, is rotated 30°, which makes it easier for me to understand...)

Is my next move worth the try ? What would you do to improve rendering in Firefox and IE (mouse pb) ? DO you notice other problems on your computers and if so, what's your hardware/software combination ?

Thanks again !