我試圖訪問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