remove preloadjs from animate test, to save bundle
Well, there's no real bundle yet, but just was noticing that PreloadJS is like 100KB, and we're only using very very basic features. Simplify and save!
This commit is contained in:
parent
e20ecd8277
commit
a0c7b6076f
1 changed files with 31 additions and 17 deletions
|
@ -3,7 +3,6 @@
|
|||
<head>
|
||||
<script src="https://code.createjs.com/1.0.0/easeljs.min.js"></script>
|
||||
<script src="https://code.createjs.com/1.0.0/tweenjs.min.js"></script>
|
||||
<script src="https://code.createjs.com/1.0.0/preloadjs.min.js"></script>
|
||||
<script src="/api/assetProxy?url=http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/all-item_foreground_lower.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -36,32 +35,47 @@
|
|||
<button id="pause-play">Pause/play</button>
|
||||
</div>
|
||||
<script>
|
||||
function loadImage(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = () => resolve(image);
|
||||
image.onerror = (e) => reject(e);
|
||||
image.src = src;
|
||||
});
|
||||
}
|
||||
|
||||
function proxyUrl(url) {
|
||||
return "/api/assetProxy?url=" + encodeURIComponent(url);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const composition = Object.values(AdobeAn.compositions)[0];
|
||||
const library = composition.getLibrary();
|
||||
|
||||
const manifest = library.properties.manifest.map((item) => ({
|
||||
...item,
|
||||
type: createjs.Types.IMAGE, // can't infer from assetProxy URL!
|
||||
src:
|
||||
"/api/assetProxy?url=" +
|
||||
encodeURIComponent(
|
||||
"http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/" +
|
||||
item.src
|
||||
const manifestImages = new Map(
|
||||
library.properties.manifest.map(({ id, src }) => [
|
||||
id,
|
||||
loadImage(
|
||||
proxyUrl(
|
||||
"http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/" +
|
||||
src
|
||||
)
|
||||
),
|
||||
}));
|
||||
|
||||
const queue = new createjs.LoadQueue();
|
||||
const queueCompleted = new Promise((resolve) =>
|
||||
queue.on("complete", () => resolve())
|
||||
])
|
||||
);
|
||||
queue.loadManifest(manifest);
|
||||
await queueCompleted;
|
||||
|
||||
try {
|
||||
await Promise.all(manifestImages.values());
|
||||
} catch (e) {
|
||||
console.error("Error loading images", e);
|
||||
return;
|
||||
}
|
||||
|
||||
const spriteSheets = composition.getSpriteSheet();
|
||||
for (const { name, frames } of library.ssMetadata) {
|
||||
const image = await manifestImages.get(name);
|
||||
spriteSheets[name] = new createjs.SpriteSheet({
|
||||
images: [queue.getResult(name)],
|
||||
images: [image],
|
||||
frames,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue