Text
package demos
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLScriptElement
import org.w3c.dom.get
import kotlin.browser.document
import kotlin.browser.window
import kotlin.js.json
fun main(args: Array<String>) {
val app = PIXI.Application()
document.body!!.appendChild(app.view)
fun init() {
fun onAssetsLoaded() {
val bitmapFontText = PIXI.extras.BitmapText("bitmap fonts are\n now supported!", json(
"font" to "35px Desyrel",
"align" to "right"
))
bitmapFontText.x = app.screen.width.toDouble() - bitmapFontText.textWidth.toDouble() - 20
bitmapFontText.y = 20
app.stage.addChild(bitmapFontText)
}
PIXI.loader
.add("desyrel", "../assets/desyrel.xml")
.load({ _, _ -> onAssetsLoaded() })
val background = PIXI.Sprite.fromImage("../assets/textDemoBG.jpg")
background.width = app.screen.width
background.height = app.screen.height
app.stage.addChild(background)
val textSample = PIXI.Text("Pixi.js can has\n multiline text!", json(
"fontFamily" to "Snippet",
"fontSize" to 35,
"fill" to "white",
"align" to "left"
))
textSample.position.set(20)
val spinningText = PIXI.Text("I'm fun!", json(
"fontWeight" to "bold",
"fontSize" to 60,
"fontFamily" to "Arial",
"fill" to "#cc00ff",
"align" to "center",
"stroke" to "#FFFFFF",
"strokeThickness" to 6
))
spinningText.anchor.set(0.5)
spinningText.x = app.screen.width.toDouble() / 2
spinningText.y = app.screen.height.toDouble() / 2
val countingText = PIXI.Text("COUNT 4EVAR: 0", json(
"fontWeight" to "bold",
"fontStyle" to "italic",
"fontSize" to 60,
"fontFamily" to "Arvo",
"fill" to "#3e1707",
"align" to "center",
"stroke" to "#a4410e",
"strokeThickness" to 7
))
countingText.x = app.screen.width.toDouble() / 2
countingText.y = 500
countingText.anchor.x = 0.5
arrayOf(textSample, spinningText, countingText).forEach { app.stage.addChild(it) }
var count = 0.0
app.ticker.add({
count += 0.05
countingText.text = "COUNT 4EVAR: ${kotlin.math.floor(count)}"
spinningText.rotation = spinningText.rotation.toDouble() + 0.03
})
}
window.asDynamic().WebFontConfig = json(
"google" to json(
"families" to arrayOf("Snippet", "Arvo:700italic", "Podkova:700")
),
"active" to ::init
)
val wf = document.createElement("script") as HTMLScriptElement
wf.src = "https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"
wf.type = "text/javascript"
wf.async = true
val s = document.getElementsByTagName("script")[0] as HTMLElement
s.parentNode!!.insertBefore(wf, s)
}