mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
working paralax (not for zoom)
This commit is contained in:
parent
357ef181d9
commit
85867f92af
10 changed files with 117 additions and 15 deletions
|
|
@ -90,7 +90,11 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
|
||||||
|
|
||||||
Level.prototype.setupLayer = function(options, behind, referenceId) {
|
Level.prototype.setupLayer = function(options, behind, referenceId) {
|
||||||
Parent.prototype.setupLayer.call(this, options, behind, referenceId);
|
Parent.prototype.setupLayer.call(this, options, behind, referenceId);
|
||||||
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, behind, referenceId);
|
var parallaxSpeed = 0.0;
|
||||||
|
if (options.properties && options.properties.parallaxSpeed) {
|
||||||
|
parallaxSpeed = parseFloat(options.properties.parallaxSpeed);
|
||||||
|
}
|
||||||
|
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, parallaxSpeed, behind, referenceId);
|
||||||
};
|
};
|
||||||
|
|
||||||
return Level;
|
return Level;
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,19 @@ function (Parent, Settings, Nc) {
|
||||||
pivot: {
|
pivot: {
|
||||||
x: mesh.texture.width / 2,
|
x: mesh.texture.width / 2,
|
||||||
y: mesh.texture.height / 2
|
y: mesh.texture.height / 2
|
||||||
}
|
},
|
||||||
|
xScale: 1,
|
||||||
|
yScale: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Nc.trigger(Nc.ns.client.view.mesh.create,
|
Nc.trigger(Nc.ns.client.view.mesh.create,
|
||||||
options.layerId,
|
options.layerId,
|
||||||
texturePath,
|
texturePath,
|
||||||
callback
|
callback,
|
||||||
|
{
|
||||||
|
alpha: options.opacity
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,17 @@ define([
|
||||||
|
|
||||||
function (Abstract) {
|
function (Abstract) {
|
||||||
|
|
||||||
function Layer(name, z, parallaxSpeed) {
|
function Layer(name, parallaxSpeed) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parallaxSpeed = parallaxSpeed;
|
this.parallaxSpeed = parallaxSpeed;
|
||||||
|
this.zoom = {
|
||||||
|
current: 1,
|
||||||
|
target: 1
|
||||||
|
};
|
||||||
|
this.position = {
|
||||||
|
current: { x: 0, y: 0},
|
||||||
|
target: { x: 0, y: 0}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(Layer, 'ID', {
|
Object.defineProperty(Layer, 'ID', {
|
||||||
|
|
@ -24,10 +32,20 @@ function (Abstract) {
|
||||||
Abstract.prototype.addMethod.call(Layer, 'addMesh', ['mesh']);
|
Abstract.prototype.addMethod.call(Layer, 'addMesh', ['mesh']);
|
||||||
Abstract.prototype.addMethod.call(Layer, 'removeMesh', ['mesh']);
|
Abstract.prototype.addMethod.call(Layer, 'removeMesh', ['mesh']);
|
||||||
Abstract.prototype.addMethod.call(Layer, 'updateMesh', ['mesh', 'options']);
|
Abstract.prototype.addMethod.call(Layer, 'updateMesh', ['mesh', 'options']);
|
||||||
|
Abstract.prototype.addMethod.call(Layer, 'render', ['centerPosition']);
|
||||||
|
|
||||||
Layer.prototype.getName = function() {
|
Layer.prototype.getName = function() {
|
||||||
return this.name;
|
return this.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Layer.prototype.setPosition = function(centerPosition) {
|
||||||
|
this.position.target.x = centerPosition.x;
|
||||||
|
this.position.target.y = centerPosition.y;
|
||||||
|
};
|
||||||
|
|
||||||
|
Layer.prototype.setZoom = function(z) {
|
||||||
|
this.zoom.target = z;
|
||||||
|
};
|
||||||
|
|
||||||
return Layer;
|
return Layer;
|
||||||
});
|
});
|
||||||
|
|
@ -64,7 +64,7 @@ function (Abstract, DomController, Settings, Exception, Nc) {
|
||||||
AbstractView.prototype.setMe = function(player) {
|
AbstractView.prototype.setMe = function(player) {
|
||||||
this.me = player;
|
this.me = player;
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
AbstractView.prototype.calculateCameraPosition = function() {
|
AbstractView.prototype.calculateCameraPosition = function() {
|
||||||
var reference = this.me.getPosition();
|
var reference = this.me.getPosition();
|
||||||
var pos = {};
|
var pos = {};
|
||||||
|
|
@ -80,7 +80,7 @@ function (Abstract, DomController, Settings, Exception, Nc) {
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
AbstractView.prototype.onFullscreenChange = function(isFullScreen) {
|
AbstractView.prototype.onFullscreenChange = function(isFullScreen) {
|
||||||
|
|
||||||
if (!isFullScreen) {
|
if (!isFullScreen) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ define([
|
||||||
|
|
||||||
function (Nc, Exception, Layer) {
|
function (Nc, Exception, Layer) {
|
||||||
|
|
||||||
function LayerManager(container) {
|
function LayerManager(container, me) {
|
||||||
this.layers = [];
|
this.layers = [];
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
|
|
@ -21,6 +21,14 @@ function (Nc, Exception, Layer) {
|
||||||
Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this)
|
Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LayerManager.prototype.render = function(centerPosition, zoom) {
|
||||||
|
for (var i = 0; i < this.layers.length; i++) {
|
||||||
|
var layer = this.layers[i];
|
||||||
|
layer.render(centerPosition, zoom);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If no referenceId is given, the layer is inserted in the far background (behind=true)
|
* If no referenceId is given, the layer is inserted in the far background (behind=true)
|
||||||
|
|
@ -87,6 +95,11 @@ function (Nc, Exception, Layer) {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Delegate methods */
|
||||||
|
|
||||||
LayerManager.prototype.delegate = function() {
|
LayerManager.prototype.delegate = function() {
|
||||||
var methodName = arguments[0];
|
var methodName = arguments[0];
|
||||||
var layerId = arguments[1];
|
var layerId = arguments[1];
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ define([
|
||||||
"Game/Client/View/Abstract/Layer",
|
"Game/Client/View/Abstract/Layer",
|
||||||
"Lib/Vendor/Pixi",
|
"Lib/Vendor/Pixi",
|
||||||
"Game/Client/View/Pixi/ColorRangeReplaceFilter",
|
"Game/Client/View/Pixi/ColorRangeReplaceFilter",
|
||||||
|
"Game/Config/Settings",
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, PIXI, ColorRangeReplaceFilter) {
|
function (Parent, PIXI, ColorRangeReplaceFilter, Settings) {
|
||||||
|
|
||||||
var AVAILABLE_MESH_FILTERS = {
|
var AVAILABLE_MESH_FILTERS = {
|
||||||
"blur": PIXI.BlurFilter,
|
"blur": PIXI.BlurFilter,
|
||||||
|
|
@ -151,7 +152,35 @@ function (Parent, PIXI, ColorRangeReplaceFilter) {
|
||||||
mesh.filters = filter;
|
mesh.filters = filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Layer.prototype.render = function(centerPosition, zoom) {
|
||||||
|
this.setPosition(centerPosition);
|
||||||
|
this.setZoom(zoom);
|
||||||
|
|
||||||
|
// Zoom
|
||||||
|
var zoomStep = (this.zoom.target - this.zoom.current) * Settings.CAMERA_GLIDE / 100;
|
||||||
|
this.zoom.current += zoomStep;
|
||||||
|
this.container.scale.x = this.zoom.current;
|
||||||
|
this.container.scale.y = this.container.scale.x;
|
||||||
|
|
||||||
|
// Position
|
||||||
|
var posXStep = (this.position.target.x - this.position.current.x) * Settings.CAMERA_GLIDE / 100;
|
||||||
|
this.position.current.x += posXStep;
|
||||||
|
this.container.x = this.position.current.x + (this.position.current.x * this.parallaxSpeed);
|
||||||
|
|
||||||
|
var posYStep = (this.position.target.y - this.position.current.y) * Settings.CAMERA_GLIDE / 100;
|
||||||
|
this.position.current.y += posYStep;
|
||||||
|
this.container.y = this.position.current.y + (this.position.current.y * this.parallaxSpeed);
|
||||||
|
};
|
||||||
|
|
||||||
return Layer;
|
return Layer;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
1 = this.zoom.current ? -1
|
||||||
|
|
||||||
|
1 = this.zoom.current * (-1) * (-1)
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
|
||||||
|
|
||||||
this.initCamera();
|
this.initCamera();
|
||||||
|
|
||||||
this.layerManager = new LayerManager(this.container);
|
this.layerManager = new LayerManager(this.container, this.me);
|
||||||
|
|
||||||
this.initLoader();
|
this.initLoader();
|
||||||
|
|
||||||
|
|
@ -61,21 +61,35 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
|
||||||
}
|
}
|
||||||
|
|
||||||
PixiView.prototype.render = function () {
|
PixiView.prototype.render = function () {
|
||||||
if(this.me) {
|
if (this.me) {
|
||||||
var pos = this.calculateCameraPosition();
|
this.layerManager.render(this.calculateCenterPosition(), this.currentZoom);
|
||||||
this.setCameraPosition(pos.x, pos.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer.render(this.stage);
|
this.renderer.render(this.stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
|
|
||||||
PixiView.prototype.initCamera = function () {
|
PixiView.prototype.initCamera = function () {
|
||||||
this.container = new PIXI.DisplayObjectContainer();
|
this.container = new PIXI.DisplayObjectContainer();
|
||||||
this.stage.addChild(this.container);
|
this.stage.addChild(this.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PixiView.prototype.calculateCenterPosition = function() {
|
||||||
|
var target = this.me.getHeadPosition();
|
||||||
|
var centerPosition = {x: target.x, y: target.y};
|
||||||
|
centerPosition.x *= -Settings.RATIO * this.currentZoom;
|
||||||
|
centerPosition.y *= -Settings.RATIO * this.currentZoom;
|
||||||
|
|
||||||
|
centerPosition.x += Settings.STAGE_WIDTH / 2;
|
||||||
|
centerPosition.y += Settings.STAGE_HEIGHT / 2;
|
||||||
|
|
||||||
|
centerPosition.x -= this.me.playerController.xyInput.x * Settings.STAGE_WIDTH / 4;
|
||||||
|
centerPosition.y += this.me.playerController.xyInput.y * Settings.STAGE_HEIGHT / 4;
|
||||||
|
|
||||||
|
return centerPosition;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
PixiView.prototype.calculateCameraPosition = function() {
|
PixiView.prototype.calculateCameraPosition = function() {
|
||||||
var targetZoom = this.currentZoom;
|
var targetZoom = this.currentZoom;
|
||||||
|
|
||||||
|
|
@ -115,7 +129,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
PixiView.prototype.setCameraZoom = function (zoom) {
|
PixiView.prototype.setCameraZoom = function (zoom) {
|
||||||
/*
|
/*
|
||||||
var oldZoom = this.container.scale.x;
|
var oldZoom = this.container.scale.x;
|
||||||
|
|
|
||||||
BIN
static/img/Backgrounds/clouds.png
Normal file
BIN
static/img/Backgrounds/clouds.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
BIN
static/img/Backgrounds/starnight-small.png
Normal file
BIN
static/img/Backgrounds/starnight-small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 287 KiB |
|
|
@ -3,9 +3,28 @@
|
||||||
"layers":[
|
"layers":[
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
"image":"..\/..\/img\/Backgrounds\/starnight.png",
|
"image":"..\/..\/img\/Backgrounds\/starnight-small.png",
|
||||||
"name":"background",
|
"name":"background",
|
||||||
"opacity":1,
|
"opacity":1,
|
||||||
|
"properties":
|
||||||
|
{
|
||||||
|
"parallaxSpeed":"-1.0"
|
||||||
|
},
|
||||||
|
"type":"imagelayer",
|
||||||
|
"visible":false,
|
||||||
|
"width":0,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"height":0,
|
||||||
|
"image":"..\/..\/img\/Backgrounds\/clouds.png",
|
||||||
|
"name":"clouds",
|
||||||
|
"opacity":0.3,
|
||||||
|
"properties":
|
||||||
|
{
|
||||||
|
"parallaxSpeed":"-0.3"
|
||||||
|
},
|
||||||
"type":"imagelayer",
|
"type":"imagelayer",
|
||||||
"visible":false,
|
"visible":false,
|
||||||
"width":0,
|
"width":0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue