прелоадер на каждую сцену.

22 августа 2018 16:20
Добрый день.
Ребята, подскажите как сделать прелоадер на каждую сцену?
Вставляю, вместо «true» стандартный прелоадер.
function load_Stock(){
load_interfase();
m_data.load(APP_ASSETS_PATH_STOCK + "Stock.json", load_cb_stock, true);
}

чутка кода
22 августа 2018 16:23
b4w.register("simple_app_es5", function(exports, require) {
// import modules used by the app

var m_app       = b4w.require("app");
var m_cfg       = b4w.require("config");
var m_data      = b4w.require("data");
var m_preloader = b4w.require("preloader");
var m_ver       = b4w.require("version");
var m_anim      = b4w.require("animation");
var m_cont      = b4w.require("container");
var m_mouse     = b4w.require("mouse");
var m_scenes    = b4w.require("scenes");
var m_geom      = require("geometry");
var m_obj       = require("objects");
var m_ln        = require("logic_nodes");
var m_cam       = require("camera");
var m_phy       = require("physics");
var m_trans     = require("transform");
var m_util      = require("util");
var m_tex       = require("textures");
/*——————————————————-Variable_Initialization———*/
var _previous_selected_obj = null,
    stage = false,
    game_end = false,
    block_door = false,
    answer = 0,
    can = 0,
    cube = null,
    exit_bild = null,
    ent_Stock = null,          /*1.10*/
    ent_Industrial = null,     /*2.9*/
    ent_Admin = null,          /*3.21*/
    ent_Safety = null,         /*4.10*/
    ent_Training = null,       /*5.10*/
    ent_Smoking = null,        /*6.5*/
    ent_Locker = null,         /*7.12*/
    ent_Security = null,       /*8.10*/
    ent_Recreation = null,     /*9.17*/
    ent_Camteen = null,        /*10.9*/
    ent_Hotel = null,          /*11.23*/
    ent_Pantry = null,         /*12.5*/
    ent_Bookkeeping = null,    /*13.9*/
    ent_Medical = null,        /*14.17*/
/*—————-ALL_GEOMERTY—————————--*/
/*—————-Склад————————————*/
ent_cargoRackOne = null,
ent_cargoRackTwo = null,
ent_rackOne = null,
ent_rackTwo = null,
ent_rackThree = null,
ent_emergencyKey = null,
ent_tireRack = null,
ent_safe = null,
ent_cabinetTool = null,
ent_urn = null,
ent_desiccator = null,

/*———————————————————*/    
    arr_num = {
    	"w1":  "ent_Stock",
    	"w2":  "ent_Industrial",
    	"w3":  "ent_Admin",
    	"w4":  "ent_Safety",
    	"w5":  "ent_Training",
    	"w6":  "ent_Smoking",
    	"w7":  "ent_Locker",
    	"w8":  "ent_Security",
    	"w9":  "ent_Recreation",
    	"w10": "ent_Camteen",
    	"w11": "ent_Hotel",
    	"w12": "ent_Pantry",
    	"w13": "ent_Bookkeeping",
    	"w14": "ent_Medical",
    },
    arr_quan = ["0","11","9","22","11","10","5","12","12","17","11","22","5","9","15"], 
    arr_img = ["c_1.jpg","c_2.jpg","c_3.jpg","c_4.jpg","c_5.jpg","c_6.jpg","c_7.jpg","c_8.jpg","c_9.jpg","c_10.jpg","c_11.jpg","c_12.jpg","c_13.jpg","c_14.jpg"],  
    id = 0,
    num_id = 0,
    id2 = 0,
    num_id2 = 0,
    id3 = 0,
    num_id3 = 0,
    val_id3 = 0,
    step_block = 0,
    step_move = 3,    
    st = 0,
    slider = 100,
    ans_id = 0,
    arr_ge = {
        "gе_1":   0,
        "gе_2":   0,
        "gе_3":   0,
        "gе_4":   0,
        "gе_5":   0,
        "gе_6":   0,
        "gе_7":   0,
        "gе_8":   0,
        "gе_9":   0,
        "gе_10":  0,
        "gе_11":  0,
        "gе_12":  0,
        "gе_13":  0,
        "gе_14":  0,
    },
    arr_room = {
        "r1": "Склад",
        "r2": "Производственный цех",
        "r3": "Администрация",
        "r4": "Комната охраны труда",
        "r5": "Учебный класс",
        "r6": "Курилка",
        "r7": "Раздевалка/душевая",
        "r8": "Зона охраны",
        "r9": "Комната отдыха",
        "r10": "Столовая",
        "r11": "Гостиница для сотрудников",
        "r12": "Кладовка для бытхим",
        "r13": "Бухгалтерия",
        "r14": "Медицинский кабинет",                                                                          
    },
	pic_info = 0,
	vendor_code = 0, 
	arr_activ = [],
	result_activ = [],
	correct_subjects = 0,	
	step_one = false,
	step_two = false,
	step_three = false,
	names = 0,
	essence = 0,
	sizes = 0,
	material = 0,
	feature = 0,
	prices = 0,    
    arr_can = {
       "can0": main_canvas_click,                      
       "can1": main_canvas_click_stock,                   /*sign 1*/
       "can2": main_canvas_click_Industrial,              /*sign 2*/
       "can3": main_canvas_click_admin,                   /*sign 3*/
       "can4": main_canvas_click_safely,                  /*sign 4*/
       "can5": main_canvas_click_Training,                /*sign 5*/
       "can6": main_canvas_click_Smoking,                 /*sign 6*/
       "can7": main_canvas_click_Locker,                  /*sign 7*/
       "can8": main_canvas_click_Security,                /*sign 8*/
       "can9": main_canvas_click_Recreation,              /*sign 9*/
       "can10": main_canvas_click_Camteen,                /*sign 10*/
       "can11": main_canvas_click_Hotel,                  /*sign 11*/
       "can12": main_canvas_click_Pantry,                 /*sign 12*/
       "can13": main_canvas_click_Bookkeeping,            /*sign 13*/
       "can14": main_canvas_click_Medical,                /*sign 14*/                                              
    }, 
    obj_grids = {
       "grid_red": "assets/grid_red.png",
       "grid_green": "assets/grid_green.png", 
    },   
// detect application mode
    DEBUG = (m_ver.type() == "DEBUG");

// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_assets_path("simple_app");
var APP_ASSETS_PATH_STOCK = m_cfg.get_assets_path("Stock");
var APP_ASSETS_PATH_INDUST = m_cfg.get_assets_path("industrial");
var APP_ASSETS_PATH_ADMIN = m_cfg.get_assets_path("admin");
var APP_ASSETS_PATH_SAFELY = m_cfg.get_assets_path("safely");
var APP_ASSETS_PATH_TRAINING = m_cfg.get_assets_path("training");
var APP_ASSETS_PATH_LOCKER = m_cfg.get_assets_path("Locker")
var APP_ASSETS_PATH_SMOK = m_cfg.get_assets_path("Smoking");
var APP_ASSETS_PATH_RECREATION = m_cfg.get_assets_path("Recreation")
var APP_ASSETS_PATH_CAMTEEN = m_cfg.get_assets_path("Camteen");
var APP_ASSETS_PATH_HOTEL = m_cfg.get_assets_path("Hotel");
var APP_ASSETS_PATH_PANTRY = m_cfg.get_assets_path("Pantry");
var APP_ASSETS_PATH_BOOK = m_cfg.get_assets_path("Bookkeeping");
var APP_ASSETS_PATH_SECURITY = m_cfg.get_assets_path("Security");
var APP_ASSETS_PATH_MEDICAL = m_cfg.get_assets_path("Medical");
/**
 * export the method to initialize the app (called at the bottom of this file)
 */
exports.init = init;
function init(){
    m_app.init({
        canvas_container_id: "main_canvas_container",
        callback: init_cb,
        show_fps: DEBUG,
        console_verbose: DEBUG,
        autoresize: true
    });
}

/**
 * callback executed when the app is initialized 
 */
function init_cb(canvas_elem, success) {

    if (!success) {
        console.log("b4w init failure");
        return; 
    }

    m_preloader.create_preloader();

    // ignore right-click on the canvas element
    canvas_elem.oncontextmenu = function(e) {
        e.preventDefault();
        e.stopPropagation();
        return false;
    };
    load();
}

/**
 * load the scene data*/
function preloader_cb(percentage){
    m_preloader.update_preloader(percentage);
}
function load(){
    m_data.load(APP_ASSETS_PATH + "simple_app.json", load_cb, preloader_cb);  
}
function load_Stock(){                                             /*sign 1*/
	load_interfase();
    m_data.load(APP_ASSETS_PATH_STOCK + "Stock.json", load_cb_stock, true);
}

/*———-LOAD_SCENES CAMERAS EVENTS————*/
function load_events(data_id, success){
    if (!success) {
        console.log("b4w load failure");
        return;
    }
    m_app.enable_camera_controls();
    var canvas_elem = m_cont.get_canvas();
    var num_can =  arr_can["can"+can];
    //console.log('Number room '+can);     /*номер комнаты*/
    canvas_elem.addEventListener("mousedown", num_can, false);
    canvas_elem.addEventListener("touchstart", num_can, false);    
}
/*———-LOAD_BILD————*/
function load_cb(data_id, success) {
    load_events(data_id, success);
    if ( step_one == false ){
        setTimeout(function(){
        	step_one = true;
            $('.two_infor').fadeIn("slow");
        },500);
    }

    /*——————————————————--Object_Initialization————*/ 
    ent_Stock = m_scenes.get_object_by_name("Stock");
    ent_Industrial = m_scenes.get_object_by_name("Industrial");
    ent_Admin = m_scenes.get_object_by_name("Admin");
    ent_Safety = m_scenes.get_object_by_name("Safety");
    ent_Training = m_scenes.get_object_by_name("Training");    
    ent_Smoking = m_scenes.get_object_by_name("Smoking");
    ent_Locker = m_scenes.get_object_by_name("Locker");
    ent_Security = m_scenes.get_object_by_name("Security");
    ent_Recreation = m_scenes.get_object_by_name("Recreation");
    ent_Camteen = m_scenes.get_object_by_name("Camteen");
    ent_Hotel = m_scenes.get_object_by_name("Hotel");
    ent_Pantry = m_scenes.get_object_by_name("Pantry");
    ent_Bookkeeping = m_scenes.get_object_by_name("Bookkeeping");
    ent_Medical = m_scenes.get_object_by_name("Medical");


    /*——————————————————--Function_initialization———-*/ 
    document.getElementById("clos").onclick = hide_warn; 
    document.getElementById("room1").onclick = tester;
    document.getElementById("room2").onclick = tester;
    document.getElementById("room3").onclick = tester;
    document.getElementById("room4").onclick = tester;
    document.getElementById("room5").onclick = tester;
    document.getElementById("room6").onclick = tester;
    document.getElementById("room7").onclick = tester;
    document.getElementById("room8").onclick = tester;
    document.getElementById("room9").onclick = tester;
    document.getElementById("room10").onclick = tester;
    document.getElementById("room11").onclick = tester;
    document.getElementById("room12").onclick = tester;
    document.getElementById("room13").onclick = tester;
    document.getElementById("room14").onclick = tester; 
    document.getElementById("left_pick").onclick = move_block; 
    document.getElementById("right_pick").onclick = move_block;
    document.getElementById("cl").onclick = hide_info;
    answer_arr();                                                  
    setTimeout(function(){
        answer_stage();
    },2000);
    document.getElementById("cl_info4").onclick = close_info1;

    /*—————————————————————————-*/
}


/*———-LOAD_STOCK————*/
function load_cb_stock(data_id, success){
    load_events(data_id, success);
    forcibly_block();
    exit_bild = m_scenes.get_object_by_name("door");
    ent_cargoRackOne = m_scenes.get_object_by_name("cargoRackOne");
    ent_cargoRackTwo = m_scenes.get_object_by_name("cargoRackTwo");
    ent_rackOne = m_scenes.get_object_by_name("rackOne");
    ent_rackTwo = m_scenes.get_object_by_name("rackTwo");
    ent_rackThree = m_scenes.get_object_by_name("rackThree");
    ent_emergencyKey = m_scenes.get_object_by_name("emergencyKey");
    ent_tireRack = m_scenes.get_object_by_name("tireRack");
    ent_safe = m_scenes.get_object_by_name("safe");
    ent_cabinetTool = m_scenes.get_object_by_name("cabinetTool");
    ent_urn = m_scenes.get_object_by_name("urn");
    ent_desiccator = m_scenes.get_object_by_name("desiccator"); 
    hide_stock();    
}

function hide_stock(){
	m_scenes.hide_object(ent_cargoRackOne);   
    m_scenes.hide_object(ent_cargoRackTwo);
    m_scenes.hide_object(ent_rackOne);
    m_scenes.hide_object(ent_rackTwo);
    m_scenes.hide_object(ent_rackThree);
    m_scenes.hide_object(ent_emergencyKey);
    m_scenes.hide_object(ent_tireRack);
    m_scenes.hide_object(ent_safe);
    m_scenes.hide_object(ent_cabinetTool);
    m_scenes.hide_object(ent_urn);
    m_scenes.hide_object(ent_desiccator);

}
function show_answer_stock(){
	m_scenes.show_object(ent_cargoRackOne);   
    m_scenes.show_object(ent_cargoRackTwo);
    m_scenes.show_object(ent_rackOne);
    m_scenes.show_object(ent_rackTwo);
    m_scenes.show_object(ent_rackThree);
    m_scenes.show_object(ent_emergencyKey);
    m_scenes.show_object(ent_tireRack);	
}

function main_canvas_click_stock(e) {
    answer_canvas(e);     
    }
	
	
function answer_canvas(e){
	//console.log(block_door);
   if (e.preventDefault)
        e.preventDefault();
        var x = m_mouse.get_coords_x(e);
        var y = m_mouse.get_coords_y(e);
        var obj = m_scenes.pick_object(x, y);               
        switch (obj){
          case exit_bild: 
            if ( block_door == true){
                show_bild();  
            } 
          break;  
          default:  
        }   	
} 

function hide_block(){
    m_scenes.hide_object(cube);
}
function show_block(){
    m_scenes.show_object(cube);
}
function show_bild(data_id){
    can = 0;
    m_data.unload(m_scenes);
    m_data.load(APP_ASSETS_PATH + "simple_app.json",  load_cb, null, true);
    hide_intrface();  

}
function reset_bild(){
    m_data.unload(APP_ASSETS_PATH);
    stage = false;
    show_bild();
}
function close_game(){
    m_data.unload(APP_ASSETS_PATH);	
}
function show_stock(){                                                            /*sign 1*/
    can = 1;
    m_data.unload(APP_ASSETS_PATH);
    m_data.load("assets/Stock.json", load_cb_stock, null, true); 
    load_interface();       
}
23 августа 2018 16:15
Разобрался. И с созданием собственного прелоадора.
 
Пожалуйста, зарегистрируйтесь или войдите под своей учетной записью , чтобы оставлять сообщения.