Programing

ϡenchant.jsϤȤɬפʡŪʥΤޤȤǤ

enchant.js°ΥץΥ󥲡(\examples\action)ȥ塼ƥ󥰥(\examples\shooting)ʤɤɤƤޤ

enchant.jsϡץ뤿Υ饤֥ץǤ(२󥸥Ȥ)

HTML5JavascriptȤѤǺƤơѥʤޡȥե䥿֥åȤˤбǤޤ

ǤϡĥɤʣˤƤäơޤ륲ޤ

⤦餷

1176_140.gif

ɬפʥե

enchant.js顢ΥեФޤ

޲(bear.gif)ϡɤƤޤ

  • enchant.jsenchant.js
  • game.jsΥᥤץ
  • index.htmlᥤץƤӽФHTMLե롣֥饦dz
  • bear.gif:ե
bear.gif

index.html

¹Ԥˤϡ index.html֥륯å顢ᥤץǤgame.js䡢饤֥Ǥenchant.jsƤӽФƤޤ

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no"> 
        <meta name="apple-mobile-web-app-capable" content="yes"> 
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <title>Sample Game</title>
        <script type="text/javascript" src="enchant.js"></script>
        <script type="text/javascript" src="game.js"></script>
        <style type="text/css">
            body {
                margin: 0;
            }
        </style>
    </head>
    <body>
    </body>
</html>

game.jsδܥ

ΥᥤץǤgame.jsδŪʹ֤ˤߤƤޤ

⤷ʤ

줬ܷե(bear.gif)ɤ߹Ǥ뤱ɽϤʤ

ΥƥȤgame.jsȤƥȥեȤ¸롣ơindex.htmlƤӽФȡץ¹ԡ

enchant();

window.onload = function() {
	var game = new Game(320, 320); 	//̤
	game.preload('bear.gif');	//եɤ߹

	game.onload = function() {
		//{פȡ}פδ֤ˡư򵭽Ҥ
	}
	game.start();
}

򤿤ɽ

ҤΥե񤭴ơץ饤ȵǽ(Sprite)Dzɽ롣

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      	bear.image = game.assets['bear.gif'];

		game.rootScene.addChild(bear);
	}
	game.start();
}

ɽѤ

ʣΥ᡼äƤξ硢ץ饤Ȥ̤Υ᡼ɽ롣

ޤ⤤Ƥ륢˥᡼ʤɤ˻Ȥޤ(ޤ⤭ޤ)

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      	bear.image = game.assets['bear.gif'];
		bear.frame = 1;

		game.rootScene.addChild(bear);
	}
	game.start();
}

ɽ֤

ץ饤Ȥΰ֤

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      	bear.image = game.assets['bear.gif'];
		bear.x = 150;
		bear.y = 150;
		bear.frame = 1;

		game.rootScene.addChild(bear);
	}
	game.start();
}

ϤDzڤؤ

򲡤ơڤؤ

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      		bear.image = game.assets['bear.gif'];

      		bear.addEventListener('enterframe', function() {
			bear.x = 150;
			bear.y = 150;
			if(game.input.left) bear.frame = 1;
			if(game.input.right) bear.frame = 2;
		});
		game.rootScene.addChild(bear);
	}
	game.start();
}

˥᡼

ǡξ

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      		bear.image = game.assets['bear.gif'];

      		bear.addEventListener('enterframe', function() {
			bear.x = 150;
			bear.y = 150;
			if(game.input.right) {
				if(bear.frame == 1) {
					bear.frame = 2;
				} else {
					bear.frame = 1;
				}
			}
			if(game.input.left) {
				if(bear.frame == 4) {
					bear.frame = 5;
				} else {
					bear.frame = 4;
				}
			}
		});
		game.rootScene.addChild(bear);
	}
	game.start();
}

˥᡼

롣ɤ̵롣

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      		bear.image = game.assets['bear.gif'];

      		bear.addEventListener('enterframe', function() {
			bear.y = 150;
			if(game.input.right) {
				if(bear.frame == 1) {
					bear.frame = 2;
				} else {
					bear.frame = 1;
				}
				bear.x += 5;	
			}
			if(game.input.left) {
				if(bear.frame == 4) {
					bear.frame = 5;
				} else {
					bear.frame = 4;
				}
				bear.x -= 5;	
			}
		});
		game.rootScene.addChild(bear);
	}
	game.start();
}

˥᡼

롣ɤǻߤޤ롣

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload('bear.gif');

	game.onload = function() {
		var bear = new Sprite(20, 30);
      		bear.image = game.assets['bear.gif'];

      		bear.addEventListener('enterframe', function() {
			bear.y = 150;
			if(game.input.right) {
				if(bear.frame == 1) {
					bear.frame = 2;
				} else {
					bear.frame = 1;
				}
				if (bear.x < 300) {
					bear.x += 5;
				} else {
					bear.x = 300;
				}
			}
			if(game.input.left) {
				if(bear.frame == 4) {
					bear.frame = 5;
				} else {
					bear.frame = 4;
				}
				if (bear.x > 0) {
					bear.x -= 5;
				} else {
					bear.x = 0;
				}
			}
		});
		game.rootScene.addChild(bear);
	}
	game.start();
}

ץ

ޤǤǴե

ʸɽ

̾ʸɽˤϡ٥뵡ǽ(Label)Ȥޤ

̾˸ʸɽ

Running Bear:פȤʸɽ

enchant();

window.onload = function() {
	var game = new Game(320, 320);

	var label = new Label("Running Bear:");
	label.x = 0;
	label.y = 0;
	game.rootScene.addChild(label);

	game.start();
}

ʸ񤭴

ǤϤʤɽƤʸѲ

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload("bear.gif");

	var label = new Label("Running Bear:");
	label.x = 0;
	label.y = 0;
	game.rootScene.addChild(label);
	
	game.onload = function() {
		var label_time = new Label();
		label_time.x = 0;
		label_time.y = 14;
		
      		label_time.addEventListener('enterframe', function() {
			label_time.text = game.frame;
		});
		game.rootScene.addChild(label_time);
	}
	game.start();
}

˥᡼ʸɽ

ޤꡢв֤ɽޤ

˥᡼Υԡɤgame.fps = 15;פĴƤޤ

enchant();

window.onload = function() {
	var game = new Game(320, 320);
	game.preload("bear.gif");
	game.fps = 15;

	var label = new Label("Running Bear:");
	label.x = 0;
	label.y = 0;
	game.rootScene.addChild(label);
	
	game.onload = function() {
		//٥ʸɽ
		var label_time = new Label();
		label_time.x = 0;
		label_time.y = 14;
				
      	label_time.addEventListener('enterframe', function() {
			label_time.text = game.frame;
		});
		game.rootScene.addChild(label_time);

		//ץ饤Ȥǥɽ
		var bear = new Sprite(20, 30);
      	bear.image = game.assets['bear.gif'];
		
		bear.addEventListener('enterframe', function() {
			if(bear.frame == 1) {
				bear.frame = 2;
			} else {
				bear.frame = 1;
			}
			
			bear.x += 5
			if (bear.x > 300) {
					bear.x = 0;
			}
			bear.y = 50;
		});
		game.rootScene.addChild(bear);
	}
	game.start();
}

ץ

ޤǤǴե

̲Ф

˸̲ĤȡڤǤ

ȤˤФ

ɥե()ɤ߹ǡ.playפǺޤ

enchant();

window.onload = function() {
    var game = new Game(320, 320);
    game.preload('jump.wav');
    game.onload = function() {
	    var sound = game.assets['jump.wav'].play();
	    sound.play();
    };
    game.start();
};

ˤ碌ƲФ

ɽΤȤˡȤ߹ߤޤ

̲եɤ߹ʤơ٤ϫޤenchant.jsΥС󤬸ŤȤޤʤޤ

enchant();

window.onload = function() {
    var game = new Game(320, 320);
    game.preload('jump.wav', 'bear.gif');
    game.onload = function() {
	    game.assets['jump.wav'].play();
		
		var bear = new Sprite(20, 30);
      	bear.image = game.assets['bear.gif'];
		
		bear.addEventListener('enterframe', function() {
			if(game.input.right) {
				var sound = game.assets['jump.wav'].clone();
				sound.play();
			}
		});
		game.rootScene.addChild(bear);
    };
    game.start();
};

ץ

ޤǤǴե

ʲ

ץϡĤʤȤ߹碌Ȥƺȡ䤹ʤޤ

ʲ

KumaȤ(֥)player1player2˳ƤƤޤ ҤȤĤ߷׿(Kuma)顢ʣʤФƤޤʤϡƬʸʸˤޤϡʸǽ񤤤Ƥޤ

enchant();

var Kuma = enchant.Class.create(enchant.Sprite, {
    initialize: function(x, y){
        enchant.Sprite.call(this, 20, 30);
        this.image = game.assets['bear.gif'];
        this.x = x; this.y = y; this.frame = 0;
        game.rootScene.addChild(this);
    }
});

window.onload = function() {
    game = new Game(320, 320); 
    game.preload('bear.gif');
    game.onload = function() {
	player1 = new Kuma(0, 0);
	player1.frame = 1;
	player2 = new Kuma(30, 0);
	player2.frame = 2;
    }
    game.start();
}

ʲư

ʤǤϡʤ߷׿¦ưǤޤǤϡKumaʤˡmove_rightmove_leftƤޤơᥤʬǡ줿˹碌ơmove_rightmove_leftƤӽФƤޤ

enchant();

var Kuma = enchant.Class.create(enchant.Sprite, {
    initialize: function(x, y){
        enchant.Sprite.call(this, 20, 30);
        this.image = game.assets['bear.gif'];
        this.x = x; this.y = y; this.frame = 0;
        game.rootScene.addChild(this);
    },
	move_right: function() {
		this.x += 5;
	},
	move_left: function() {
		this.x -= 5;
	}
});

window.onload = function() {
    game = new Game(320, 320); 
    game.preload('bear.gif');
    game.onload = function() {
		player = new Kuma(0, 0);
		
		game.addEventListener('enterframe', function() {
			if(game.input.right) {
				player.move_right();
			}
			if(game.input.left) {
				player.move_left();
			}
		});
    }
    game.start();
}

ʲΥ˥᡼

äĤƤߤϤθФϡ¦˰ưǡ¦Ϥäꡣ ϺĤǤ롣

enchant();
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 320;

var Kuma = enchant.Class.create(enchant.Sprite, {
    initialize: function(x, y){
		this.KUMA_WIDTH = 20;
		this.KUMA_HEIGHT = 30;
		this.KUMA_Y = 50;
		this.dir = 0;		//ʹ 0:(right)1:(left)
		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
		this.step = 5;
		
		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
		this.image = game.assets['bear.gif'];
		this.x = x;
		this.y = this.KUMA_Y;
		this.frame = 0;

		this.addEventListener('enterframe', function() {
			if(game.input.right) {
				this.move_right();
			} else if(game.input.left) {
				this.move_left();
			} else {
				this.move_stop();
			}
			this.change_frame();
		});
		game.rootScene.addChild(this);
	},
	move_right: function() {
		this.dir = 0;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
			this.x += this.step;
		} else {
			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
		}
	},
	move_left: function() {
		this.dir = 1;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x > 0) {
			this.x -= this.step;
		} else {
			this.x = 0;
		}
	},
	move_stop: function(){
		if(this.walk !== 0) {
			game.assets['jump.wav'].play();
		}
		this.walk = 0;
	},
	change_frame: function() {
		this.frame = this.dir * 3 + this.walk;
	}
});

window.onload = function() {
	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
	game.preload('jump.wav', 'bear.gif');
	game.onload = function() {
		player = new Kuma(0, 0);
	}
	game.start();
}

ޤǤǴե

ʣΥѡĤư

󥲡ǤϡʣŨ䥿åȤо줷ޤȤСФǤȤ١ȤäǤ¸뤿ˤϡ̤ΥѡĤʣо줵ơƱưɬפޤ

ʣβɽ

ޤʣβɽˡҤȤĤʲɽƤߤޤ礦ϡۤɤΥʲˡȤۤȤƱǡAppleȤʤ夫ߤäƤޤAppleϡ1ɽޤäƤΤϡβʤõǤ褦ˤƤȤ(remove)Ǥ

enchant();
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 320;

var Apple = enchant.Class.create(enchant.Sprite, {
	initialize: function(x, y){
		this.WIDTH = 16;
		this.HEIGHT = 16;
		this.STEP = 5;
		
		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
		this.image = game.assets['icon0.gif'];
		this.x = x;
		this.y = y;
		this.frame = 15;
		this.addEventListener('enterframe', function(){
			this.move_step();
		});
		game.rootScene.addChild(this);
	},
	move_step: function() {
		this.y += this.STEP;
		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
			this.remove();
		}
	},
	remove: function(){
		game.rootScene.removeChild(this);
	}
});

window.onload = function() {
	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
	game.fps = 15;
	game.preload('icon0.gif');
	game.onload = function() {
		target = new Apple(100, 0);
	}
	game.start();
}

ʣβư

¤ʣư褦ˤȡʤޤʣApple夫ߤäƤޤʤʬϡۤɤƱǤ¦ʣAppleβƤޤ

enchant();
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 320;

var Apple = enchant.Class.create(enchant.Sprite, {
	initialize: function(x, y){
		this.WIDTH = 16;
		this.HEIGHT = 16;
		this.STEP = 5;
		
		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
		this.image = game.assets['icon0.gif'];
		this.x = x;
		this.y = y;
		this.frame = 15;
		this.addEventListener('enterframe', function(){
			this.move_step();
		});
		game.rootScene.addChild(this);
	},
	move_step: function() {
		this.y += this.STEP;
		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
			this.remove();
		}
	},
	remove: function(){
		game.rootScene.removeChild(this);
	}
});

window.onload = function() {
	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
	game.fps = 15;
	game.preload('icon0.gif');
	game.onload = function() {
		targets = [];
		game.rootScene.addEventListener('enterframe', function(){
 			if((game.frame % 10) == 0){
				var x = Math.floor(Math.random() * 300);
				targets[game.frame] = new Apple(x, 0);
			}
		});
	}
	game.start();
}

ޤǤǴե

ˡ̣դäȡ餷ʤäƤޤ͡

(ĤǤ)ŨƱɽ

ĤǤ뼫ȡŨƱɽȡʤޤ

enchant();
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 320;

//ĤǤ뼫
var Kuma = enchant.Class.create(enchant.Sprite, {
    initialize: function(x, y){
		this.KUMA_WIDTH = 20;
		this.KUMA_HEIGHT = 30;
		this.KUMA_Y = 200;
		this.dir = 0;		//ʹ 0:(right)1:(left)
		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
		this.step = 5;
		
		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
		this.image = game.assets['bear.gif'];
		this.x = x;
		this.y = this.KUMA_Y;
		this.frame = 0;

		this.addEventListener('enterframe', function() {
			if(game.input.right) {
				this.move_right();
			} else if(game.input.left) {
				this.move_left();
			} else {
				this.move_stop();
			}
			this.change_frame();
		});
		game.rootScene.addChild(this);
	},
	move_right: function() {
		this.dir = 0;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
			this.x += this.step;
		} else {
			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
		}
	},
	move_left: function() {
		this.dir = 1;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x > 0) {
			this.x -= this.step;
		} else {
			this.x = 0;
		}
	},
	move_stop: function(){
		if(this.walk !== 0) {
			game.assets['jump.wav'].play();
		}
		this.walk = 0;
	},
	change_frame: function() {
		this.frame = this.dir * 3 + this.walk;
	}
});

//ʣɽꥭ
var Apple = enchant.Class.create(enchant.Sprite, {
	initialize: function(x, y){
		this.WIDTH = 16;
		this.HEIGHT = 16;
		this.STEP = 5;
		
		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
		this.image = game.assets['icon0.gif'];
		this.x = x;
		this.y = y;
		this.frame = 15;
		this.addEventListener('enterframe', function(){
			this.move_step();
		});
		game.rootScene.addChild(this);
	},
	move_step: function() {
		this.y += this.STEP;
		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
			this.remove();
		}
	},
	remove: function(){
		game.rootScene.removeChild(this);
	}
});

window.onload = function() {
	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
	game.fps = 15;
	game.preload('bear.gif', 'icon0.gif', 'jump.wav');
	game.onload = function() {
		player = new Kuma(0, 0);
		targets = [];
		game.rootScene.addEventListener('enterframe', function(){
 			if((game.frame % 10) == 0){
				var x = Math.floor(Math.random() * 300);
				targets[game.frame] = new Apple(x, 0);
			}
		});
	}
	game.start();
}

ޤǤǴե

Ƚդäȡäݤʤޤ͡

Ƚ

ꥭ餬ܿɤȽԤޤȽϡɽ뤿ʤǤ륹ץ饤(Sprite)Ƚ̿(intersect)Ȥޤ(Apple)ưȤ󥯥ޤȤȽԤäơäƤ顢оݤΥ󥴤õ̲Ĥ餷ޤ

enchant();
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 320;
score = 0;

