Skip to content

Commit

Permalink
generic sprite anim fix and send_to_back option
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Jan 21, 2024
1 parent c59513f commit 2f9ac5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions base/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ export class Map {
animation?: string;
/** The collision layer that the sprite will be. Important when sorting sprites. */
collision_layer?: number;
/** If true, the sprite will be sorted under NPC layers. */
send_to_back?: boolean;
}
) {
if (key_name in this.generic_sprites) {
Expand All @@ -1735,8 +1737,10 @@ export class Map {
generic_sprite.scale.y = options?.scale_y ?? generic_sprite.scale.y;
generic_sprite.rotation = options?.rotation ?? generic_sprite.rotation;
generic_sprite.base_collision_layer = options?.collision_layer ?? this.collision_layer;
generic_sprite.send_to_back = options?.send_to_back ?? false;
if (options?.play) {
const anim_key = sprite_base.getAnimationKey(action, options.animation);
sprite_base.setAnimation(generic_sprite, action);
const anim = generic_sprite.animations.getAnimation(anim_key);
anim.play(options?.frame_rate, options?.loop);
}
Expand Down
3 changes: 2 additions & 1 deletion base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,8 @@ export class GameEventManager {
info.loop,
info.action,
info.animation,
info.collision_layer
info.collision_layer,
info.send_to_back
);
case event_types.PARTICLES:
return new ParticlesEvent(
Expand Down
6 changes: 5 additions & 1 deletion base/game_events/GenericSpriteEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class GenericSpriteEvent extends GameEvent {
private action: string;
private animation: string;
private collision_layer: number;
private send_to_back: boolean;

constructor(
game,
Expand All @@ -58,7 +59,8 @@ export class GenericSpriteEvent extends GameEvent {
loop,
action,
animation,
collision_layer
collision_layer,
send_to_back
) {
super(game, data, event_types.GENERIC_SPRITE, active, key_name, keep_reveal);
this.control_type = control_type;
Expand Down Expand Up @@ -90,6 +92,7 @@ export class GenericSpriteEvent extends GameEvent {
this.action = action;
this.animation = animation;
this.collision_layer = collision_layer;
this.send_to_back = send_to_back;
}

_fire() {
Expand All @@ -115,6 +118,7 @@ export class GenericSpriteEvent extends GameEvent {
action: this.action,
animation: this.animation,
collision_layer: this.collision_layer,
send_to_back: this.send_to_back,
}
);
this.data.map.sort_sprites();
Expand Down

0 comments on commit 2f9ac5f

Please sign in to comment.