ユーザ用ツール

サイト用ツール

サイドバー

About

Contents

Materials Link

その他

PR


wiki:enchant.js:tips:008

008 タッチイベント

概要

タッチイベントを検知します。ログの出力確認にはChromeを使用しています。

ソースコード

// main.js
enchant();
window.onload = preloadAssets;
 
var game;
var scene;
 
function preloadAssets()
{
	game = new Game(320,480);
	game.onload = init;
 
	game.start();
}
 
function init()
{
	game.scale = 1;
	game.fps = 30;
	scene = new Scene();
	scene.backgroundColor = "#000";
	game.pushScene(scene);
 
	main();
}
 
function main()
{
	// タッチイベントを登録。
	scene.addEventListener(Event.TOUCH_START,touchStart);
	scene.addEventListener(Event.TOUCH_MOVE,touchMove);
	scene.addEventListener(Event.TOUCH_END,touchEnd);
}
 
// タッチ開始.
function touchStart(e)
{
	console.log(e.type);
}
 
// タッチ中.
function touchMove(e)
{
	console.log(e.type);
}
 
// タッチ終了.
function touchEnd(e)
{
	console.log(e.type);
}

console.log() でログが出力出来ます。仮対応やデバッグ用に重宝します。

ダウンロード

Permalink wiki/enchant.js/tips/008.txt · 最終更新: 2014/11/07 09:29 (外部編集)

oeffentlich