抖音很火的召唤神龙的小游戏完整代码-召唤神龙

抖音很火的召唤神龙的小游戏完整代码-召唤神龙,第1张

抖音很火的解压小游戏,完整代码分享。有兴趣的可以试着写一下。

 

1.  index




  

  召唤神龙

  
  

  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  
  
  

  
  
  

  
  
  
  
    

  



  
  
  
  

   
  
  
  

  
 
 loading......0%

	
	 
      
        
      
   

   
    
  
  
     
   
	
   
  
  
  








  
  
  
  
  

















2. ads.js

var videoContent = document.getElementById('contentElement');

var adDisplayContainer =
    new google.ima.AdDisplayContainer(
        document.getElementById('adContainer'),
        videoContent);
// Must be done as the result of a user action on mobile
adDisplayContainer.initialize();

// Re-use this AdsLoader instance for the entire lifecycle of your page.
var adsLoader = new google.ima.AdsLoader(adDisplayContainer);

// Add event listeners
adsLoader.addEventListener(
    google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
    onAdsManagerLoaded,
    false);
adsLoader.addEventListener(
    google.ima.AdErrorEvent.Type.AD_ERROR,
    onAdError,
    false);

function onAdError(adErrorEvent) {
	 console.log("adError");
	 
	 
	document.getElementById("adContainer").style.display = "none";
	 
	 
	 
	 
	     var GameConfig = __require("GameConfig");

          if(GameConfig.playNum == 0){

              adCompleteFlag = true;
            if(adCompleteFlag && resCompleteFlag){

                adCompleteFlag = false;

                var launchScene = GameConfig.launchScene;
                var Bros = GameConfig.Bros;
                var caS = GameConfig.caS;
                cc.director.loadScene(launchScene, null,
                    function () {
                        adCompleteFlag = false;
                        if (Bros) {
                            // show canvas
                            caS = '';
                            var div = document.getElementById('GameDiv');
                            if (div) {
                                 div.style.backgroundImage = '';
                            }
                        }
                        cc.loader.onProgress = null;
                        console.log('Success to load scene: ' + launchScene);
                    }

                );

              

                }

          }
	 
	 
	 
	   adEndComplete = true;
        if(adEndComplete && resEndComplete){
            adEndComplete = false;
            console.log("indexOverErr");
            var MainManger = __require("MainManage");
            MainManger.showGameEndLayer();
        }
	 
  // Handle the error logging and destroy the AdsManager
  console.log(adErrorEvent.getError());
  adsManager.destroy();
}

// An event listener to tell the SDK that our content video
// is completed so the SDK can play any post-roll ads.
var contentEndedListener = function() {adsLoader.contentComplete();};
videoContent.onended = contentEndedListener;

// Request video ads.
var preloader = new google.ima.AdsRequest();
preloader.adTagUrl = 'https://googleads.g.doubleclick.net/pagead/ads?ad_type=video_image&client=ca-games-pub-8708616103041212&description_url=http%3A%2F%2Fwww.vsane.com&videoad_start_delay=-1&hl=zh_CN&max_ad_duration=15000';
// Specify the linear and nonlinear slot sizes. This helps the SDK to
// select the correct creative if multiple are returned.
preloader.linearAdSlotWidth = 640;
preloader.linearAdSlotHeight = 400;
preloader.nonLinearAdSlotWidth = 640;
preloader.nonLinearAdSlotHeight = 400;


// showMyAds();

function showMyAds() {
	// alert("showMy");
		if (typeof(killads)=='undefined'){
			// alert('广告被过滤');
			console.log("AdNo");
			 adEndComplete = false;
			var MainManger = __require("MainManage");
            MainManger.showGameEndLayer();
		}else{
            var winHeight = document.documentElement.clientHeight;

            if (document.body.clientHeight > 700){
                document.getElementById("adContainer").style.height = winHeight-85+"px";
            }else{
                document.getElementById("adContainer").style.height = winHeight-65+"px";
            }
            // document.getElementById("adContainer").style.height = winHeight-60+"px";
         
            document.getElementById("adContainer").style.display = "block";
            adsLoader.requestAds(preloader);
		}
}


