2014-09-29 1 views
0

캔버스에 선을 그리려면이 코드가 필요하다고 생각했지만 그렇지 않은 것 같습니다. 내가 잘못했거나하지 않았던 것에 대한 조언을 얻을 수 있습니까?pixi.dart로 캔버스로 그리지 않는 라인

import 'dart:html'; 
import 'package:pixi/pixi.dart'; 

class BunnyExample 
{ 
    CanvasRenderer renderer = new CanvasRenderer(width: 400, height: 300); 
    Stage stage  = new Stage(new Colour.fromHtml('#ffffff')); 
    Graphics graph = new Graphics(); 

    BunnyExample() 
    { 
     document.body.append(this.renderer.view); 
     window.requestAnimationFrame(_lineAnim); 
    } 

    void _lineAnim(var num) 
    { 
     window.requestAnimationFrame(this._lineAnim); 
     graph 
     ..position = new Point(0, 0) 
     ..pivot = new Point(50, 50) 
     ..lineStyle(1,new Colour(255, 0, 0)) 
     ..beginFill(new Colour(255,0,0)) 
     ..lineTo(50, 70) 
     ..endFill(); 
     stage.children.add(graph); 
     renderer.render(stage); 
    } 
} 

void main() 
{ 
    new BunnyExample(); 
} 

답변

0

당신이 전화를해야 할 것 같다 moveTo()lineTo() 전에 : 또한

void _lineAnim(var num) 
{ 
    window.requestAnimationFrame(this._lineAnim); 
    graph 
    ..position = new Point(0, 0) 
    ..pivot = new Point(50, 50) 
    ..lineStyle(1,new Colour(255, 0, 0)) 
    ..beginFill(new Colour(255,0,0)) 
    ..moveTo(50, 50) 
    ..lineTo(50, 70) 
    ..endFill(); 
    renderer.render(stage); 
} 

, 생성자에서 무대를 설정하는 것이 좋습니다, 또는 당신은 메모리 누수가있을 수 있습니다 :

BunnyExample() 
{ 
    stage.children.add(graph); //doing this in the animation loop leads to a memory leak 
    document.body.append(this.renderer.view); 
    window.requestAnimationFrame(_lineAnim); 
} 
+0

을 조언을 주셔서 감사합니다 ... 0,0에서 시작하는 것이 기본값이 아니라 오히려 null이며 코드가 손상되지 않습니다? 아니면 무슨 일이야? :/ –

+0

아, 0,0으로 이동하여 50,50으로 그렸을 때 그려진 것도 볼 수 없었습니다 ... 캔버스 외부의 기원은 무엇입니까? o.O –

+0

'position'과'pivot' 속성을 지우면 0,0에서 50,50까지 줄을 그릴 수 있습니다. 그러나 그 이유를 설명 할 수는 없습니다. 나는이 라이브러리의 전문가가 아니며, 왜 코드가 작동하지 않는지 알아 내기 위해 디버그했다. – luizmineo

관련 문제