1
我想寫一個使用PIXI.js繪製圓圈的類。使用Pixi.js v4和Typerscript繪製圓圈(IONIC 2)
這是我home.ts類
import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { CanvasAnimations } from '../../canvas/Canvas'
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
canvas = new CanvasAnimations();
@ViewChild('canvasWrapper') MyCanvas:ElementRef;
@ViewChild('homeContent') HomeContent:ElementRef;
constructor(public navCtrl: NavController) {}
ionViewDidLoad() {
this.canvas.setCanvas(this.MyCanvas, window.innerWidth, window.innerHeight);
this.canvas.generateCircle();
}
}
這是我CanvasAnimations類
import { ElementRef } from '@angular/core';
import * as PIXI from 'pixi.js';
export class CanvasAnimations {
// Class Properties
stage = new PIXI.Container();
constructor() { }
setCanvas(canvasElement: ElementRef, windowWidth: number, windowHeight: number) {
var renderer = PIXI.autoDetectRenderer(windowWidth, windowHeight, { backgroundColor: 0x00FF00, antialias: true });
canvasElement.nativeElement.appendChild(renderer.view);
renderer.render(this.stage);
}
generateCircle() {
var circle = new PIXI.Graphics();
circle.beginFill(0x000000);
circle.drawCircle(0, 0, 100);
circle.endFill();
circle.x = 100;
circle.y = 130;
this.stage.addChild(circle);
}
}
但是我可以看到畫布渲染,但不是一個圓,我不明白爲什麼.. 有什麼建議麼?