Pixi.js: لا يمكن تحديث النص المحاذي لليمين بدون توسيع عرض الحاوية الرئيسية

تم إنشاؤها على ١ أغسطس ٢٠١٩  ·  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 ، لذا فإن عرض العارض هو 2x العرض "الفعلي" لنافذتي. app.screen هو 1x.

نعم ، هذا منطقي! عند القيام بأي شيء "تثبيت" ، يجب أن تعمل في وحدات بكسل معروفة بدقة ، ولا تعمل عروض / ارتفاعات الحاوية بشكل جيد لذلك لأنها ديناميكية بالنسبة لمنطقة أطفالهم.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات