Hello World|cocos2d-js

cocos2d-js Hello World

Hello World|cocos2d-js : デモ

Hello World|cocos2d-js : ZIPファイル(150kb)

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="src/cocos2d-js-v3.11-lite.js"></script>
<script cocos src="src/main.js"></script>
</body>
</html>

3.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.director.runScene(new gameScene());
};
cc.game.run();

project.json

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

app.js

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

var game = cc.Layer.extend({
	init:function(){
		this._super();
		var size = cc.director.getWinSize();
		var label = cc.LabelTTF.create("Hello World", "Arial", 40);
		label.setPosition(size.width / 2, size.height / 2);
		this.addChild(label, 1);
	}
})

コメントを残す

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