function onAdsManagerLoaded(adsManagerLoadedEvent) {
	console.log("ADLoad");
	
	  adCompleteFlag = true;
	
	 // document.getElementById("adContainer").style.display = "block";
  // Get the ads manager.
  adsManager = adsManagerLoadedEvent.getAdsManager(
      videoContent);  // See API reference for contentPlayback

  // Add listeners to the required events.
  adsManager.addEventListener(
      google.ima.AdErrorEvent.Type.AD_ERROR,
      onAdError);
  adsManager.addEventListener(
      google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,
      onContentPauseRequested);
  adsManager.addEventListener(
      google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,
      onContentResumeRequested);

var o = document.getElementById("adContainer");
var h = o.offsetHeight; //高度
var w = o.offsetWidth; //宽度
  try {
    // Initialize the ads manager. Ad rules playlist will start at this time.
    adsManager.init(w, h, google.ima.ViewMode.FULLSCREEN);
    // Call start to show ads. Single video and overlay ads will
    // start at this time; this call will be ignored for ad rules, as ad rules
    // ads start when the adsManager is initialized.
    adsManager.start();
  } catch (adError) {
	 
    // An error may be thrown if there was a problem with the VAST response.
    // Play content here, because we won't be getting an ad.
    // videoContent.play();
  }
}

function onContentPauseRequested() {
	
	
  // This function is where you should setup UI for showing ads (e.g.
  // display ad timer countdown, disable seeking, etc.)
  videoContent.removeEventListener('ended', contentEndedListener);
  videoContent.pause();
  
}

//广告结束的时候调用的函数
function onContentResumeRequested() {
	console.log("ADLoadComplete",resEndComplete);
	
	
	
	 var GameConfig = __require("GameConfig");
        console.log("IndexMainManger",GameConfig.launchScene, GameConfig.Bros,GameConfig.caS);

        if(GameConfig.playNum == 1){
            adCompleteFlag = true;
            if(adCompleteFlag && resCompleteFlag){

                var launchScene = GameConfig.launchScene;
                var Bros = GameConfig.Bros;
                var caS = GameConfig.caS;
                cc.director.loadScene(launchScene, null,
                    function () {
						
						
                        adCompleteFlag = false;
						
						
						
                        if (Bros) {
                            // show canvas
                            var canvas = document.getElementById('GameCanvas');
							canvas.style.visibility = '';
                            var div = document.getElementById('GameDiv');
                            if (div) {
                                 div.style.backgroundImage = '';
                            }
                        }
                        cc.loader.onProgress = null;
                        console.log('Success to load scene1: ' + launchScene);
						
						
						
						
						
                    }
                );
				

            }
           

        }
		
		
		
	
	
	
	 adEndComplete = true;
        if(adEndComplete && resEndComplete){
            adEndComplete = false;
            console.log("indexOverErr");
            var MainManger = __require("MainManage");
            MainManger.showGameEndLayer();
        }
	
  // This function is where you should ensure that your UI is ready
  // to play content.
  document.getElementById("adContainer").style.display = "none";
  

  // videoContent.addEventListener('ended', contentEndedListener);
  // videoContent.play();
  
}

function noAdGoToScene(){
	
	
		 var GameConfig = __require("GameConfig");
        console.log("IndexMainMangerMaing",GameConfig.launchScene, GameConfig.Bros,GameConfig.caS);
		
				var launchScene = GameConfig.launchScene;
				var Bros = GameConfig.Bros;
                var caS = GameConfig.caS;
                cc.director.loadScene(launchScene, null,
                    function () {
						
                    adCompleteFlag = false;
						
                        if (Bros) {
                            // show canvas
                            var canvas = document.getElementById('GameCanvas');
							canvas.style.visibility = '';
                            var div = document.getElementById('GameDiv');
                            if (div) {
                                 div.style.backgroundImage = '';
                            }
                        }
                        cc.loader.onProgress = null;
                        console.log('Success to load scene1Main: ' + launchScene);
						
						
						
						
						
                    }
                );
	
	
}



3.mian.js

