プログラミングとイラストレーション » サウンド|cocos2d-js
プログラミングとイラストレーション > cocos2d > サウンド|cocos2d-js

サウンド|cocos2d-js

サウンド|cocos2d-js

サウンド|cocos2d-js: デモ

サウンド|cocos2d-js : ZIPファイル(934kb)

1.HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <meta name="full-screen" content="yes"/>
  <meta name="screen-orientation" content="portrait"/>
  <meta name="x5-fullscreen" content="true"/>
  <meta name="360-fullscreen" content="true"/>
  <style>
    body, canvas, div{
      -moz-user-select:none;
      -webkit-user-select:none;
      -ms-user-select:none;
      -khtml-user-select:none;
      -webkit-tap-highlight-color:rgba(0,0,0,0);
    }
  </style>
</head>
<body style="padding:0; margin:0; background:#000;">
<canvas id="gameCanvas"></canvas>
<script src="cocos2d-js-v3.11.js"></script>
<script cocos src="main.js"></script>
</body>
</html>

2.JavaScript

main.js

cc.game.onStart = function(){
	if(!cc.sys.isNative && document.getElementById("cocosLoading"))
		document.body.removeChild(document.getElementById("cocosLoading"));

		

	cc.view.enableRetina(false);
	cc.view.adjustViewPort(true);
	cc.view.setDesignResolutionSize(320, 480, cc.ResolutionPolicy.SHOW_ALL);
	cc.view.resizeWithBrowserSize(true);
	cc.LoaderScene.preload(g_resources, function(){
		cc.director.runScene(new gameScene());
	}, this);
	
};
cc.game.run();

app.js



var gameScene = cc.Scene.extend({
	onEnter:function(){
		this._super();
		//cc.log("my awesome game starts here");
		gameLayer = new game();
		gameLayer.init();
		this.addChild(gameLayer);
	}
});

var game = cc.Layer.extend({
	init:function(){
		this._super();
		this.audioEngine = cc.audioEngine;

		var playSoundMenu = new cc.MenuItemFont.create("Play Sound effect", this.playSound, this);
		playSoundMenu.setPosition(new cc.Point(0,350));

		var playBGMusicMenu = new cc.MenuItemFont.create("Play BG music", this.playBGMusic, this);
		playBGMusicMenu.setPosition(new cc.Point(0,300));

		var stopBGMusicMenu = new cc.MenuItemFont.create("Stop BG music", this.stopBGMusic, this);
		stopBGMusicMenu.setPosition(new cc.Point(0,250));

		var musicUpMenu = new cc.MenuItemFont.create("Music volume Up", this.musicUp, this);
		musicUpMenu.setPosition(new cc.Point(0, 200));

		var musicDownMenu = new cc.MenuItemFont.create("Music volume Down", this.musicDown, this);
		musicDownMenu.setPosition(new cc.Point(0,150));

		var effectsUpMenu = new cc.MenuItemFont.create("Effects volume Up", this.effectsUp, this);
		effectsUpMenu.setPosition(new cc.Point(0,100));

		var effectsDownMenu = new cc.MenuItemFont.create("Effects volume Down", this.effectsDown, this);
		effectsDownMenu.setPosition(new cc.Point(0,50));

		var menu = cc.Menu.create(playSoundMenu, playBGMusicMenu, stopBGMusicMenu, musicUpMenu, musicDownMenu, effectsUpMenu, effectsDownMenu);
		menu.setPosition(new cc.Point(160, 40));
		this.addChild(menu);
	},

	playSound:function(){
		this.audioEngine.playEffect(res.bang_mp3);
	},

	playBGMusic:function(){
		if(!this.audioEngine.isMusicPlaying()){
			this.audioEngine.playMusic(res.loop_mp3, true);
		}
	},

	stopBGMusic:function(){
		if(this.audioEngine.isMusicPlaying()){
			this.audioEngine.stopMusic();
		}
	},

	musicUp:function(){
		this.audioEngine.setMusicVolume(this.audioEngine.getMusicVolume()+0.1);
	},

	musicDown:function(){
		this.audioEngine.setMusicVolume(this.audioEngine.getMusicVolume()-0.1);
	},

	effectsUp:function(){
		this.audioEngine.setEffectsVolume(this.audioEngine.getEffectsVolume()+0.1);
	},

	effectsDown:function(){
		this.audioEngine.setEffectsVolume(this.audioEngine.getEffectsVolume()-0.1);
	}
});

resource.js

var res = {
	bang_mp3:"res/bang.mp3",
	loop_mp3:"res/loop.mp3"
};

var g_resources = [];
for(var i in res){
	g_resources.push(res[i]);
}

project.json

{
    "debugMode"     : 1,
    "showFPS"		:false,
    "frameRate"     : 60,
    "id"            : "gameCanvas",
    "renderMode"    : 1,
    "jsList"        : ["app.js", "resource.js"]
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

コメントフィード

トラックバック URL : http://www.htmlcode.jp/%e3%82%b5%e3%82%a6%e3%83%b3%e3%83%89%ef%bd%9ccocos2d-js/trackback/