//ĤǤ뼫
var Kuma = enchant.Class.create(enchant.Sprite, {
    initialize: function(x, y){
		this.KUMA_WIDTH = 20;
		this.KUMA_HEIGHT = 30;
		this.KUMA_Y = 200;
		this.dir = 0;		//ʹ 0:(right)1:(left)
		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
		this.step = 5;
		
		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
		this.image = game.assets['bear.gif'];
		this.x = x;
		this.y = this.KUMA_Y;
		this.frame = 0;

		this.addEventListener('enterframe', function() {
			if(game.input.right) {
				this.move_right();
			} else if(game.input.left) {
				this.move_left();
			} else {
				this.move_stop();
			}
			this.change_frame();
		});
		game.rootScene.addChild(this);
	},
	move_right: function() {
		this.dir = 0;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
			this.x += this.step;
		} else {
			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
		}
	},
	move_left: function() {
		this.dir = 1;
		if((this.walk == 0) || (this.walk == 2)){
			this.walk = 1;
		} else if(this.walk == 1) {
			this.walk = 2;
		}
		if (this.x > 0) {
			this.x -= this.step;
		} else {
			this.x = 0;
		}
	},
	move_stop: function(){
		this.walk = 0;
	},
	change_frame: function() {
		this.frame = this.dir * 3 + this.walk;
	}
});

//ʣɽꥭ
var Apple = enchant.Class.create(enchant.Sprite, {
	initialize: function(x, y){
		this.WIDTH = 16;
		this.HEIGHT = 16;
		this.STEP = 5;
		
		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
		this.image = game.assets['icon0.gif'];
		this.x = x;
		this.y = y;
		this.frame = 15;
		this.addEventListener('enterframe', function(){
			this.move_step();
		});
		game.rootScene.addChild(this);
	},
	move_step: function() {
		this.y += this.STEP;

		//Ƚ
		if(this.intersect(player)){
			this.remove();
			game.assets['jump.wav'].play();
		}
		//üã
		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
			this.remove();
		}
	},
	remove: function(){
		game.rootScene.removeChild(this);
	}
});

window.onload = function() {
	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
	game.fps = 15;
	game.preload('bear.gif', 'icon0.gif', 'jump.wav');
	game.onload = function() {
		player = new Kuma(0, 0);
		targets = [];
		game.rootScene.addEventListener('enterframe', function(){
 			if((game.frame % 10) == 0){
				var x = Math.floor(Math.random() * 300);
				targets[game.frame] = new Apple(x, 0);
			}
		});
	}
	game.start();
}

ޤǤǴե

ʥץ饰

enchant.jsϡץ饰(plugin)ǵǽĥǤޤ

Ȥ⡢ץ饰ѤȺȸΨ夬ޤ

⻲ͤˤʤޤ

ץ饰λȤ

ץ饰ϡenchant.jsƱեľpluginsեȤǤ礦

enchant.jsषϡԤˤʤäƤޤ

줫顢ץ饰ɬפȤƱեѰդޤ

  • nineleap.enchant.jsξ
    • start.png
    • end.png
    • font.png
  • ui.enchant.jsξ
    • apad.png
    • pad.png

Ȥϡindex.html˥ץ饰եεҤɲäޤ

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no"> 
        <meta name="apple-mobile-web-app-capable" content="yes"> 
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <title>enchant</title>
        <script type="text/javascript" src="enchant.js"></script>
        <script type="text/javascript" src="plugins/nineleap.enchant.js"></script>
        <script type="text/javascript" src="plugins/util.enchant.js"></script>
        <script type="text/javascript" src="plugins/ui.enchant.js"></script>
        <script type="text/javascript" src="game.js"></script>
        <style type="text/css">
            body {margin: 0;}
        </style>
    </head>
    <body>
    </body>
</html>

嵭Ǥϡ10-11ܤpluginsեˤץ饰ե(nineleap.enchant.jsutil.enchant.js)ꤷƤޤץ饰ϡץ(:game.js)˵Ҥޤ

Ȳ

nineleap.enchant.jsɤ߹ȡॹȻ˼ưŪ˥ѥåɽޤ

λ

nineleap.enchant.jsɤ߹ߡཪλ٤Ȥ˲Υɤ񤭤ޤ

game.end(game.score, "game end");

game.scoreϡǼѿ

ɽ

ץ(game.onload = function()ΤȤ)ˡΥɤ񤭤ޤȡ֤Ƥ(ȥå)ˤʤޤ

timeLabel = new TimeLabel(8, 8);
game.rootScene.addChild(timeLabel);

Τ褦˽񤯤ȥȥ

timeLabel = new TimeLabel(8, 8, "countdown");
timeLabel.time = 30;
game.rootScene.addChild(timeLabel);

ɽ٥ѹˤ

timeLabel.label = "LIFE:";

ߤηв֤Фˤϡ

A = timeLabel.label;

