Pixi.js: ์ƒ์œ„ ์ปจํ…Œ์ด๋„ˆ์˜ ๋„ˆ๋น„๋ฅผ ํ™•์žฅํ•˜์ง€ ์•Š๊ณ  ์˜ค๋ฅธ์ชฝ ๋งž์ถค ํ…์ŠคํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2019๋…„ 08์›” 01์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: pixijs/pixi.js

์˜ˆ, ์ด์ „ ๊ด€๋ จ ๋ฌธ์ œ๋ฅผ ์‚ดํŽด ๋ณด์•˜์Šต๋‹ˆ๋‹ค : # 4341, # 4002, # 3476

ํ…์ŠคํŠธ ์กฐ๊ฐ์„ ๋งŒ๋“ค๊ณ  ํ™”๋ฉด ์˜ค๋ฅธ์ชฝ์— ์ •๋ ฌ ํ•œ ๋‹ค์Œ ํ™”๋ฉด ์˜ค๋ฅธ์ชฝ์— ์ •๋ ฌ ๋œ ์ƒํƒœ๋กœ ์œ ์ง€ํ•˜๋ฉด์„œ ํ…์ŠคํŠธ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

anchor.x = 1 ์‚ฌ์šฉํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ์ ‘๊ทผ ๋ฐฉ์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
https://jsfiddle.net/r63ud8yL/1/

const app = new PIXI.Application({resizeTo: document.body, backgroundColor: 0xFFFFFF})
document.body.append(app.view)

// Forcing app.stage to occupy width of screen
// Is there a better way to do this?
const neCorner = new PIXI.Sprite()
neCorner.x = 0
neCorner.y = 0
const swCorner = new PIXI.Sprite()
swCorner.x = document.body.clientWidth
swCorner.y = document.body.clientHeight
app.stage.addChild(neCorner, swCorner)

const text = new PIXI.Text('first')
app.stage.addChild(text)
text.anchor.x = 1

// Align text to right edge
text.x = app.stage.width

// Replacing text with a longer string
text.text = 'second'
// It extends past the edge of the window; only 'sec' is visible

๋‹ค์Œ์€ (stage.width - text.width) ์‚ฌ์šฉํ•˜๋Š” ๋‘ ๋ฒˆ์งธ ์ ‘๊ทผ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.
https://jsfiddle.net/r63ud8yL/2/

const app = new PIXI.Application({resizeTo: document.body, backgroundColor: 0xFFFFFF})
document.body.append(app.view)

// Forcing app.stage to occupy width of screen
// Is there a better way to do this?
const neCorner = new PIXI.Sprite()
neCorner.x = 0
neCorner.y = 0
const swCorner = new PIXI.Sprite()
swCorner.x = document.body.clientWidth
swCorner.y = document.body.clientHeight
app.stage.addChild(neCorner, swCorner)

const text = new PIXI.Text('first')
app.stage.addChild(text)

// Align text to right edge
text.x = (app.stage.width - text.width)

// Replacing text with a longer string
// It extends past the edge of the window; only 'sec' is visible
text.text = 'second'

// Attempting to align text to right edge again...
text.x = (app.stage.width - text.width)
// ...but the longer text expanded the width of app.stage
// so still only 'sec' is visible

์›๋ž˜ ๋„ˆ๋น„ ์ธ app.stage ํ•˜๊ณ  ํ…์ŠคํŠธ๋ฅผ ์ •๋ ฌ ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ง€๋งŒ ํ•ด๋‹น ๊ฐ’์„ ์ €์žฅํ•  ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค. ์˜๊ตฌ ์•ต์ปค์—์„œ ์˜ค๋ฅธ์ชฝ์—์„œ ์™ผ์ชฝ์œผ๋กœ ํ•œ ์ค„ ํ…์ŠคํŠธ๋ฅผ "ํ๋ฅด๋Š”"๋ฐฉ๋ฒ•์ด ์žˆ์–ด์•ผํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋‹จ๊ณ„๋ฅผ ๋†“์น˜๊ณ  ์žˆ์Šต๋‹ˆ๊นŒ?

ํ™˜๊ฒฝ

๐Ÿค” Question

๋ชจ๋“  4 ๋Œ“๊ธ€

์ด๊ฑด ์–ด๋•Œ์š”? (๋ถ€๋ชจ ๊ฒฝ๊ณ„๊ฐ€ ์ •์  ์ธ ๊ฒฝ์šฐ)

https://jsfiddle.net/5o0yjusv/

๋ถ€๋ชจ์˜ ๊ฒฝ๊ณ„๊ฐ€ ์˜ˆ๊ธฐ์น˜ ์•Š๊ฒŒ ๋ณ€๊ฒฝ๋˜๋ฉด ํ…์ŠคํŠธ๋ฅผ ์ œ์™ธํ•œ ๊ฒฝ๊ณ„๋ฅผ ๊ณ„์‚ฐํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

https://jsfiddle.net/2xwb9yk8/

๋‚ด ์˜๊ฒฌ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. https://jsfiddle.net/b9zp5kuh/

๋ Œ๋”๋Ÿฌ ์ž์ฒด์˜ ๋„ˆ๋น„๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋งŒํ•˜๋ฉด๋ฉ๋‹ˆ๋‹ค.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค, @themoonrat . ์ด๊ฒƒ์€ ๋‚˜๋ฅผ ์˜ฌ๋ฐ”๋ฅธ ๊ธธ๋กœ ์ธ๋„ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๊ฐˆ๊ฑฐ์•ผ app.screen ๋Œ€์‹  app.renderer . ๋‚ด window.devicePixelRatio ๋Š” 2์ด๋ฏ€๋กœ ๋ Œ๋”๋Ÿฌ์˜ ๋„ˆ๋น„๋Š” ๋‚ด ์ฐฝ์˜ "์‹ค์ œ"๋„ˆ๋น„์˜ 2 ๋ฐฐ์ž…๋‹ˆ๋‹ค. app.screen ์€ 1x์ž…๋‹ˆ๋‹ค.

๋ง์ด ๋˜๋„ค์š”! '๊ณ ์ •'์„ ํ•  ๋•Œ ์ •ํ™•ํžˆ ์•Œ๋ ค์ง„ ํ”ฝ์…€๋กœ ์ž‘์—…ํ•ด์•ผํ•˜๋ฉฐ ์ปจํ…Œ์ด๋„ˆ ๋„ˆ๋น„ / ๋†’์ด๋Š” ์ž์‹ ์˜์—ญ์— ๋™์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