Timing Enemy Creation
I am creating a 2d side scroller game with blitzbasic. i got everything down but the timing. My current implementation creates a new enemy every frame. I tried to slow down the creation by using delay on the enemy creation, but all it did was delay the whole game.
so what i am trying to ask is how do i slow down the enemy creation without slowing down the entire program?
You'll need some kind of timer.
The most simple thing you could do is to store the number of the current/last frame in a variable. Also store when the last enemy was created in a variable. Decide on how often you want to add enemies and update the lastenemy variable when you add a new enemy.
Of course... you might want to use a real timer that actually measures time instead.
The most simple thing you could do is to store the number of the current/last frame in a variable. Also store when the last enemy was created in a variable. Decide on how often you want to add enemies and update the lastenemy variable when you add a new enemy.
Of course... you might want to use a real timer that actually measures time instead.
what i was thinking of trying to do was create an actual timer. Then i would have a certain number. every time the number divided into the time with a remainder of 0 create an enemy.
here's what i have come with:
timer= createtimer(100) ;100 is when to create a tick
...
create_enemy()
time= timerticks(timer) ;time equals total # of current ticks
if (timer modulus 3=0) then ;if = 0 crate an enemy.
{
enemy.enemy=new enemy
}
does anyone know of a better way of doing this?
timer= createtimer(100) ;100 is when to create a tick
...
create_enemy()
time= timerticks(timer) ;time equals total # of current ticks
if (timer modulus 3=0) then ;if = 0 crate an enemy.
{
enemy.enemy=new enemy
}
does anyone know of a better way of doing this?
Leffe(or anyone else) could you elaborate on your idea of current and last frame. possibly post example code, thanks, in advance.
Have two variables:
1) how often to create an enemy (in ticks)
2) how long since the previous enemy was created
Each physics step (tick), then do this:
You can change the "++" to "+= elapsedTime" or whatever, depending on whether you use ticks or seconds for your measurements (if it's seconds, you probably want double rather than int for the counter, too :-)
1) how often to create an enemy (in ticks)
2) how long since the previous enemy was created
Each physics step (tick), then do this:
curTick++; if( curTick >= howOftenToCreateAnEnemy ) { curTick -= howOftenToCreateAnEnemy; CreateEnemy(); }
You can change the "++" to "+= elapsedTime" or whatever, depending on whether you use ticks or seconds for your measurements (if it's seconds, you probably want double rather than int for the counter, too :-)
You could also just create a new enemy every 10th frame or so -- though that wouldn't be as accurate as a timer.
Quote:Original post by mumpo
You could also just create a new enemy every 10th frame or so -- though that wouldn't be as accurate as a timer.
yeah, i tried that. it worked fairly well, but the time would change constantly becase i use random enemies, and some of them are more detailed than others, so the time between creations would slow down and speed up constantly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement