PixiTextInput master READ ONLY 0
  • explorer
  • search
a [App]
a CG.PixiTextInput
a README.md
a app.ts
a [Test]
a test
  • README.md

PIXI 文字輸入框(PixiTextInput)

基於 Mwni 的函式庫改編而來,

這個 PIXI.js 的模組提供了一種方便的方法來將文字輸入框添加到 PIXI.js 舞台上。輸入框本身是一個 HTML \<input> 元素,根據 PIXI.DisplayObject 給定的變換位置放置在舞台上方。方框會在 PIXI 舞台上繪製。此外,您可以選擇在文字輸入框失去焦點時,選擇是否應該用 PIXI.Text 來替代 \<input>。

我的改動

  1. 事先宣告 Class 的屬性變數,因為 TypeScript 在使用 this 賦值前,需要事先宣告屬性變數。
  2. 將所有帶有 _ 前綴的屬性、函數,變成私有屬性(private)。
  3. 修正了一個把 _dom_visible 誤寫成 dom_visible 的 BUG。
  4. 添加了三個 interfaceTextInputOptions、TextInputStyle、TextBoxStyle,並於部分輸入參數加上型別標註。
  5. 刪除函數 renderWebGLrenderCanvas,這些函數用於支援 pixi v4,但此模組使用的 pixi 為 v5,因此不需要這些函數。
  6. 讓 _surrogate.resolution 預設為 2。
  7. 修正部分因 JavaScript 源碼,轉移到 TypeScript 後所出現的錯誤提示,如型別錯誤等。

使用範例

import pixi = CG.Base.pixi;
import TextInput = CG.PixiTextInput.TextInput;

function examples() {
    // 初始化 pixi 舞台
    pixi.initialize(600, 500);

    // 建立文字輸入框
    const input = new TextInput({
        input: {
            fontSize: '25pt',
            padding: '14px',
            width: '500px',
            color: '#26272E'
        },
        box: { fill: 0xE8E9F3, rounded: 16, stroke: { color: 0xCBCEE0, width: 4 } }
    })
    input.position.set(pixi.stageWidth * 0.5, pixi.stageHeight * 0.5); // 調整輸入框的位置
    input.pivot.set(input.width * 0.5, input.height * 0.5); // 調整輸入框的錨點
    pixi.root.addChild(input); // 將文字框添加到舞台中

    const input2 = new TextInput({
        input: {
            fontSize: '20pt',
            padding: '14px',
            width: '400',
            color: '#26272E'
        },
        box: { fill: 0xFFFFFF, rounded: 16, stroke: { color: 0x333333, width: 4 } }
    })
    input2.position.set(pixi.stageWidth * 0.5, pixi.stageHeight * 0.75);
    input2.pivot.set(input.width * 0.5, input.height * 0.5);
    pixi.root.addChild(input2);

}

examples();

原始 MIT 許可證

MIT License

Copyright (c) 2018 Mwni

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Links and Resources

Authors

cook1470

READ ONLY
  • problem
  • console
No problems have been detected so far.
Ln 1, Col 1, Sel 0
Markdown