feat(assets): use single texture atlas instead of loading all images individually
This commit is contained in:
@@ -15,9 +15,9 @@ const { onRender, onClick } = useScreen();
|
||||
|
||||
const { assets } = useAssets();
|
||||
|
||||
const BUTTON_WIDTH = assets.common.button.width;
|
||||
const BUTTON_HEIGHT = assets.common.button.height;
|
||||
const LETTER_WIDTH = assets.common.B.width;
|
||||
const BUTTON_WIDTH = assets.images.common.button.rect.width;
|
||||
const BUTTON_HEIGHT = assets.images.common.button.rect.height;
|
||||
const LETTER_WIDTH = assets.images.common.B.rect.width;
|
||||
|
||||
const B_BUTTON: Rect = [31, 172, BUTTON_WIDTH, BUTTON_HEIGHT];
|
||||
const A_BUTTON: Rect = [144, 172, BUTTON_WIDTH, BUTTON_HEIGHT];
|
||||
@@ -29,23 +29,25 @@ onRender((ctx) => {
|
||||
ctx.translate(0, props.yOffset);
|
||||
|
||||
const drawButton = (
|
||||
image: HTMLImageElement,
|
||||
image: {
|
||||
draw: (ctx: CanvasRenderingContext2D, x: number, y: number) => void;
|
||||
},
|
||||
text: string,
|
||||
x: number,
|
||||
offset: number,
|
||||
) => {
|
||||
ctx.drawImage(assets.common.button, x, 172);
|
||||
assets.images.common.button.draw(ctx, x, 172);
|
||||
|
||||
const { actualBoundingBoxRight: textWidth } = ctx.measureText(text);
|
||||
const width = LETTER_WIDTH + 4 + textWidth;
|
||||
const left = Math.ceil(x + BUTTON_WIDTH / 2 - width / 2 - offset / 2);
|
||||
|
||||
ctx.drawImage(image, left, 176);
|
||||
image.draw(ctx, left, 176);
|
||||
ctx.fillText(text, left + LETTER_WIDTH + 4, 185);
|
||||
};
|
||||
|
||||
drawButton(assets.common.B, props.bLabel, 31, 5);
|
||||
drawButton(assets.common.A, props.aLabel, 144, 0);
|
||||
drawButton(assets.images.common.B, props.bLabel, 31, 5);
|
||||
drawButton(assets.images.common.A, props.aLabel, 144, 0);
|
||||
}, 60);
|
||||
|
||||
onClick((x, y) => {
|
||||
|
||||
Reference in New Issue
Block a user