Description
I really liked the Zelda example and Sprite::Animated, and I have come up with a few things that should be implemented. They should all be simple to implement and all have a great benefit.
Firstly, it would be perfect if we could separate the x and y when making the animation sequences. So instead of doing this:
$hero->set_sequences(
stop => [ [ 0, 0 ] ],
stop_left => [ [ 0, 1 ] ],
stop_right => [ [ 0, 2 ] ],
stop_up => [ [ 0, 3 ] ],
stop_down => [ [ 0, 0 ] ],
down => [
[ 0, 0 ], [ 1, 0 ], [ 2, 0 ], [ 3, 0 ],
[ 4, 0 ], [ 5, 0 ], [ 6, 0 ], [ 7, 0 ],
],
left => [ [ 0, 1 ], [ 1, 1 ], [ 2, 1 ], [ 3, 1 ], [ 4, 1 ], [ 5, 1 ], ],
right => [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 2 ], [ 5, 2 ], ],
up => [
[ 0, 3 ], [ 1, 3 ], [ 2, 3 ], [ 3, 3 ],
[ 4, 3 ], [ 5, 3 ], [ 6, 3 ], [ 7, 3 ],
],
);
We could do something like this:
$hero->set_sequences_x(
down => [ 0..7 ],
left => [ 0..5 ],
right => [ 0..5 ],
up => [ 0..7 ],
);
$hero->set_sequences_y(
stop => [],
stop_down => [],
stop_left => [ 1 ],
stop_right => [ 2 ],
stop_up => [ 3 ],
left => 1,
right => 2,
up => 3,
);
Notice other than the x, y, I used [] to mean [0]. This should already be possible, and it probably is. Also, when you specify a value without the arrayref, it will apply that value to every frame of sequence. This means that you would have to use the arrayref form to use this form (but you should be able to do it in any order).
Next, the ticks_per_frame sets the framerate for every animation of the sprite.
my $hero = SDLx::Sprite::Animated->new(
ticks_per_frame => 600,
);
There should be a way to set the framerate for each individual sequence of animations. Something like:
$hero->set_sequences_ticks_per_frame(
up => 400,
down => 800,
);
Also, there should be a "cycle counter" that counts the number of times the sequence has finished and looped back to the start. This might be in $hero->{cycles}. This would be very useful for making animations that play once when combined with something like set_sequences_call_after_cycles().
$bomb->set_sequences_call_after_cycles(
explode => &kill_sprite;
);
After 1 cycle of the explode animation, &kill_sprite will be called and be given the $bomb var as if it were a method call. Also, if you needed to do something after more cycles, you could do something like:
$hero->set_sequences_call_after_cycles(
idle => { 20 => sub{ $_[0]->current_sequence("random_stuff") } };
);
The keys for the hash are the number of cycles and the values are the coderefs again. As shown in the example, this would be useful to make the player do something random when they have been idling for too long (as you would see in many games).
Next. Combine this:
$app->add_move_handler( &move_hero );
$app->add_move_handler( &boundary_check );
$app->add_move_handler( &scroll_background );
Into this:
$app->add_move_handler( &move_hero, &boundary_check, &scroll_background );
That's all I've got. You should implement them, they'll make things a lot easier, and that's what this is all about, right? ^_^