I want to determine more than two fingers in enchant.js.

Asked 1 years ago, Updated 1 years ago, 33 views


in enchant.js If you draw a line with touch, the object moves over it,
I would like to realize that

You can succeed with just one finger, but
If you have more than one finger, they are all recognized as the same line.
Objects move different lines, and it doesn't work.

I thought it would be the fastest way to avoid drawing lines with more than two fingers.
enchant.Event
I don't know how to do it because there are no such events under my control.
If anyone knows how to recognize two or more fingers, please let me know.

The code is extracted only from the required parts.
Thank you for your cooperation.


enchant();

window.onload=function(){
    game=newGame(STAGE_WIDTH,STAGE_HEIGHT);
    game.fps = FRAME;
    game.preload(
        CHARA_0_IMG
    );
    game.rootScene.backgroundColor="white";

    game.onload=function(){
        varscene=new GamePlayScene();

        // touch start
        game.rootScene.on('touchstart', function(e){
            drawFlg = true;
        });

        // touch move
        game.rootScene.on('touchmove', function(e){
            if(drawFlg===true) {// When it can be described
                createCircle(e.x, e.y);
            }
        });

        // touch end
        game.rootScene.on('touchend', function(e){
            drawFlg = false;
            // description number of notes
            drawNo++;
        });
    }
    game.start();
}

// a description of a circle
function createCircle(x,y){
    varball = new Sprite(10,10);
    var texture = new Surface(10,10);
    var context = texture.context;
    context.fillStyle="green";
    context.strokeStyle="green";

    context.lineWidth = 2;
    context.arc(5,5,4,0, Math.PI*2, false);
    context.fill();
    context.stroke();

    ball.image=texture;
    ball.moveBy(x,y);
    ball.destroy=false;

    game.rootScene.addChild(ball);

    if(!circleList[drawNo]){
        circuitList [drawNo] = [ ];
    }
    circuitList [drawNo].push(ball);
    drawList [drawNo] = false;

    ball.addEventListener(Event.ENTER_FRAME, function(){
        if(ball.destroy===true){
            game.rootScene.removeChild(ball);
        }
    });
}

javascript

2022-09-30 19:53

1 Answers

There seems to be no method for multi-touching in entchant.js.
Here article seems to be using forceful methods to achieve multi-touch.
The original specification cannot recognize more than one finger at the same time, so it is almost impossible to judge.

I also searched the plug-in, but I couldn't find it.

You may be able to make a decision by combining hammer.js and enchant.js, even though it is out of the framework of enchant.js.

To get the number of fingers touched by hammer.js, it appears that you can see the number of elements in the touches property of event data across the callback of the event listener.


2022-09-30 19:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.