mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added player health action view
This commit is contained in:
parent
c3aee14f23
commit
aa6fdaa2df
8 changed files with 214 additions and 44 deletions
|
|
@ -22,6 +22,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
|
||||
|
||||
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
|
||||
|
||||
NotificationCenter.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
|
||||
NotificationCenter.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
|
||||
NotificationCenter.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
|
||||
}
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
@ -131,5 +135,17 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
throw new Exception('Abstract Function showInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onCreateAndAddPlayerInfo = function(options) {
|
||||
throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
||||
throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onRemovePlayerInfo = function(playerInfo) {
|
||||
throw new Exception('Abstract Function onRemovePlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
return AbstractView;
|
||||
});
|
||||
|
|
@ -43,33 +43,6 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.setCanvas(this.renderer.view);
|
||||
}
|
||||
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
}
|
||||
|
||||
PixiView.prototype.initInfo = function() {
|
||||
this.infoContainer = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.infoContainer);
|
||||
|
||||
var blurFilter = new PIXI.BlurFilter();
|
||||
blurFilter.blurX = 12;
|
||||
blurFilter.blurY = 12;
|
||||
var grayFilter = new PIXI.GrayFilter();
|
||||
grayFilter.gray = 0.85;
|
||||
this.infoFilters = [blurFilter, grayFilter];
|
||||
|
||||
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
|
||||
this.infoBox = new PIXI.Graphics();
|
||||
this.infoBox.alpha = 0.7;
|
||||
|
||||
this.infoContainer.addChild(this.infoBox);
|
||||
this.infoContainer.addChild(this.infoText);
|
||||
|
||||
this.infoContainer.visible = false;
|
||||
};
|
||||
|
||||
PixiView.prototype.render = function () {
|
||||
if(this.me && this.me.isSpawned) {
|
||||
var pos = this.calculateCameraPosition();
|
||||
|
|
@ -79,6 +52,8 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.renderer.render(this.stage);
|
||||
}
|
||||
|
||||
// Meshes
|
||||
|
||||
PixiView.prototype.addMesh = function(mesh) {
|
||||
this.container.addChild(mesh);
|
||||
};
|
||||
|
|
@ -89,9 +64,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
|
||||
PixiView.prototype.createMesh = function (texturePath, callback, options) {
|
||||
|
||||
var texture = PIXI.Texture.fromImage(texturePath, true, PIXI.BaseTexture.SCALE_MODE.NEAREST);
|
||||
//texture.filter = PIXI.BaseTexture.FILTER.LINEAR;
|
||||
console.log(PIXI.BaseTexture);
|
||||
var texture = PIXI.Texture.fromImage(texturePath, false, PIXI.BaseTexture.SCALE_MODE.NEAREST);
|
||||
|
||||
var mesh = new PIXI.Sprite(texture);
|
||||
|
||||
|
|
@ -132,6 +105,13 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y);
|
||||
}
|
||||
|
||||
// Camera
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
}
|
||||
|
||||
PixiView.prototype.calculateCameraPosition = function() {
|
||||
var zoom = this.container.scale.x;
|
||||
|
||||
|
|
@ -170,6 +150,29 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
// Info Overlay
|
||||
|
||||
PixiView.prototype.initInfo = function() {
|
||||
this.infoContainer = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.infoContainer);
|
||||
|
||||
var blurFilter = new PIXI.BlurFilter();
|
||||
blurFilter.blurX = 12;
|
||||
blurFilter.blurY = 12;
|
||||
var grayFilter = new PIXI.GrayFilter();
|
||||
grayFilter.gray = 0.85;
|
||||
this.infoFilters = [blurFilter, grayFilter];
|
||||
|
||||
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
|
||||
this.infoBox = new PIXI.Graphics();
|
||||
this.infoBox.alpha = 0.7;
|
||||
|
||||
this.infoContainer.addChild(this.infoBox);
|
||||
this.infoContainer.addChild(this.infoText);
|
||||
|
||||
this.infoContainer.visible = false;
|
||||
};
|
||||
|
||||
PixiView.prototype.toggleInfo = function(show, string) {
|
||||
if(show) {
|
||||
this.infoText.setText(string);
|
||||
|
|
@ -200,5 +203,47 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
// Player Info
|
||||
|
||||
PixiView.prototype.onCreateAndAddPlayerInfo = function(callback, options) {
|
||||
var playerInfo = new PIXI.Graphics();
|
||||
this.container.addChild(playerInfo);
|
||||
|
||||
this.onUpdatePlayerInfo(playerInfo, options);
|
||||
|
||||
callback(playerInfo);
|
||||
};
|
||||
|
||||
PixiView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
||||
var width = 14,
|
||||
height = 2,
|
||||
borderWidth = 1,
|
||||
offsetX = -8,
|
||||
offsetY = -52;
|
||||
|
||||
if(typeof options.healthFactor != 'undefined') {
|
||||
playerInfo.clear();
|
||||
|
||||
playerInfo.beginFill(0x000000);
|
||||
playerInfo.lineStyle(borderWidth, 0x000000);
|
||||
playerInfo.drawRect(0, 0, width, height);
|
||||
playerInfo.endFill();
|
||||
|
||||
if(options.healthFactor > 0) {
|
||||
playerInfo.beginFill(0x00FF00);
|
||||
playerInfo.lineStyle(0, 0x000000);
|
||||
playerInfo.drawRect(borderWidth, borderWidth, width * options.healthFactor, height);
|
||||
playerInfo.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.x && options.y) playerInfo.position = new PIXI.Point(offsetX + options.x, offsetY + options.y);
|
||||
if (options.visible === true || options.visible === false) playerInfo.visible = options.visible;
|
||||
};
|
||||
|
||||
PixiView.prototype.onRemovePlayerInfo = function(playerInfo) {
|
||||
this.container.removeChild(playerInfo);
|
||||
};
|
||||
|
||||
return PixiView;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue