¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

JavaScript/tmlib.js

Last-modified: 2018-11-14 (¿å) 15:23:54 (2153d)
Top / JavaScript / tmlib.js

¼¡¤Î¥¤¥Ù¥ó¥È¤Ë»²²Ã¤·¤Æ¿§¡¹¶µ¤¨¤Æ¤¤¤¿¤À¤­¤Þ¤·¤¿¡£
¡ÚTechBuzz¡Ûtmlib.js hackthon #1 ¡ÁJavaScript ¤ò¤è¤ê»È¤¤¤ä¤¹¤¯, ¤è¤êÊØÍø¤Ë, ¤½¤·¤Æ¤è¤êË­¤«¤Ë¤ò¥â¥Ã¥È¡¼¤È¤¹¤ë¡Ötmlib.js¡×¤Î¥Ï¥Ã¥«¥½¥ó¥¤¥Ù¥ó¥È³«ºÅ¡Á
¥¹¥é¥¤¥É¥·¥ç¡¼


tmlib.js¤È¤ÏPC/iPhone/Android¤Ê¤É¤Î¥Ö¥é¥¦¥¶¤ÇÆ°¤¯web¥¢¥×¥ê¤ò³«È¯¤Ç¤­¤ëJavaScript¥é¥¤¥Ö¥é¥ê¤Ç¤¹¡£ ¤â¤Á¤í¤ó¥Æ¥­¥¹¥È¥¨¥Ç¥£¥¿¤ÈFTP¥½¥Õ¥È¤È¤«¤Ç³«È¯¤Ç¤­¤ë¤Î¤Ç¤¹¤¬¡¢º£²ó¤Ïjsdo.it¤È¤¤¤¦¥Ö¥é¥¦¥¶¾å¤Çhtml/css/JavaScript¤Ê¤É¤Î³«È¯¤¬¹Ô¤¨¤ëweb¥µ¡¼¥Ó¥¹¤Ç³«È¯¤·¤Þ¤·¤¿¡£ ¤³¤Á¤é¤¬Ìܤ«¤é¥¦¥í¥³¤Ç¤·¤Æ¡¢¼¡¤Î¤è¤¦¤Ê¼ê½ç¤Ç´Êñ¤Ë³«È¯¤Ç¤­¤Þ¤·¤¿¡£

  1. twitter, facebook¤Ê¤É¤Çjsdo.it¤Ë¥í¥°¥¤¥ó
  2. ¼«Ê¬ÍѤΥե©¥ë¥À̾¤òÆþ¤ì¤ë(»ä¤Ïpapuujp)
  3. Start coding¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢ºÇÄã¸Â¤Îindex.html, index.js, style.css¤¬¥µ¡¼¥Ð¾å¤Çºî¤é¤ì¡¢¥Ö¥é¥¦¥¶¤ÇÊÔ½¸²Äǽ¤È¤Ê¤ë
  4. +¥Ü¥¿¥ó¤Ç»È¤¤¤¿¤¤JavaScript¥é¥¤¥Ö¥é¥ê(jQuery Mobile, tmlib.js, enchant.js¤Ê¤É)¤òÄɲ乤ë
  5. index.js¤Ëºî¤ê¤¿¤¤¥³¡¼¥É¤ò½ñ¤¤¤Æ¡¢command + s(mac)¤äcontrol + s(windows)¤ÇÊݸ¤¹¤ë¤È¡¢¥×¥ì¥Ó¥å¡¼¥¦¥£¥ó¥É¥¦¤Çɽ¼¨¤µ¤ì¤ë

jsdo.it¤Î²¿¤¬¤¤¤¤¤«¤È¤¤¤¦¤È¡¢FTP¤Ç¥¢¥Ã¥×¤·¤Ê¤¯¤Æ¤â¥µ¡¼¥Ð¾å¤Ç¤¹¤°¤Ë¸ø³«¤µ¤ì¤¿¾õÂ֤ǻ¤ë¤³¤È¤Ç¤¹¡£ Î㤨¤Ðº£²óºî¤Ã¤¿¥µ¥ó¥×¥ë¤Ï¤³¤Á¤é¤È¤Ê¤ê¤Þ¤¹¡£¥Þ¥¦¥¹¤ä¥¹¥Þ¥Û¾å¤Î»Ø¥¹¥é¥¤¥É¤Ç¼«µ¡¤òº¸±¦¤ËÆ°¤«¤·¡¢À±¤òÈò¤±¤ë¥²¡¼¥à¤Ç¤¹¡£
http://jsrun.it/papuujp/star-game2
¥½¡¼¥¹¤â¸ø³«¤Ç¤­¤Æ¡¢¤³¤Á¤é¤È¤Ê¤ê¤Þ¤¹¡£Èó¸ø³«¤È¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡£
http://jsdo.it/papuujp/star-game2
jsdo.it¤ò»È¤¦¤ÈiPad¤Ç¤âweb¥¢¥×¥ê³«È¯¤¬¹Ô¤Ê¤¨¤Þ¤¹¤·¡¢JavaScript¤äjQuery Mobile¤Ê¤É¤Î¼Â½¬·Á¼°¤ÎÊÙ¶¯²ñ¤È¤«¤Ç¤â¼ê·Ú¤Ë»È¤¨¤½¤¦¤Ç¤¹¡£
¡Ê¥Ç¥Ð¥Ã¥°µ¡Ç½¤¬¼å¤¤¤Î¤Ç¡¢¤½¤Á¤é¤ÏGoogle Chrome Developer¥Ä¡¼¥ë¤ò°ì½ï¤Ë³«¤±¤Ð¤¤¤¤¤È¤¤¤¦¤³¤È¤â¶µ¤¨¤Æ¤¤¤¿¤À¤­¤Þ¤·¤¿¡£¤È¤Æ¤âÊØÍø¤Ç¤·¤¿¡Ë

tmlib.js¼«¿È¤Ï¼¡¤Î¤è¤¦¤Ë¿§¡¹¤Ê²ÄǽÀ­¤ò´¶¤¸¤Þ¤·¤¿¡£

  • ¼ê·Ú¤Ë»î¤»¤ë
  • ¥¢¥Ë¥á¡¼¥·¥ç¥ó¤È¤«¤¬ÆÀ°Õ
  • ¥¹¥Þ¥Û¥¿¥Ã¥Á¤äPC¤Ç¤Î¥Þ¥¦¥¹Áàºî¤Î°ã¤¤¤òµÛ¼ý¤·¤ÆξÂбþ¤Îweb¥¢¥×¥ê¤òºî¤ì¤ë
  • AppStore¤È¤«¤Ë¸ø³«¤·¤Ê¤¤¤Ç¤â¤¹¤°¤Ë¥ê¥Ã¥Á¤Êweb¥¢¥×¥ê¤ò¸ø³«¤Ç¤­¤ë
  • facebook¥¢¥×¥ê¤âºî¤ì¤½¤¦
  • Titanium Mobile¤ÎWebView¤ËÆþ¤ì¤Æ¡¢²èÌÌɽ¼¨¤ò¥ê¥Ã¥Á¤Ë»È¤¨¤½¤¦


tmlib¤Ç²¿¤¬ºî¤ì¤ë¤«¤Ï¡¢¥Ô¥ó¤­¤ê¤Ç¤¹¤¬¼¡¤Ç¤ª»î¤·¤¯¤À¤µ¤¤¡£
http://jsdo.it/search?q=tmlib

¥ª¥¹¥¹¥á¤Î¥Á¥å¡¼¥È¥ê¥¢¥ë

phi»á¼«¿È¤Î¥Á¥å¡¼¥È¥ê¥¢¥ë¤¬¤È¤Æ¤âʬ¤«¤ê¤ä¤¹¤¯¤Æ¥ª¥¹¥¹¥á¤Ç¤¹¡£¤Þ¤¿²þ¤¤µ¤ì¤¿Êý¤Î¥²¡¼¥à¤â»²¹Í¤Ë¤Ê¤ê¤Þ¤¹¡£


¤³¤Á¤é¤Îtmlib.js¤òÍѤ¤¤¿¥·¥å¡¼¥Æ¥£¥ó¥°¥²¡¼¥àºîÀ®¹ÖºÂÆ°²è¤â°ì¤«¤é¥³¡¼¥É¤ò½ñ¤¤¤Æ¤¤¤Æʬ¤«¤ê¤ä¤¹¤¤¤Ç¤¹¡£


¤³¤Á¤é¤Î¥Á¥å¡¼¥È¥ê¥¢¥ë¤â¥ª¥¹¥¹¥á¤Ç¤¹¡£¥Í¡¼¥à¥¹¥Ú¡¼¥¹¤ò¶èÀڤäƤ¤¤Æ¹Ôµ·¤¬¤¤¤¤¥³¡¼¥É¤ß¤¿¤¤¤Ç¤¹¡£¤¿¤À¤·¥·¡¼¥ó¤ÎÄêµÁ¤Ï¿ô»ú¥¿¥Ã¥Á¥²¡¼¥à¥µ¥ó¥×¥ë¤Î¤è¤¦¤Ë¡Ötm.define()¡×¤ò»È¤Ã¤¿Êý¤¬¿·¤·¤¤¤è¤¦¤Ç¤¹¡£¾Ü¤·¤¤°ã¤¤¤Ï¤è¤¯Ê¬¤«¤ê¤Þ¤»¤ó¡£

¥¯¥é¥¹¤Ë¤Ä¤¤¤Æ

ºÇ½é¡Ötm.createClass()¡×¤Çºî¤Ã¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡Ötm.define()¡×¤ò»È¤¦¤Î¤¬¤¤¤¤¤½¤¦¤Ç¤¹¡£


¥Í¡¼¥à¥¹¥Ú¡¼¥¹¡Ê̾Á°¶õ´Ö¡Ë¤ò¤­¤Ã¤Á¤ê¤Èʬ¤±¤Æ¥¯¥é¥¹ÄêµÁ¤¹¤ëÊýË¡¤Ï¼¡¤Î¥µ¥ó¥×¥ë¤¬Ê¬¤«¤ê¤ä¤¹¤«¤Ã¤¿¤Ç¤¹¡£¤¿¤À¤·¥é¥¤¥Ö¥é¥ê³«È¯¤Ç¤Ê¤¯¥¢¥×¥ê³«È¯¤Î¾ì¹ç¤Ï¡¢¥Í¡¼¥à¥¹¥Ú¡¼¥¹¤òʬ¤±¤Ê¤¤Êý¤¬¥½¡¼¥¹¤¬¸«¤ä¤¹¤¯¤Æ¤¤¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£


¼¡¤Î¤è¤¦¤ËÁ´ÂΤò¨¼Â¹Ô´Ø¿ô¤È¤·¤Æ¾¤Î¥é¥¤¥Ö¥é¥ê¤«¤é¸«¤¨¤Ê¤¯¤¹¤ë¤Î¤¬Ê¬¤«¤ê¤ä¤¹¤¯¤ÆÎɤµ¤½¤¦¤Ç¤¹¡£¡Ê»²¹Í¤È¤·¤¿¥½¡¼¥¹ ²þ¤ tmlib ¿ô»ú¥²¡¼¥à¡Ë

(function TouchTheNumber() {
	// screen 
	var SCREEN_WIDTH    = 680;
	var SCREEN_HEIGHT   = 960;
	...
	... tm.main()¤ä³Æ¥·¡¼¥ó¤ÎÄêµÁ
	...
})();

¥¢¥Ë¥á¡¼¥·¥ç¥ó¤Ë¤Ä¤¤¤Æ

tm.app.Tweener

tm.app.Tweener¤òÍѤ¤¤ë¤ÈÁêÂÐŪ¤Ê»þ´Ö¼´¤Ç¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òÀѤ߽ŤͤÆɽ¸½¤Ç¤­¤Þ¤¹¡£°ú¿ô¤Ê¤É¾Ü¤·¤¯¤Ï¥½¡¼¥¹¤ò¸«¤ë¤Î¤¬Îɤµ¤½¤¦¤Ç¤¹¡£

tm.app.Timeline

tm.app.Timeline¤òÍѤ¤¤ë¤ÈÀäÂÐŪ¤Ê»þ´Ö¼´¤Ç¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òɽ¸½¤Ç¤­¤Þ¤¹¡£°ú¿ô¤Ê¤É¾Ü¤·¤¯¤Ï¥½¡¼¥¹¤ò¸«¤ë¤Î¤¬Îɤµ¤½¤¦¤Ç¤¹¡£

tm.app.Timeline¤Î¼ç¤Ê¥á¥½¥Ã¥É

  • clear: ¤½¤ì¤Þ¤Ç¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤ò¥¯¥ê¥¢
  • set: ¥¢¥Ë¥á¡¼¥·¥ç¥ó̵¤·¤Ç»ØÄꤷ¤¿ÃͤËÀßÄê
  • to: »ØÄꤷ¤¿Ãͤޤǥ¢¥Ë¥á¡¼¥·¥ç¥ó
  • by: ­¤·¤¿Ãͤޤǥ¢¥Ë¥á¡¼¥·¥ç¥ó

to, by¤½¤ì¤¾¤ì¤Î°ú¿ô

  • props: Ìܻؤ¹Ãͤޤ¿¤Ï­¤¹Ãͤò{}¤Ëµ­½Ò x, y, scaleX, scaleY, alpha
  • duration: ¥¢¥Ë¥á¡¼¥·¥ç¥ó»þ´Ö¤ò»ØÄê¡Ê¥ß¥êÉáË
  • delay: ¥¢¥Ë¥á¡¼¥·¥ç¥ó³«»Ï»þ´Ö¤ò»ØÄê¡Ê¥ß¥êÉáË
  • fn: "easeOutExpo"¤È¤¤¤Ã¤¿¥¢¥Ë¥á¡¼¥·¥ç¥ó¤Î¤«¤±Êý¡Ê¥¤¡¼¥¸¥ó¥°¡Ë¤ò»ØÄê

