game are, some registers names on the screen

This commit is contained in:
Torsten Ruger 2015-07-09 15:23:36 +03:00
parent 3f8f5cdc72
commit ab48f10ee8
3 changed files with 30 additions and 17 deletions

View File

@ -1,13 +1,14 @@
# By default Volt generates this controller for your Main component # By default Volt generates this controller for your Main component
if RUBY_PLATFORM == 'opal' if RUBY_PLATFORM == 'opal'
require "main/lib/game" require "main/lib/main_view"
end end
module Main module Main
class MainController < Volt::ModelController class MainController < Volt::ModelController
def index def index
Game.new() MainView.new()
end end
def about def about

View File

@ -1,35 +1,29 @@
require 'opal/pixi' require 'opal/pixi'
require 'native' require 'native'
#require_relative "registers" require "main/lib/registers_view"
class Game class MainView
def initialize def initialize
stage = PIXI::Container.new @container = PIXI::Container.new
height = `window.innerHeight` height = `window.innerHeight`
width = `window.innerWidth` width = `window.innerWidth`
puts width renderer = PIXI::WebGLRenderer.new( width - 100 , height - 100, {"backgroundColor" => 0xFFFFFF})
renderer = PIXI::WebGLRenderer.new( width - 100 , height - 100, {})
# opal-jquery would clean this up
body = Native(`window.document.body`) body = Native(`window.document.body`)
# bit of a hack as it assumes index's structure # bit of a hack as it assumes index's structure
html_con = body.firstElementChild html_con = body.firstElementChild
html_con.insertBefore renderer.view , html_con.lastElementChild html_con.insertBefore renderer.view , html_con.lastElementChild
texture = PIXI::Texture.from_image "/assets/images/bunny.png" @container.add_child RegisterView.new(height - 150)
bunny = PIXI::Sprite.new texture
bunny.anchor = PIXI::Point.new(0.5, 0.5)
bunny.position = PIXI::Point.new(300, 150)
stage.add_child(bunny)
animate = Proc.new do animate = Proc.new do
`requestAnimationFrame(animate)` `requestAnimationFrame(animate)`
bunny.rotation += 0.1 renderer.render @container
renderer.render stage
end end
animate.call animate.call
end end
attr_reader :container
end end

View File

@ -0,0 +1,18 @@
class RegisterView < PIXI::Container
@@register_names = (0..8).collect {|i| "r#{i}"}
def initialize at_y
super()
@registers = {}
x = 0
@@register_names.each do |name|
reg = PIXI::Text.new( name )
reg.position = PIXI::Point.new x , at_y
x += reg.width + 20
@registers[name] = reg
self.add_child reg
end
end
end