How to set objects on a androidH runner game

安稳与你 提交于 2020-01-06 19:29:56

问题


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://www.filedropper.com/test_37

The obstacles and coins are on random. But the obstacles and coins are overlapping each other.. Which is very bad for a runner game because it looks very bad and the gameplay gets very very complicated.

How can i fix it??. Is there any way to fix it?.

And i am also thinking if I can set the obstacles and coins to a specific area (not on random). So the game will be more oganized and the gameplay won't be complicated. Which i still don't know -_-.

But i still prefer it on random. So guys please help me fix it..


回答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



来源:https://stackoverflow.com/questions/15081730/how-to-set-objects-on-a-androidh-runner-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!