¥¤¡¼¥¸¥ó¥°

"easeOutExpo"¤È¤¤¤Ã¤¿¥¢¥Ë¥á¡¼¥·¥ç¥ó¤Î¤«¤±Êý¤Ç¤¹¡£

¥¹¥Ë¥Ú¥Ã¥È

¥á¥¤¥ó½èÍý

// main ½èÍý
tm.main(function() {
    alert("tmlib.js ¤Á¤ã¤ó¤È»È¤¨¤Æ¤ë¤è¡Á¤ó¢ö");
});

¥¯¥é¥¹ÄêµÁ

var Hoge = tm.createClass({
    init: function(num) {
        this.num = num;
    },
    toString: function() {
        return "»ä¤Î¿ôÃͤÏ{num}¤Ç¤¹!!".format(this);
    }
});
var hoge = Hoge(128);
document.write(hoge.toString());
document.write("<br />");

¥¨¥Í¥ß¡¼¥¯¥é¥¹ÄêµÁ

ÇÛÎóÊÑ¿ôenemyList¤ò»È¤Ã¤¿Å¨½èÍý¤¬ÊÙ¶¯¤Ë¤Ê¤Ã¤¿¤Î¤Ç¥½¡¼¥¹°ìÉô¤ò°úÍѤ·¤Þ¤·¤¿¡£¼¡¤ÎÅÀ¤ËÃí°Õ¤·¤Æ¸«¤ë¤ÈÊÙ¶¯¤Ë¤Ê¤ê¤Þ¤¹¡£

  • enemyList¤ò½é´ü²½¤¹¤ë°ÌÃÖ ... ¥á¥¤¥ó¥·¡¼¥ó¤Î½é´ü²½½èÍý
  • enemyList¤ÎÃæ¤ËÆþ¤ì¤ëEnemy¥¯¥é¥¹¤ÎÄêµÁÊýË¡
  • Enemy¥¤¥ó¥¹¥¿¥ó¥¹¤ÎÀ¸À®¡¢¥·¡¼¥ó¤ª¤è¤ÓenemyList¤Ø¤ÎÄɲÃ
  • Enemy¥¤¥ó¥¹¥¿¥ó¥¹¤Î¥·¡¼¥ó¤ª¤è¤ÓenemyList¤«¤é¤Îºï½ü ¥·¥å¡¼¥Æ¥£¥ó¥°¥²¡¼¥à¤ÎÁ´¥³¡¼¥É¤ÏJavaScript/tmlib.js/sample/Èò¤±¥²¡¼(³«»Ï, ½ªÎ»²èÌ̤¢¤ê)¤Ë°úÍѤµ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤Þ¤¹¡£¥ª¥ê¥¸¥Ê¥ë¤Ï¤³¤Á¤é¤Ç¤¹¡£

#pre{{
/*
* ¥°¥í¡¼¥Ð¥ëÊÑ¿ô
*/
var enemyList = null;

/*
* ¥¨¥Í¥ß¡¼
*/
var Enemy = tm.createClass({
superClass: tm.app.StarShape,
// ½é´ü²½
init: function() {
this.superInit(PLAYER_SIZE, PLAYER_SIZE);
},
// ¹¹¿·
update: function(app) {
this.y += 8; // °ÜÆ°
this.rotation += 15; // ²óž
// ºï½üȽÄê
if (this.y > SCREEN_HEIGHT) {
this.remove();
enemyList.erase(this);
}
}
});

// ¥á¥¤¥ó¥·¡¼¥ó
var MainScene = tm.createClass({
superClass: tm.app.Scene,
init: function() {
this.superInit();

enemyList = [];

// ¥×¥ì¥¤¥ä¡¼
this.player = Player();
this.addChild(this.player);
this.player.x = SCREEN_CENTER_X;
this.player.y = SCREEN_HEIGHT-100;
},

update: function() {
// ¥¨¥Í¥ß¡¼À¸À®
if (app.frame % 8 == 0) {
// ¥¨¥Í¥ß¡¼
var enemy = Enemy();
enemy.x = tm.util.Random.randint(0, SCREEN_WIDTH);
enemy.y = -50;
this.addChild(enemy); // ¥·¡¼¥ó¤ËÄɲÃ
enemyList.push(enemy); // ¥ê¥¹¥È¤ËÄɲÃ
}

// ¥×¥ì¥¤¥ä¡¼, ¥¨¥Í¥ß¡¼¾×ÆÍȽÄê
for (var i=0,len=enemyList.length; i<len; ++i) {
var enemy = enemyList[i];
// ¾×ÆÍȽÄê
if (this.player.isHitElement(enemy)) {
// Game Over
app.replaceScene(ResultScene());
}
}
}
});
}}

¥ê¥ó¥¯