Skip to content Skip to sidebar Skip to footer

How To Set Objects On A Androidh Runner Game

I am trying to develop a android runner game for school purpose.. I am still new to this and please I need your assistance.. You guys can view my CS5flash file at >>> http

Solution 1:

You will need to change the way you are adding the coins and obstacles! I suggest using a timer for each. Atm you are adding a ton of them on every frame, calculating overlaps would use too much resources! and put them in an array or better a vector! i would reccomend using an object Pool aswell!

so limit the amout of coins and hurdles that can be present, like 5 or so. then remove them from the array/vector when they are offscreen or collected! then when you add new stuff you can check against the array/vector what the allowed values are!

when you got your Array you can pass it to the randomRange() function and exlcude those values! would look somthing like this! not testet!!

function randomRange (min:Number, max:Number, exclude:Array = null):int
{
    var val:int = (min + Math.random() * (max - min)) >> 0;
    if (exclude)
    {
        for (var i:int = 0; i < exclude; i++)
        {
            while ((val < exclude[i].x + exclude[i].width) && (val > exclude[i].x))
            {
                val = (min + Math.random() * (max - min)) >> 0;
            }
        }
    }
    return val;
}

Its still quite exspensive performance wise. but with only a few object you should be fine

Post a Comment for "How To Set Objects On A Androidh Runner Game"