Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed generate texture to sprite.js to ES6 format #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 45 additions & 48 deletions public/src/game objects/graphics/generate texture to sprite.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
var config = {
type: Phaser.CANVAS,
parent: 'phaser-example',
scene: {
preload: preload,
create: create,
update: update
},
width: 800,
height: 600
};

var game = new Phaser.Game(config);
var starGraphics;

function preload ()
class Example extends Phaser.Scene
{
}
function create() {
starGraphics = this.make.graphics({x: 0, y: 0, add: false});
drawStar(starGraphics, 105, 105, 5, 100, 50, 0xFFFF00, 0xFF0000);
starGraphics.generateTexture('starGraphics', 210, 210);
image = this.add.image(400, 300, 'starGraphics');
}

function update() {
constructor ()
{
super();
this.starGraphics = undefined;
}

}
create() {
this.starGraphics = this.make.graphics({x: 0, y: 0, add: false});
this.drawStar(this.starGraphics, 105, 105, 5, 100, 50, 0xFFFF00, 0xFF0000);
this.starGraphics.generateTexture('starGraphics', 210, 210);
this.add.image(400, 300, 'starGraphics');
}

function drawStar (graphics, cx, cy, spikes, outerRadius, innerRadius, color, lineColor) {
var rot = Math.PI / 2 * 3;
var x = cx;
var y = cy;
var step = Math.PI / spikes;
graphics.lineStyle(10, lineColor, 1.0);
graphics.fillStyle(color, 1.0);
graphics.beginPath();
graphics.moveTo(cx, cy - outerRadius);
for (i = 0; i < spikes; i++) {
x = cx + Math.cos(rot) * outerRadius;
y = cy + Math.sin(rot) * outerRadius;
graphics.lineTo(x, y);
rot += step;
drawStar (graphics, cx, cy, spikes, outerRadius, innerRadius, color, lineColor) {
let rot = Math.PI / 2 * 3;
let x = cx;
let y = cy;
let step = Math.PI / spikes;
graphics.lineStyle(10, lineColor, 1.0);
graphics.fillStyle(color, 1.0);
graphics.beginPath();
graphics.moveTo(cx, cy - outerRadius);
for (let i = 0; i < spikes; i++) {
x = cx + Math.cos(rot) * outerRadius;
y = cy + Math.sin(rot) * outerRadius;
graphics.lineTo(x, y);
rot += step;

x = cx + Math.cos(rot) * innerRadius;
y = cy + Math.sin(rot) * innerRadius;
graphics.lineTo(x, y);
rot += step;
x = cx + Math.cos(rot) * innerRadius;
y = cy + Math.sin(rot) * innerRadius;
graphics.lineTo(x, y);
rot += step;
}
graphics.lineTo(cx, cy - outerRadius);
graphics.closePath();
graphics.fillPath();
graphics.strokePath();
}
graphics.lineTo(cx, cy - outerRadius);
graphics.closePath();
graphics.fillPath();
graphics.strokePath();
}

const config = {
type: Phaser.CANVAS,
parent: 'phaser-example',
scene: [Example],
width: 800,
height: 600
};

const game = new Phaser.Game(config);