RenderTexture
@file:Suppress("DEPRECATION")
package demos
import PIXI.Sprite
import kotlin.browser.document
import kotlin.js.Math
fun main(args: Array<String>) {
val app = PIXI.Application()
document.body!!.appendChild(app.view)
var renderTexture = PIXI.RenderTexture.create(
app.screen.width,
app.screen.height
)
var renderTexture2 = PIXI.RenderTexture.create(
app.screen.width,
app.screen.height
)
val currentTexture = renderTexture
val outputSprite = PIXI.Sprite(currentTexture)
outputSprite.x = 400
outputSprite.y = 300
outputSprite.anchor.set(0.5)
app.stage.addChild(outputSprite)
val stuffContainer = PIXI.Container()
stuffContainer.x = 400
stuffContainer.y = 300
app.stage.addChild(stuffContainer)
val fruits = (1..8).map { i -> "../assets/spinObj_0$i.png" }
val items = Array<Sprite>(20, { i ->
val item = PIXI.Sprite.fromImage(fruits[i % fruits.size])
item.x = Math.random() * 400 - 200
item.y = Math.random() * 400 - 200
item.anchor.set(0.5)
stuffContainer.addChild(item)
return@Array item
})
var count = 0.0
app.ticker.add({
items.forEach { item -> item.rotation = item.rotation.toDouble() + 0.1 }
count += 0.01
val temp = renderTexture
renderTexture = renderTexture2
renderTexture2 = temp
outputSprite.texture = renderTexture
stuffContainer.rotation = stuffContainer.rotation.toDouble() - 0.01
outputSprite.scale.set(1 + kotlin.math.sin(count) * 0.2)
app.renderer.render(app.stage, renderTexture2, false)
})
}