I'm writing a basic application in dart that uses canvas, it basically has 2 squares one of them move from right to left of screen and the second move when the user presse Arrow keys.
Now the problem is that When i try it in Dartium it works fine. But if i try to open it in Chrome/Firefox, i can see only an empty rectangle.
Dart editor doesn't show any error, even when i compile it as javascript code.
But when i look into console of Inspect element of Chrome there is that error message:
Uncaught TypeError: Object [object Window] has no method 'webkitRequestAnimationFrame$1'
The calls to that method are here:
void main() {
var maincharacter = new Player(10,10, 70, 70, "red");
var secondCharacter = new Player(400,250, 50,50, "yellow");
player = maincharacter;
sprites = new Set();
randomnumbergenerator = new Random();
window.on.keyDown.add(myKeyDownEvent);
CanvasElement element = query("canvas");
context = element.context2d;
maincharacter.context = context;
secondCharacter.context = context;
maincharacter.type = 'player';
sprites.add(maincharacter);
sprites.add(secondCharacter);
window.webkitRequestAnimationFrame(animate);
}
And here:
void animate(num time){
enemyCreator(time);
context.clearRect(0,0,400,400);
for(final sprite in sprites){
if(!sprite.isPlayer()) {
sprite.move(5, 0);
// sprite.isOutside(0);
if(!(sprite.posx<0)){
query('#text').text = " Posx: ${sprite.posx.toString()} Length: ${sprites.length}";
sprite.draw();
} else {
query('#text').text = "Destroyed";
sprites.remove(sprite);
}
} else {
sprite.draw();
query('#text').text = " Time: $counter Length: ${sprites.length}";
}
}
window.webkitRequestAnimationFrame(animate);
}
This is the javascript line that throws the exception:
$.window().webkitRequestAnimationFrame$1($.animate)
Any idea?
The method is called requestAnimationFrame()
not webkitRequestAnimationFrame()
in Dart: http://api.dartlang.org/docs/bleeding_edge/dart_html/LocalWindow.html#requestAnimationFrame
int requestAnimationFrame(RequestAnimationFrameCallback callback)
As John said, try:
window.requestAnimationFrame(animate);
You probably confused Dart's method with the "native" DOM method
Window.prototype.webkitRequestAnimationFrame
in Dart you do not specify that prefix.