我试图访问ProcessingJS片段中的mousePressed属性,但得到undefined
。如何在ProcessingJS中使用mousePressed?
这里是我试过到目前为止:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://cloud.github.com/downloads/processing-js/processing-js/processing-1.4.1.min.js"></script>
<script>
$(document).ready(function() {
$('body').append($('<canvas id="preview"><p>Your browser does not support the canvas tag.</p></canvas>'));
function onPJS(p) {
p.setup = function(){
console.log(p.mousePressed);//prints undefined
try{
console.log(p.mousePressed());
}catch(e){
console.log(e.name,e.message);//prints TypeError Property 'mousePressed' of object [object Object] is not a function
}
}
}
new Processing(document.getElementById("preview"), onPJS);
});
</script>
对我缺少/做错了什么任何线索?
我现在正在使用依靠jquery的hacky解决方法:var mousePressed = false; (“#preview”)。mousedown(function(){\t mousePressed = true; \t}); ()# \t $(“#preview”)。mouseup(function(){\t mousePressed = false; \t});'但是我希望有更好的方法来处理这个PJS只能 – 2013-05-07 09:59:27
你可以把你的代码放在http:/ /jsfiddle.net/ – 2013-05-08 13:44:34
@benoît现在在[jsfiddle](http://jsfiddle.net/orgicus/qb5xp/),这有帮助吗? – 2013-05-08 14:31:39