import * as PIXI from 'pixi.js';
const app = new PIXI.Application({ resizeTo: window });
document.body.appendChild(app.view);
const stageSize = {
width: app.screen.width,
height: app.screen.height,
};
let renderTexture = PIXI.RenderTexture.create(stageSize);
let renderTexture2 = PIXI.RenderTexture.create(stageSize);
const currentTexture = renderTexture;
const outputSprite = new PIXI.Sprite(currentTexture);
outputSprite.x = 400;
outputSprite.y = 300;
outputSprite.anchor.set(0.5);
app.stage.addChild(outputSprite);
const stuffContainer = new PIXI.Container();
stuffContainer.x = 400;
stuffContainer.y = 300;
app.stage.addChild(stuffContainer);
const fruits = [
'https://pixijs.com/assets/rt_object_01.png',
'https://pixijs.com/assets/rt_object_02.png',
'https://pixijs.com/assets/rt_object_03.png',
'https://pixijs.com/assets/rt_object_04.png',
'https://pixijs.com/assets/rt_object_05.png',
'https://pixijs.com/assets/rt_object_06.png',
'https://pixijs.com/assets/rt_object_07.png',
'https://pixijs.com/assets/rt_object_08.png',
];
const items = [];
for (let i = 0; i < 20; i++)
{
const item = PIXI.Sprite.from(fruits[i % fruits.length]);
item.x = Math.random() * 400 - 200;
item.y = Math.random() * 400 - 200;
item.anchor.set(0.5);
stuffContainer.addChild(item);
items.push(item);
}
let count = 0;
app.ticker.add(() =>
{
for (let i = 0; i < items.length; i++)
{
const item = items[i];
item.rotation += 0.1;
}
count += 0.01;
const temp = renderTexture;
renderTexture = renderTexture2;
renderTexture2 = temp;
outputSprite.texture = renderTexture;
stuffContainer.rotation -= 0.01;
outputSprite.scale.set(1 + Math.sin(count) * 0.2);
app.renderer.render(app.stage, {
renderTexture: renderTexture2,
clear: false,
});
});