0
私はJavaScriptキャンバスゲームを作っていますが、デバイス上のタッチスクリーンがタップされているのと同じように押されているかどうかを検出する必要があります。私はそれを拾うために働いているが、それが押されている間にメソッドを呼び出す方法を理解できない。JavaScript処理デバイスのタッチスクリーンが押されている
は、だから私は、イベントhandelersを追加
function addTouchEventHandlers()
{
screen.canvas.addEventListener('touchstart', touchStart);
screen.canvas.addEventListener('touchend', touchEnd);
}
私はタッチスタートとタッチ終了
方法は、単に私のスプライト変更function touchStart(e) {
if (gameStarted) {
// Prevent players from inadvertently
// dragging the game canvas
e.preventDefault();
}};
function touchEnd(e) {
var x = e.changedTouches[0].pageX;
var y = e.changedTouches[0].pageY;
if (gameStarted) {
if (x > screen.width/2)
{
processRightTap();
}
else if (x < screen.width/2 && y < screen.height/2)
{
processTopLeftTap(); <- I want to keep calling this method when held down
}
else if (x < screen.width/2 && y > screen.height/2)
{
processBottomLeftTap(); <- I want to keep calling this method when held down
}
// Prevent players from double
// tapping to zoom into the canvas
e.preventDefault();
}
};
yの位置を持っている
function processBottomLeftTap() {
ship.y += 4;
}
function processTopLeftTap() {
ship.y -= 4;
}
キーボードのメソッドisPressedとisDownに似たものがありますか? またはメソッドの周りにwhileループを作成するにはどうすればよいですか? このようなものです。
while(The screen is being touched at X position)
{
processTopLeftTap();
}