Callbacks or threads?

Previous topic - Next topic

bigtunacan

Is there any support for callbacks or thread creation and self-termination? 

This could apply in a lot of cases, but the current scenario I ran into is that I want to be able to scale an image over a set period of time.  I would like to do this simply by calling a function once and then forgetting about it...

I would like to be able to do something like this...

Code (glbasic) Select

// Crappy pseudo-code that wouldn't possibly work...
FUNCTION zoom_sprite_over_time_elapse: sprite_name$, zoom, time_to_zoom_in_seconds%
    // Startup a thread here...
    LOCAL curr_zoom = 1
    WHILE TRUE
          draw_texture_atlas_sprite(sprite_name$, curr_zoom)
          IF curr_zoom < zoom && some_amount_of_time_has_passed
               curr_zoom += bigger
          ENDIF
    WEND
    // Oh nice... all that hard work is done... time to go all harakiri on that thread...
ENDFUNCTION

Ian Price

Can't you just set a timer in code to call that function every XXX seconds?

Code (glbasic) Select


//Main loop
...
...
INC dlay

IF delay>120 // Time delay
zoom_sprite()
delay=0
ENDIF
...


Or why kill the function, just let it run continuously and only activate part of it if the time factor is within certain params?
I came. I saw. I played.

bigtunacan

@Ocean,

Thanks!  I'll have to give it a test run to see if it works with iOS.  All of my sprite loading occurs at initialization, before I'd be spinning up any threads, so that shouldn't be a problem.