ɽ

ץΤνʬ(window.onload = function() )ˡΥɤ񤭤ޤ줬ˤʤޤ

game.score = 0; //ν

ץ(game.onload = function()ΤȤ)ˡΥɤ񤭤ޤ줬ɽ

scoreLabel = new ScoreLabel(40, 8);
game.rootScene.addChild(scoreLabel);

ɲåɤȤơΥɤ񤭤ޤ

game.score += 10;

ɽ٥ѹˤ

scoreLabel.label = "APPLE:";

(ɽ)

Ũ㳲ʪʤɤХХɽ뤳ȤɽȤޤ͡ΥɽˤϡȤޤȤϡȤ110ޤǤο򼡡Ŭ˺ФˡǤutil.enchant.jsץ饰Ȥȡ򼡤Τ褦˴ñ˰ޤ

A = rand(10); //

åѥåб

ޡȥեʤɤΥåѥåбˤˤϡΥɤɲäޤǡؤޥǡƱ褦˥Ǥޤ

var pad = new Pad();
pad.x = 0;
pad.y = 220;
game.rootScene.addChild(pad);

pad.xpad.yǡѥѥåɤɽ֤ꡣ

ץ

  • ץץ¹Ԥ
  • 30ô֤ǡǤ󥴤򽸤Ƥ
  • ǡޤޤ
  • νꥢȤȡޥå(ѥ)å(ޡȥե)ǤǤޤ

ޤǤǴե

̤Ť͹碌

ʣʥ̤ɽȤϡŤ͹碌褦˺Ǥ

enchant.jsǤϡΤ褦˽Ť̤ͤ򥷡(Scene)ȸƤӤޤ

9leapǸ

9leapϡenchant.jsȤäƥȡƤ줿ϡѥǤ⥹ޡȥեǤͷ٤ޤ

󤹤ȥơȤƤǽˤʤۤ
Ʊǥץ쥤TwitterǥեƤͤξϥɽޤ
򤪵ɲäơ夫ͷ֤ȤǤޤ

9leap˥󤹤ˤϡTwitterȤɬפǤ

ˡ

ϡ餬ͤˤʤޤ

9leapƤƤߤ

طʡޥåפɽ

Ȥ饯ǤϤӤΤǡطʤɽƤߤޤ

طʤˤϡطʿꤹˡȲꤹˡޤ

طʿλ

طʿꤹˤϡΤ褦˥(game.rootScene)طʿ(backgroundColor)RGBꤷޤ

game.rootScene.backgroundColor = 'rgb(182, 255, 255)';

طʲɽ

طʲɽˤϡޤطʤθˤʤǺѰդޤϡΤ褦93ޥǺ(map2.gif)Ȥޤ

map2.gif

93ޥβϡΤ褦ֹƤޤ

 0, 1, 2, 3, 4, 5, 6, 7, 8
 9,10,11,12,13,14,15,16,17
18,19,20,21,22,23,24,25,26

ˡβɤΤ褦ˤʤ٤뤫ͤǻꤷޤ

Ǻ֤Ȥˤϡֹꤷޤ ʤˤʤȤϡ-1פꤷޤ

ϡ20ޥ10ޥβطʤȤɽޤ

var blocks = [
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
	[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4],
	[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],
];

ºݤ֤ˤϡΤ褦ˤޤ

  • game.preload('bear.gif', 'map2.gif'); Ǻɤ߹
  • Υɤطʤ
var map = new Map(16, 16);
map.image = game.assets['map2.gif'];
map.loadData(blocks);
  • game.rootScene.addChild(map); ǡǸϿ

ץ

ޤǤǴե

nakamura001 ץ뽸

ޤǡenchant.jsΥץäƤ顢ΥȤˤɤޤȤޤäƤΤȯȥǥˤɤ夯Τݤ˴ޤǡ󥯤Ƥޤ

  • 饯򱦤˰ư ǥ
  • 饯ǰư ǥ
  • ư(饯βȿž)
  • åפ֤˥饯ư ǥ
  • ٥ɽ ǥ
  • Ƚ(饤֥Υ᥽åɤȤ鷺˼Ƚ) ǥ
  • Ƚ(饤֥Υ᥽åɤȽ) ǥ
  • 饯˥᡼ˡ
  • 饯ɲˡ
  • ֤ΰư
  • 쥤䡼طθ饯ɲˡ
  • ʪʪꤲˡ

git


  ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS
Last-modified: 2013-03-01 () 12:47:21 (4071d)