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>
|
<head>
|
||||||
<script src="https://code.createjs.com/1.0.0/easeljs.min.js"></script>
|
<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/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>
|
<script src="/api/assetProxy?url=http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/all-item_foreground_lower.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -36,32 +35,47 @@
|
||||||
<button id="pause-play">Pause/play</button>
|
<button id="pause-play">Pause/play</button>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<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() {
|
async function main() {
|
||||||
const composition = Object.values(AdobeAn.compositions)[0];
|
const composition = Object.values(AdobeAn.compositions)[0];
|
||||||
const library = composition.getLibrary();
|
const library = composition.getLibrary();
|
||||||
|
|
||||||
const manifest = library.properties.manifest.map((item) => ({
|
const manifestImages = new Map(
|
||||||
...item,
|
library.properties.manifest.map(({ id, src }) => [
|
||||||
type: createjs.Types.IMAGE, // can't infer from assetProxy URL!
|
id,
|
||||||
src:
|
loadImage(
|
||||||
"/api/assetProxy?url=" +
|
proxyUrl(
|
||||||
encodeURIComponent(
|
"http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/" +
|
||||||
"http://images.neopets.com/cp/items/data/000/000/564/564507_fc3216b9b8/" +
|
src
|
||||||
item.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();
|
const spriteSheets = composition.getSpriteSheet();
|
||||||
for (const { name, frames } of library.ssMetadata) {
|
for (const { name, frames } of library.ssMetadata) {
|
||||||
|
const image = await manifestImages.get(name);
|
||||||
spriteSheets[name] = new createjs.SpriteSheet({
|
spriteSheets[name] = new createjs.SpriteSheet({
|
||||||
images: [queue.getResult(name)],
|
images: [image],
|
||||||
frames,
|
frames,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue