207 lines
4.3 KiB
Plaintext
207 lines
4.3 KiB
Plaintext
log.console("test_sprite starting")
|
|
|
|
var time = use('time')
|
|
|
|
var core = use('core')
|
|
var sprite = use('sprite')
|
|
var compositor = use('compositor')
|
|
var film2d = use('film2d')
|
|
var math = use('math/radians')
|
|
|
|
var sprites = []
|
|
var t = 0
|
|
|
|
var camera = {
|
|
pos: {x: 250, y: 250},
|
|
width: 500,
|
|
height: 500,
|
|
anchor: {x: 0.5, y: 0.5}
|
|
}
|
|
|
|
var compositor_config = {
|
|
clear: {r: 0.1, g: 0.1, b: 0.15, a: 1},
|
|
planes: [
|
|
{
|
|
name: 'main',
|
|
plane: 'main',
|
|
camera: camera,
|
|
resolution: {width: 500, height: 500},
|
|
presentation: 'stretch',
|
|
clear: {r: 0.1, g: 0.1, b: 0.15, a: 1}
|
|
}
|
|
]
|
|
}
|
|
|
|
function init() {
|
|
// Row 1: Opacity test - 0, 0.25, 0.5, 0.75, 1.0
|
|
var i = 0
|
|
for (i = 0; i < 5; i++) {
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 50 + i * 100, y: 450},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
opacity: i * 0.25
|
|
})
|
|
}
|
|
|
|
// Row 2: Tint test - red, green, blue, yellow, magenta
|
|
var tints = [
|
|
{r: 1, g: 0, b: 0, a: 1},
|
|
{r: 0, g: 1, b: 0, a: 1},
|
|
{r: 0, g: 0, b: 1, a: 1},
|
|
{r: 1, g: 1, b: 0, a: 1},
|
|
{r: 1, g: 0, b: 1, a: 1}
|
|
]
|
|
for (i = 0; i < 5; i++) {
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 50 + i * 100, y: 350},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
tint: tints[i]
|
|
})
|
|
}
|
|
|
|
// Row 3: Filter test - nearest (small scaled up) vs linear (small scaled up)
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 125, y: 250},
|
|
width: 150,
|
|
height: 150,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
filter: 'nearest'
|
|
})
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 375, y: 250},
|
|
width: 150,
|
|
height: 150,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
filter: 'linear'
|
|
})
|
|
|
|
// Row 4: Flip test - normal, flip_x, flip_y, flip_both
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 75, y: 125},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
flip: {x: false, y: false}
|
|
})
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 175, y: 125},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
flip: {x: true, y: false}
|
|
})
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 275, y: 125},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
flip: {x: false, y: true}
|
|
})
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 375, y: 125},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
flip: {x: true, y: true}
|
|
})
|
|
|
|
// Row 5: UV scroll test - animated texture offset
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 0,
|
|
image: 'examples/bunny',
|
|
pos: {x: 450, y: 125},
|
|
width: 64,
|
|
height: 64,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
uv: {offset: {x: 0, y: 0}, scale: {x: 1, y: 1}, rotate: 0}
|
|
})
|
|
|
|
// Animated opacity sprite
|
|
sprites[] = sprite({
|
|
plane: 'main',
|
|
layer: 1,
|
|
image: 'examples/bunny',
|
|
pos: {x: 250, y: 50},
|
|
width: 80,
|
|
height: 80,
|
|
anchor_x: 0.5,
|
|
anchor_y: 0.5,
|
|
opacity: 1
|
|
})
|
|
|
|
log.console("test_sprite initialized with " + text(length(sprites)) + " sprites")
|
|
}
|
|
|
|
function update(dt) {
|
|
t += dt
|
|
|
|
// Animate opacity on the last sprite (pulsing)
|
|
var animated_opacity_sprite = sprites[length(sprites) - 1]
|
|
animated_opacity_sprite.opacity = 0.5 + 0.5 * math.sine(t * 2)
|
|
|
|
// Animate UV scroll on the UV test sprite
|
|
var uv_sprite = sprites[length(sprites) - 2]
|
|
uv_sprite.uv.offset.x = (t * 0.5) % 1
|
|
uv_sprite.uv.offset.y = (t * 0.3) % 1
|
|
|
|
// Animate tint on first tint sprite (cycling hue)
|
|
var tint_sprite = sprites[5]
|
|
tint_sprite.tint.r = 0.5 + 0.5 * math.sine(t * 1.5)
|
|
tint_sprite.tint.g = 0.5 + 0.5 * math.sine(t * 1.5 + 2.094)
|
|
tint_sprite.tint.b = 0.5 + 0.5 * math.sine(t * 1.5 + 4.188)
|
|
}
|
|
|
|
function render() {
|
|
var plan = compositor.compile(compositor_config)
|
|
return compositor.execute(plan)
|
|
}
|
|
|
|
init()
|
|
|
|
core.start({
|
|
width: 500,
|
|
height: 500,
|
|
title: "Test Sprite Features",
|
|
framerate: 60,
|
|
update: update,
|
|
render: render
|
|
})
|