2015-07-08 01:10:34 +02:00
|
|
|
require 'opal/pixi'
|
|
|
|
require 'native'
|
2015-07-06 20:55:34 +02:00
|
|
|
|
|
|
|
class Game
|
|
|
|
def initialize
|
2015-07-08 01:10:34 +02:00
|
|
|
stage = PIXI::Stage.new 0x66FF99
|
|
|
|
renderer = PIXI::WebGLRenderer.new 400, 300
|
2015-07-06 20:55:34 +02:00
|
|
|
|
2015-07-08 01:10:34 +02:00
|
|
|
# opal-jquery would clean this up
|
|
|
|
body = Native(`window.document.body`)
|
|
|
|
# bit of a hack as it assumes index's structure
|
|
|
|
body.firstElementChild.firstElementChild.appendChild renderer.view
|
2015-07-06 20:55:34 +02:00
|
|
|
|
2015-07-08 01:10:34 +02:00
|
|
|
texture = PIXI::Texture.from_image "/assets/images/bunny.png"
|
|
|
|
bunny = PIXI::Sprite.new texture
|
|
|
|
bunny.anchor = PIXI::Point.new(0.5, 0.5)
|
|
|
|
bunny.position = PIXI::Point.new(300, 150)
|
2015-07-06 20:55:34 +02:00
|
|
|
|
2015-07-08 01:10:34 +02:00
|
|
|
stage.add_child(bunny)
|
2015-07-06 20:55:34 +02:00
|
|
|
|
2015-07-08 01:10:34 +02:00
|
|
|
animate = Proc.new do
|
|
|
|
`requestAnimFrame(animate)`
|
|
|
|
bunny.rotation += 0.1
|
|
|
|
renderer.render stage
|
2015-07-06 20:55:34 +02:00
|
|
|
end
|
2015-07-08 01:10:34 +02:00
|
|
|
`requestAnimFrame(animate)`
|
2015-07-06 20:55:34 +02:00
|
|
|
end
|
|
|
|
end
|