var loadingNum = 0;
window.boot = function () {
    var settings = window._CCSettings;
    window._CCSettings = undefined;
    var onProgress = null;
    
    var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
    var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
    var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;


    function setLoadingDisplay () {
        // Loading splash scene
        var splash = document.getElementById('splash');
        var loadintT = document.getElementById("loadingText")
        // var progressBar = splash.querySelector('.progress-bar span');
        cc.loader.onProgress = function (finish, total, item) {
            loadData.completedCount = finish;
            loadData.totalCount = total;
			
			var percent = 100 * finish / total;
			if(loadingNum >= 1 && total > 1){
				if(percent.toFixed(0) >= 100){
                    loadintT.innerHTML = 'loading......100' + '%';
                    clearInterval(timer); 
                    setTimeout(function(){
                        loadintT.remove();
                    },0.1 * 1000);
				}
			}
            loadingNum++;
        };
        splash.style.display = 'block';
        // progressBar.style.width = '0%';

        cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
            splash.style.display = 'none';
        });
    }

    var onStart = function () {

        cc.view.enableRetina(true);
        cc.view.resizeWithBrowserSize(true);

        if (cc.sys.isBrowser) {
            setLoadingDisplay();
        }

        if (cc.sys.isMobile) {
            if (settings.orientation === 'landscape') {
                cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
            }
            else if (settings.orientation === 'portrait') {
                cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
            }
            // cc.view.enableAutoFullScreen([
            //     cc.sys.BROWSER_TYPE_BAIDU,
            //     cc.sys.BROWSER_TYPE_BAIDU_APP,
            //     cc.sys.BROWSER_TYPE_WECHAT,
            //     cc.sys.BROWSER_TYPE_MOBILE_QQ,
            //     cc.sys.BROWSER_TYPE_MIUI,
            //     cc.sys.BROWSER_TYPE_HUAWEI,
            //     cc.sys.BROWSER_TYPE_UC,
            // ].indexOf(cc.sys.browserType) < 0);
            cc.view.enableAutoFullScreen(false);
        }

        // Limit downloading max concurrent task to 2,
        // more tasks simultaneously may cause performance draw back on some android system / browsers.
        // You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
        if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
            cc.assetManager.downloader.maxConcurrency = 2;
            cc.assetManager.downloader.maxRequestsPerFrame = 2;
        }

        var launchScene = settings.launchScene;
        var bundle = cc.assetManager.bundles.find(function (b) {
            return b.getSceneInfo(launchScene);
        });
        var canvas;
        if (cc.sys.isBrowser) {
            canvas = document.getElementById('GameCanvas');
        }
        
        var MainManger = __require("MainManage");
        MainManger.init(launchScene,cc.sys.isBrowser,canvas.style.visibility);
        // bundle.loadScene(launchScene, null, onProgress,
        //     function (err, scene) {
        //         if (!err) {
        //             cc.director.runSceneImmediate(scene);
        //             if (cc.sys.isBrowser) {
        //                 // show canvas
        //                 var canvas = document.getElementById('GameCanvas');
        //                 canvas.style.visibility = '';
        //                 var div = document.getElementById('GameDiv');
        //                 if (div) {
        //                     div.style.backgroundImage = '';
        //                 }
        //                 console.log('Success to load scene: ' + launchScene);
        //             }
        //         }
        //     }
        // );
    };

    var option = {
        id: 'GameCanvas',
        debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
        showFPS: settings.debug,
        frameRate: 60,
        groupList: settings.groupList,
        collisionMatrix: settings.collisionMatrix,
    };

    cc.assetManager.init({ 
        bundleVers: settings.bundleVers,
        remoteBundles: settings.remoteBundles,
        server: settings.server
    });
    
    var bundleRoot = [INTERNAL];
    settings.hasResourcesBundle && bundleRoot.push(RESOURCES);

    var count = 0;
    function cb (err) {
        if (err) return console.error(err.message, err.stack);
        count++;
        if (count === bundleRoot.length + 1) {
            cc.assetManager.loadBundle(MAIN, function (err) {
                if (!err) cc.game.run(option, onStart);
            });
        }
    }

    cc.assetManager.loadScript(settings.jsList.map(function (x) { return 'src/' + x;}), cb);

    for (var i = 0; i < bundleRoot.length; i++) {
        cc.assetManager.loadBundle(bundleRoot[i], cb);
    }
};

if (window.jsb) {
    var isRuntime = (typeof loadRuntime === 'function');
    if (isRuntime) {
        require('src/settings.js');
        require('src/cocos2d-runtime.js');
        if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
            require('src/physics.js');
        }
        require('jsb-adapter/engine/index.js');
    }
    else {
        require('src/settings.js');
        require('src/cocos2d-jsb.js');
        if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
            require('src/physics.js');
        }
        require('jsb-adapter/jsb-engine.js');
    }

    cc.macro.CLEANUP_IMAGE_CACHE = true;
    window.boot();
}

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/992968.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存