2015-07-08 01:10:34 +02:00
|
|
|
require 'opal/pixi'
|
|
|
|
require 'native'
|
2015-07-09 11:32:29 +02:00
|
|
|
#require_relative "registers"
|
2015-07-06 20:55:34 +02:00
|
|
|
|
|
|
|
class Game
|
2015-07-09 11:32:29 +02:00
|
|
|
|
2015-07-06 20:55:34 +02:00
|
|
|
def initialize
|
2015-07-09 11:32:29 +02:00
|
|
|
stage = PIXI::Container.new
|
|
|
|
|
|
|
|
height = `window.innerHeight`
|
|
|
|
width = `window.innerWidth`
|
|
|
|
puts width
|
|
|
|
renderer = PIXI::WebGLRenderer.new( width - 100 , height - 100, {})
|
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
|
2015-07-09 11:32:29 +02:00
|
|
|
html_con = body.firstElementChild
|
|
|
|
html_con.insertBefore renderer.view , html_con.lastElementChild
|
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
|
2015-07-09 11:32:29 +02:00
|
|
|
`requestAnimationFrame(animate)`
|
2015-07-08 01:10:34 +02:00
|
|
|
bunny.rotation += 0.1
|
|
|
|
renderer.render stage
|
2015-07-06 20:55:34 +02:00
|
|
|
end
|
2015-07-09 11:32:29 +02:00
|
|
|
animate.call
|
2015-07-06 20:55:34 +02:00
|
|
|
end
|
|
|
|
end
|