Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SDLx::Sprite::Animated ideas #132

Open
kthakore opened this Issue · 11 comments

1 participant

@kthakore
Owner

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? ^_^

@kthakore
Owner

Author: Blaizer
Time: 1279586144
Field: status
Value: assigned

@kthakore kthakore was assigned
@kthakore
Owner

Author: Blaizer
Time: 1279586144
Field: difficulty
Value: Pretty easy

@kthakore
Owner

Author: Blaizer
Time: 1279586144
Field: owner
Value: Blaizer

@kthakore
Owner

Author: Blaizer
Time: 1279586144
Field: comment
Value:

@kthakore
Owner

Author: Blaizer
Time: 1279624702
Field: comment
Value: $hero->set_sequences_y(
stop => [],
);

Having [] here mean [0] is a bad idea, it should mean []. What I really meant was:

$hero->set_sequences(
stop => [ [] ],
);

mean

$hero->set_sequences(
stop => [ [ 0, 0 ] ],
);

which is a good idea.

@kthakore
Owner

Author: Blaizer
Time: 1279630143
Field: status
Value: accepted

@kthakore
Owner

Author: Blaizer
Time: 1279630143
Field: comment
Value:

@kthakore
Owner

Author: Blaizer
Time: 1279762880
Field: comment
Value: After thinking about this for a long time, I've decided on a new format. Instead of all the set_sequences_* functions, it would be much better like this:

$animation->set_sequences(
idle => {
x => [0..7],
after_cycle => { 20 => &random_animation },
},
attack => {
x => [0..5],
y => 1,
ticks_per_frame => 10,
after_cycle => &end;
},
a_sequence_where_each_frame_is_of_different_dimensions_to_the_others => {
rect => [0, 0, 10, 20],
x => [0, 1],
y => 5,
}
);

Each hash key works as explained before. If ticks_per_frame isn't specified, the default ticks_per_frame set when the animation is constructed is used. The rect key is used when you want the rect a different width/height for that particular animation.

I think that's it, there might be something I missed.

@kthakore
Owner

Author: Blaizer
Time: 1280035407
Field: version
Value: 2.5

@kthakore
Owner

Author: Blaizer
Time: 1280035407
Field: milestone
Value: Extend

@kthakore
Owner

Author: Blaizer
Time: 1280035407
Field: comment
Value:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.