基於 Mwni 的函式庫改編而來,
這個 PIXI.js 的模組提供了一種方便的方法來將文字輸入框添加到 PIXI.js 舞台上。輸入框本身是一個 HTML \<input> 元素,根據 PIXI.DisplayObject 給定的變換位置放置在舞台上方。方框會在 PIXI 舞台上繪製。此外,您可以選擇在文字輸入框失去焦點時,選擇是否應該用 PIXI.Text 來替代 \<input>。
this
賦值前,需要事先宣告屬性變數。private
)。_dom_visible
誤寫成 dom_visible
的 BUG。interface
,TextInputOptions、TextInputStyle、TextBoxStyle
,並於部分輸入參數加上型別標註。renderWebGL
、renderCanvas
,這些函數用於支援 pixi v4,但此模組使用的 pixi 為 v5,因此不需要這些函數。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 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.