mirror of
https://github.com/wassname/phaser.git
synced 2026-08-14 12:40:17 +08:00
Fixed Camera FX: Mirror and Scanlines and updated the tests.
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../build/phaser-fx.d.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
// Just set the world to be the size of the image we're loading in
|
||||
myGame.world.setSize(1216, 896);
|
||||
myGame.loader.addImageFile('backdrop', 'assets/pics/ninja-masters2.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var mirror;
|
||||
function create() {
|
||||
// What we need is a camera 800x400 pixels in size as the mirror effect will be 200px tall and sit below it.
|
||||
// So we resize our default camera to 400px
|
||||
myGame.camera.height = 400;
|
||||
// Because it's our default camera we need to tell it to disable clipping, otherwise we'll never see the mirror effect render.
|
||||
myGame.camera.disableClipping = true;
|
||||
// Add our effect to the camera
|
||||
mirror = myGame.camera.fx.add(Phaser.FX.Camera.Mirror);
|
||||
// The first 2 parameters are the x and y coordinates of where to display the effect. They are in STAGE coordinates, not World.
|
||||
// The next is a Quad making up the rectangular region of the Camera that we'll create the effect from (in this case the whole camera).
|
||||
// Finally we set the fill color that is put over the top of the mirror effect.
|
||||
mirror.start(0, 400, new Phaser.Quad(0, 0, 800, 400), 'rgba(0, 0, 100, 0.7)');
|
||||
// Experiment with variations on these to see the different mirror effects that can be achieved.
|
||||
//mirror.flipX = true;
|
||||
//mirror.flipY = true;
|
||||
myGame.add.sprite(0, 0, 'backdrop');
|
||||
}
|
||||
function update() {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.scroll.x -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -1,68 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../build/phaser-fx.d.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
// Just set the world to be the size of the image we're loading in
|
||||
myGame.world.setSize(1216, 896);
|
||||
|
||||
myGame.loader.addImageFile('backdrop', 'assets/pics/ninja-masters2.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var mirror: Phaser.FX.Camera.Mirror;
|
||||
|
||||
function create() {
|
||||
|
||||
// What we need is a camera 800x400 pixels in size as the mirror effect will be 200px tall and sit below it.
|
||||
// So we resize our default camera to 400px
|
||||
myGame.camera.height = 400;
|
||||
|
||||
// Because it's our default camera we need to tell it to disable clipping, otherwise we'll never see the mirror effect render.
|
||||
myGame.camera.disableClipping = true;
|
||||
|
||||
// Add our effect to the camera
|
||||
mirror = <Phaser.FX.Camera.Mirror> myGame.camera.fx.add(Phaser.FX.Camera.Mirror);
|
||||
|
||||
// The first 2 parameters are the x and y coordinates of where to display the effect. They are in STAGE coordinates, not World.
|
||||
// The next is a Quad making up the rectangular region of the Camera that we'll create the effect from (in this case the whole camera).
|
||||
// Finally we set the fill color that is put over the top of the mirror effect.
|
||||
mirror.start(0, 400, new Phaser.Quad(0, 0, 800, 400), 'rgba(0, 0, 100, 0.7)');
|
||||
|
||||
// Experiment with variations on these to see the different mirror effects that can be achieved.
|
||||
//mirror.flipX = true;
|
||||
//mirror.flipY = true;
|
||||
|
||||
myGame.add.sprite(0, 0, 'backdrop');
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.scroll.x -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.scroll.y -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -1,32 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../build/phaser-fx.d.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(1216, 896);
|
||||
myGame.loader.addImageFile('backdrop', 'assets/pics/ninja-masters2.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scanlines;
|
||||
function create() {
|
||||
// Add our effect to the camera
|
||||
scanlines = myGame.camera.fx.add(Phaser.FX.Camera.Scanlines);
|
||||
// We'll have the scanlines spaced out every 2 pixels
|
||||
scanlines.spacing = 2;
|
||||
// This is the color the lines will be drawn in
|
||||
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
||||
myGame.add.sprite(0, 0, 'backdrop');
|
||||
}
|
||||
function update() {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.scroll.x -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -1,57 +0,0 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../build/phaser-fx.d.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.world.setSize(1216, 896);
|
||||
|
||||
myGame.loader.addImageFile('backdrop', 'assets/pics/ninja-masters2.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scanlines: Phaser.FX.Camera.Scanlines;
|
||||
|
||||
function create() {
|
||||
|
||||
// Add our effect to the camera
|
||||
scanlines = <Phaser.FX.Camera.Scanlines> myGame.camera.fx.add(Phaser.FX.Camera.Scanlines);
|
||||
|
||||
// We'll have the scanlines spaced out every 2 pixels
|
||||
scanlines.spacing = 2;
|
||||
|
||||
// This is the color the lines will be drawn in
|
||||
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
||||
|
||||
myGame.add.sprite(0, 0, 'backdrop');
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.scroll.x -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.scroll.y -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user