chris1986m Posted March 23, 2015 Share Posted March 23, 2015 Hi to all,i've tried and tested a lot the last days, but now I don't have any ideas... and may be someone can help me.I build a game with moving elements from right to left, like jetpack joyride. The "rate" value is my game level (it's the game difficulty). By changing this value, the game will be faster/slower. This means the velocity of each moving element depends on the "rate". Also the frequency on which seconds the next element will spawn.I've adjusted the space between two elements by view (not by px). Tested for "rate 0" and "rate 100". I've found a good frequency by 15000ms and 2500ms.My goal is, to get always the same space between two spawning elements whatever rate and speed is set.-----------------------rate = 25sMin = 50sMax = 300fMin = 15000fMax = 2500speed = Math.max(sMin - (sMin - sMax) * rate / 100, sMin);frequency = Math.max(fMin - (fMin - fMax) * rate / 100, fMax);nextSpawn = this.game.time.now + frequency;------------------------Rate: 25speed: 112.5frequency: 11875------------------------The results are correct, but this is not that what I needed.With the increasing speed by rate, I've to adjust the frequency by speed.This means:rate: 0speed: 50frequency: 15000CORRECT!rate: 100speed: 300frequency: 2500CORRECT!rate: 25speed: 112.5frequency: 11875TO SLOW! The frequency should be round about 7000 for the same space between the two elements.I've tried to adjust the fMin and fMax values before frequency calculation and the frequency value after the calculation.Both via percentage calculation, based on the "rate" or other values... It is not possible to get correct results between "rate 0" and "rate 100".Spawning is always to fast or to slow.11875 * 25 / 100 = 2968.7511875 - 2968.75 = 8906.25TO SLOW! The space between the two elements is greater than the default space. 7000 would be a good value....I think i've to adjust the frequency by the game speed. But I don't know how!On creating each element, the sprite gets the speed value for the velocity.x.But how can I handle "speed 112.5" to increase/decrease the spawn frequency in the correct proportion.I hope this is clear, because it is not very easy to explain this problem.Please look at the attached image. Thanks for help.Chris Link to comment Share on other sites More sharing options...
chris1986m Posted March 24, 2015 Author Share Posted March 24, 2015 Hi,is there someone who can help me or is it to bad explained?Regards Link to comment Share on other sites More sharing options...
Huggz Posted March 26, 2015 Share Posted March 26, 2015 If you don't want spawn frequency to change with game speed, why change it? Just spawn a new item every n milliseconds and just use speed to determine how quickly things are moving. Or am I missing the point? Link to comment Share on other sites More sharing options...
stauzs Posted March 26, 2015 Share Posted March 26, 2015 hi, distance is relative to the time and velocity.distance = time * velocity;// if you want to keep equal distance between objectsnext_spawn_at = this.game.time.now + distance / velocity;// You will need to change your code to fit that formula// something like:// distance = base_dist_px / frequency; higher frequency - smaller distance// velocity = base_velocity + rate * X; next_spawn_at = this.game.time.now + (base_dist_px / frequency) / (base_velocity + rate * X); Link to comment Share on other sites More sharing options...
chris1986m Posted March 26, 2015 Author Share Posted March 26, 2015 Hey,thanks for the hints.I've to Check if i can only change the Speed, or have to implement this Special calculation.RegardsChris Link to comment Share on other sites More sharing options...
chris1986m Posted March 26, 2015 Author Share Posted March 26, 2015 Hi stauzs, i have some problems with your calculation. What do you mean with time? Frequency, game.time.now?distance = time * velocity; base_velocity is the default start velocity?The velocity in game is from 50 to 300, based on the spawning time (15000 to 2500). What do you mean with X? base_dist_px = 300frequency = 15000base_velocity = 50rate = 0X = ? next_spawn_at = this.game.time.now + (base_dist_px / frequency) / (base_velocity + rate * X); Thanks for your help!!!Chris Link to comment Share on other sites More sharing options...
stauzs Posted March 27, 2015 Share Posted March 27, 2015 with time I meant interval between 2 events - in your case time between 1st spawn and 2nd spawn it's same as 1/frequencyit's from speed formula actually: v = d / t this was just an example - how you could make changes to your code.base_velocity is the default start velocity? - YesWhat do you mean with X?X is just a coefficient - to increase rate per object - you can remove it ( basically same as x = 1 ) - or call it something like base_koeeficient_per_rate Link to comment Share on other sites More sharing options...
chris1986m Posted April 28, 2015 Author Share Posted April 28, 2015 Hi,after a Long Break of Development, i've fixed the Problem.Thanks stauzs for the Tipp.V = d / td = minFrequency * minSpeedV = (15000 * 50) / speedThis give me a correct calculation for the frequency (V)Regards,Chris Link to comment Share on other sites More sharing options...
Recommended Posts