Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently working on a 'Tiny wings' like game. I've already asked about the angle of the items in curved lines and i solved (thank you for responses),i'm currently placing the items in random positions, but the terrain it's dynamically and i don't get this working.

I've a vector with the points of the terrain, and i'm doing something similar to this (Iterating trough vector):

if( _SPManager && i % 15 == 0 && i != 0 )
{
    if (  _settings.specialPoints && _currentPoints < _settings.specialPoints )
    {
        _SPManager.addPoint( _hillsPosition[i].x , _hillsPosition[i].y );
        _currentPoints++;
    }
}

But it isn't working as i expected. It isn't displaying the right number of items (Always shows less than i specified).

How do i should place the items?

Thanks :)

share|improve this question
    
Could you comment the code you share perhaps? I am not sure it is making much sense currently.. Why not, just do this: see answer –  Zehelvion Sep 27 '12 at 19:12
    
Just to be clear, making much sense as in readable to people who are unfamiliar with it, not as in good or bad - just as far as comprehension goes. –  Zehelvion Sep 27 '12 at 19:22

1 Answer 1

up vote 0 down vote accepted

It is not clear from the code, what you are achieving by iterating. Could you do this instead:

//I am guessing:
//_settings.specialPoints == //wanted amount of items

var j : int = 0;
for(var i : int = 0; i < _settings.specialPoints; i++) //I'm assuming the above
{
    j = Math.floor(Math.random() * _hillsPosition.length);
    _SPManager.addPoint( _hillsPosition[j].x , _hillsPosition[j].y );
}

Will that work, again please clarify your goal and how the current code describes the steps to get it done. (add commenting) Thanks

Do you only want indexes that divide by 15 with no remainder for some reason?

//replace the earlier randomizer with this:
j = Math.floor(Math.random() * _hillsPosition.length); //same as before
j -= j%15;
share|improve this answer
    
Sorry, it seems that it was clear to my but not for everyone else. The vector grows when the main character reaches a distance, the world generates a new hill and the new points are added to the vector and so on. In the code described above, i was iterating through that vector to place the items in a certain point of the hill. The 'i % 15 == 0' was to 'skip' an amount points in vector. My problem is that the terrain it is created 'on fly'. Is it better now? Maybe i'm not explaining correctly, sorry for that. –  Programlocura Sep 27 '12 at 21:02
    
Yeah, it makes sense, so is the player on 'i'? What is happening when you are adding new items? –  Zehelvion Sep 27 '12 at 21:56
    
Thank you very much for helping me think in a different way, was just what I needed. Now I'm emptying the vector every time a new part of the land is drawed, then the points are updated and placed in the right place, it was simply a matter of thinking it. Thanks again. –  Programlocura Sep 28 '12 at 1:01
    
You are very welcome. :) –  Zehelvion Sep 28 '12 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.