2017-09-05 5 views
1

Mon code est très simple, levé directement à partir du tutoriel. Voici index.html:Les événements de la souris Paper.js ne fonctionnent pas

<!DOCTYPE html> 
<html> 
<head> 
<!-- Load the Paper.js library --> 
<script type="text/javascript" src="js/paper-full.js"></script> 
<!-- Load external PaperScript and associate it with myCanvas --> 
<script type="text/paperscript" canvas="myCanvas" src="js/myScript.js"></script> 
</head> 
<body> 
    <canvas id="myCanvas" resize></canvas> 
</body> 
</html> 

et voici js/MyScript.js:

var myPath = new Path(); 
myPath.strokeColor = 'black'; 

myPath.add(new Point(200, 200)); 
myPath.add(new Point(100, 100)); 

function onMouseDown(event) { 
    console.log('You pressed the mouse!'); 
} 

function onMouseDrag(event) { 
    console.log('You dragged the mouse!'); 
} 

function onMouseUp(event) { 
    console.log('You released the mouse!'); 
} 

J'utilise v0.11.4 de paper.js. Le chemin apparaît correctement sur l'écran, mais la console est vide lorsque je clique autour. Est-ce que je mets mal quelque chose? S'il vous plaît, faites-moi savoir. Je vous remercie!

Répondre

0

Vous pouvez lire les didacticiels paper.js, en particulier using javascript directly > working with tools:

paper.install(window); 
window.onload = function() { 
    paper.setup('myCanvas'); 
    // Create a simple drawing tool: 
    var tool = new Tool(); 
    var path; 

    // Define a mousedown and mousedrag handler 
    tool.onMouseDown = function(event) { 
     path = new Path(); 
     path.strokeColor = 'black'; 
     path.add(event.point); 
    } 

    tool.onMouseDrag = function(event) { 
     path.add(event.point); 
    } 
}