-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: typo in animation 'end' event signature (#2807)
Fixes typo in animation event signature, causing the type hint to be for the wrong event! `ended` should have been `end`
- Loading branch information
Showing
5 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Animation Events</title> | ||
</head> | ||
<body> | ||
Should see all the different animation events in the console. | ||
<ul> | ||
<li>Frame for each frame</li> | ||
<li>End after the first end, then it is reset to loop</li> | ||
<li>Loop every animation afterwards</li> | ||
</ul> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="./index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
var game = new ex.Engine({ | ||
width: 400, | ||
height: 400 | ||
}); | ||
|
||
var animationImage = new ex.ImageSource('./explosion.png'); | ||
|
||
var explosionSpriteSheet = ex.SpriteSheet.fromImageSource({ | ||
image: animationImage, | ||
grid: { | ||
rows: 2, | ||
columns: 5, | ||
spriteHeight: 32, | ||
spriteWidth: 32 | ||
} | ||
}); | ||
|
||
var animation = ex.Animation.fromSpriteSheetCoordinates({ | ||
spriteSheet: explosionSpriteSheet, | ||
frameCoordinates: [ | ||
{x: 0, y: 0, duration: 100 }, | ||
{x: 1, y: 0, duration: 100 }, | ||
{x: 2, y: 0, duration: 100 }, | ||
{x: 3, y: 0, duration: 100 }, | ||
{x: 4, y: 0, duration: 100 }, | ||
{x: 0, y: 1, duration: 100 }, | ||
{x: 1, y: 1, duration: 100 }, | ||
{x: 2, y: 1, duration: 100 }, | ||
], | ||
strategy: ex.AnimationStrategy.End | ||
}); | ||
|
||
animation.scale = ex.vec(10, 10); | ||
|
||
animation.events.on('frame', (evt) => { | ||
console.log('frame', evt) | ||
}); | ||
animation.events.on('end', (anim) => { | ||
console.log('end', anim) | ||
anim.strategy = ex.AnimationStrategy.Loop; | ||
anim.reset(); | ||
}); | ||
animation.events.on('loop', (anim) => { | ||
console.log('loop', anim) | ||
}); | ||
|
||
var loader = new ex.Loader([animationImage]); | ||
|
||
var actor = new ex.Actor({ | ||
pos: ex.vec(200, 200), | ||
}); | ||
actor.graphics.use(animation); | ||
game.add(actor); | ||
|
||
game.start(loader); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters