728x90
app.renderer vs app.view
app.renderer๋ ๋ด๋ถ ๋งค์ปค๋์ฆ์ด๋ผ๋ฉด,(์บ๋ฒ์ค ์์ ์กฐ์ )
app.view๋ ์ด๋ฏธ ๋ง๋ค์ด์ง ์บ๋ฒ์ค ์์ฒด
//๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ
app.renderer.backgroundColor = 0x23395D;
//css
app.renderer.view.style.position = 'absolute';
Graphic ํด๋์ค
- ์ฌ๊ฐํ
app.stage๋ ํฌํ ์ต์์ ๋ ์ด์ด๋ฅผ ์๋ก ๊ณ์ ์์๊ฐ๋ ๋๋์ ์๊ฐํ๋ฉด ์ฝ๋ค.
const graphics = PIXI.Graphics;
const rect = new graphics();
rect.beginFill(0x00ff00)
.drawRect(40, 40, 200, 250)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(rect);
- ์์ ๋ก์ด ํด๋ฆฌ
const poly = new graphics();
rect.beginFill(0x00ff00)
.lineStyle(4, 0xFFEAA00, 1)
.drawPolygon(
[600, 50,
800, 150,
900, 300,
400, 300]
)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(poly);
- ์
const circle = new graphics();
circle.beginFill(0x00ff00)
.lineStyle(4, 0xFFEAA00, 1)
.drawCircle(440, 400, 80)//x์ขํ y์ขํ ๋ฐ์ง๋ฆ
.endFill()
app.stage.addChild(circle);
- ์
const line = new graphics();
line.lineStyle(4, 0xFFEAA00, 1)
.moveTo(1500, 100)
.lineTo(1500, 800)
app.stage.addChild(line);
- ๊ฐ์ด๋ฐ๊ฐ ๋ซ๋ฆฐ ์
-๊ทธ๋ํฝ ์์คํธ๋ผ ๋ชจ๋ ์ค์น
npm install @pixi/graphics-extras
const torus = new graphics();
rect.beginFill(0x00ff00)
.drawTorus(440, 440, 200, 250)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(torus);
const torus = new graphics();
rect.beginFill(0x00ff00)
.drawTorus(440, 440, 200, 250, 0, Math.PI / 2)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(torus);
- ๋ณ
const star = new graphics();
star.beginFill(0x00ff00)
.drawStar(860, 740, 30, 80)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(star);
์ ์ฒด ์ฝ๋
const Application = PIXI.Application;
const app = new Application({
//๊ฐ์ฒด๋ฅผ ์ ๋ฌํ์ฌ ์ํํ ์ ์๋ค.
width: window.innerWidth,
height: window.innerHeight,
transparent: false,
antialias: true,
backgroundColor: 0xAAAAAA
//์ด๋ฏธ์ง ๋ฐ ๋ชจ์์ ํฝ์
ํ๋ ๊ฐ์ฅ์๋ฆฌ๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ๋งค๋๋ฝ๊ฒ ํ๊ณ ์์ ํ๋ ์์ฑ
//์์ ๊ฐ์ด ๊ฐ์ฒด์ ์ค์ ํ ์ ์๋ ์์ฑ ์ค ์ผ๋ถ๋ ์บ๋ฒ์ค์ ๋๋น์ ๋์ด, ํฌ๋ช
๋ ๋ฑ์ด ์๋ค.
});
//๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ
app.renderer.backgroundColor = 0x23395D;
//์์ฑ์๊ฐ ์๋๋๋ผ๋ ์ด์ ๊ฐ์ด ํฌ๊ธฐ ์กฐ์ ๊ฐ๋ฅ
app.renderer.view.style.position = 'absolute';
document.body.appendChild(app.view);
const graphics = PIXI.Graphics;
const rect = new graphics();
rect.beginFill(0x00ff00)
.lineStyle(4, 0xFFEAA00, 1)
.drawRect(40, 40, 200, 250)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(rect);
const poly = new graphics();
rect.beginFill(0x00ff00)
.lineStyle(4, 0xFFEAA00, 1)
.drawPolygon(
[600, 50,
800, 150,
900, 300,
400, 300]
)
.endFill()
app.stage.addChild(poly);
const circle = new graphics();
circle.beginFill(0x00ff00)
.lineStyle(4, 0xFFEAA00, 1)
.drawCircle(440, 400, 80)//x์ขํ y์ขํ ๋ฐ์ง๋ฆ
.endFill()
app.stage.addChild(circle);
const line = new graphics();
line.lineStyle(4, 0xFFEAA00, 1)
.moveTo(1500, 100)
.lineTo(1500, 800)
app.stage.addChild(line);
const torus = new graphics();
torus.beginFill(0x00ff00)
.drawTorus(440, 440, 200, 250, 0, Math.PI / 2)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(torus);
const star = new graphics();
star.beginFill(0x00ff00)
.drawStar(860, 740, 30, 80)//x์ขํ y์ขํ ๋๋น ๋์ด
.endFill()
app.stage.addChild(star);
728x90
'Javascript > pixi.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[PIXI] ticker ์ฌ์ฉ๋ฐฉ๋ฒ (0) | 2022.12.26 |
---|---|
[PIXI] PIXI.Text์ PIXI.TextStyle ์ฌ์ฉ ๋ฐฉ๋ฒ (0) | 2022.12.26 |
[PIXI] app.view(์ฌ์ค์ ์บ๋ฒ์ค ํ๊ทธ) ์์ฑ ์ดํด๋ณด๊ธฐ (0) | 2022.12.23 |
[Pixi.js] ํ๊ฒฝ์ค์ ๊ณผ PIXI ๊ฐ์ฒด ์ดํด๋ณด๊ธฐ (0) | 2022.12.21 |
[Pixi.js] ํฝ์ ๊ณต๋ถ ์์ (0) | 2022.12.21 |