Coffeescript and animations?

286 views
Skip to first unread message

Stephen Cagle

unread,
Oct 12, 2011, 7:28:30 PM10/12/11
to Paper.js
I have been doing a bit of tinkering with Coffeescript and Paper.js.
No problems until I tried to do animations.
This Coffeescript code,
----------------------------------------------------------------------------------------------------------------------------------------
onFrame = (event) ->
console.log("count:#{event.count} time:#{event.time}
delta:#{event.delta}");
----------------------------------------------------------------------------------------------------------------------------------------

compiles into the following javascript code,
----------------------------------------------------------------------------------------------------------------------------------------
function() {
var onFrame;
onFrame = function(event) {
return console.log("count:" + event.count + " time:" + event.time
+ " delta:" + event.delta);
};
}).call(this);
----------------------------------------------------------------------------------------------------------------------------------------

which gives me a result of... nothing.

I assume onFrame is being detected/discovered in some interesting way.
Some way that Coffeescript has somehow succeeded in hiding from
Paper.js? If this is the case, is there some sort of workaround? Some
way in which I might "manually" inform Paper.js that onFrame is the
animation callback?

Thank you

p.s. In case it matters, I included my html below, the above generated
javascript is the "popper.js" mentioned in the html.
----------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<!-- Load the Paper.js library -->
<script type="text/javascript" src="paper.js"></script>
<script type="text/paperscript" src="popper.js"
canvas="popperCanvas"></script>
<style>
canvas {
width: 1000px;
height: 1000px;
}
</style>
</head>
<body>
<canvas id="popperCanvas"/>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------

Nick

unread,
Oct 12, 2011, 7:31:10 PM10/12/11
to Paper.js
when you're using Javascript directly, you need to call view.onFrame =
function(event){}, instead of just onFrame.

See here:

http://paperjs.org/tutorials/getting-started/using-javascript-directly/
Reply all
Reply to author
Forward
0 new messages