             root.style.position = 'relative'
 
         #The canvas could be inside other element (root) used to get the mouse events
-        if canvas.tagName != 'CANVAS'
-            canvas = @canvas = root.querySelector 'canvas'
+        canvas = @canvas = if root.tagName == 'CANVAS'
+            root
+        else
+            root.querySelector 'canvas'
         @main_loop = new MainLoop @
         render_manager = new RenderManager(
             @,

class Myou

    constructor: (root, MYOU_PARAMS)->
        @scenes= {}
        @loaded_scenes= []
        @active_sprites= []
        @objects= {}
        @actions= {}
        @groups= {}
        @log = []
        @debug_loader= null
        @canvas= null
        @root= null
        @all_materials= []
        @mesh_datas= []
        @SHADER_LIB= ''
        @all_anim_objects= []
        @root = @canvas = canvas = root
        @MYOU_PARAMS = MYOU_PARAMS
        @hash = Math.random()
        # The root element needs to be positioned, so the mouse events (layerX/Y) are


    on_scene_ready: (scene_name, callback)->
        scene_ready = @scenes[scene_name]? and (not @MYOU_PARAMS.load_physics_engine or Ammo?)
        queue = @on_scene_ready_queue[scene_name]
        # If scene was ready, just call all callbacks
        if scene_ready
            while queue.length
                queue.shift()()
            callback?()
        # otherwise, add this callback and keep checking on each frame
        else
            if callback?
                if queue?
                        queue.push(callback)
                else
                    queue = [callback]
            requestAnimationFrame(=> @on_scene_ready(scene_name))

    update_canvas_rect:  =>
        @canvas_rect = @canvas.getClientRects()[0]
