Feature/appearance #6

Merged
ilia merged 9 commits from feature/appearance into main 2026-07-20 07:09:11 +00:00
3 changed files with 11 additions and 9 deletions
Showing only changes of commit 6430470478 - Show all commits
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

+1 -1
View File
@@ -38,7 +38,7 @@ import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeV
app.stage.addChild(container); app.stage.addChild(container);
const textures = await Assets.load(['/sprites/fire_ball_1.png', '/sprites/background_1.png']); const textures = await Assets.load(['/sprites/fire_ball_1.png', '/sprites/background_1.png', '/sprites/paddle.png']);
const game = new Game(LEVELS); const game = new Game(LEVELS);
const views = createGameView(game, container, textures); const views = createGameView(game, container, textures);
+10 -8
View File
@@ -1,4 +1,4 @@
import { Container, Graphics, Sprite, Text } from 'pixi.js'; import { Container, Graphics, NineSliceSprite, Sprite, Text } from 'pixi.js';
import { CONTAINER_HEIGHT, CONTAINER_WIDTH } from './config'; import { CONTAINER_HEIGHT, CONTAINER_WIDTH } from './config';
import { Ball } from './entities/ball/ball'; import { Ball } from './entities/ball/ball';
import { Brick } from './entities/brick/brick'; import { Brick } from './entities/brick/brick';
@@ -23,9 +23,14 @@ function createBallView(ball, texture) {
/** /**
* Создает визуальное отображение ракетки с помощью Pixi.js * Создает визуальное отображение ракетки с помощью Pixi.js
* @param {Paddle} paddle экземпляр класса ракетка * @param {Paddle} paddle экземпляр класса ракетка
* @param {unknown} texture текстура ракетки
*/ */
function createPaddleView(paddle) { function createPaddleView(paddle, texture) {
return new Graphics().rect(0, 0, paddle.width, paddle.height).fill('#fff000'); const paddleSprite = new NineSliceSprite({ texture, leftWidth: 150, rightWidth: 150, topHeight: 0, bottomHeight: 0 });
paddleSprite.width = paddle.width;
paddleSprite.height = paddle.height;
return paddleSprite;
} }
/** /**
@@ -92,7 +97,7 @@ export function createGameView(game, container, textures) {
balls.set(ball, ballView); balls.set(ball, ballView);
} }
const paddle = createPaddleView(game.paddle); const paddle = createPaddleView(game.paddle, textures['/sprites/paddle.png']);
container.addChild(paddle); container.addChild(paddle);
const bricks = game.bricks.map((brick) => { const bricks = game.bricks.map((brick) => {
@@ -124,10 +129,7 @@ export function createGameView(game, container, textures) {
*/ */
export function managePerkViewsLifetime(views, game, container) { export function managePerkViewsLifetime(views, game, container) {
if (views.paddle.width !== game.paddle.width) { if (views.paddle.width !== game.paddle.width) {
container.removeChild(views.paddle); views.paddle.width = game.paddle.width;
views.paddle.destroy();
views.paddle = createPaddleView(game.paddle);
container.addChild(views.paddle);
} }
for (const [ball, ballView] of views.balls) { for (const [ball, ballView] of views.balls) {