mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed first animations
This commit is contained in:
parent
caa3945869
commit
142964938c
8 changed files with 159 additions and 53 deletions
|
|
@ -6,46 +6,97 @@ define([
|
|||
|
||||
function (Parent, Settings, NotificationCenter) {
|
||||
|
||||
function Doll(physicsEngine, playerId) {
|
||||
Parent.call(this, physicsEngine, playerId);
|
||||
this.height = 36;
|
||||
function Doll(physicsEngine, playerId) {
|
||||
this.animationDef = {
|
||||
"stand": [1,1],
|
||||
"walk": [2,28],
|
||||
"walkback": [29,55],
|
||||
//"jump": [56,80],
|
||||
"jump": [81,91],
|
||||
"fall": [81,91],
|
||||
"duck": [92,97],
|
||||
"standup": [98,103],
|
||||
"run": [104,126]
|
||||
}
|
||||
|
||||
this.animatedMeshes = {};
|
||||
|
||||
Parent.call(this, physicsEngine, playerId);
|
||||
}
|
||||
|
||||
Doll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
|
||||
Doll.prototype.setActionState = function(state) {
|
||||
|
||||
if(this.actionState == state) return;
|
||||
|
||||
if(this.animatedMeshes[this.actionState]) {
|
||||
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
|
||||
}
|
||||
|
||||
Parent.prototype.setActionState.call(this, state);
|
||||
|
||||
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: true });
|
||||
}
|
||||
|
||||
Doll.prototype.createMesh = function() {
|
||||
|
||||
var padF = function(n) {
|
||||
if(n<10) return "00" + n;
|
||||
if(n<100) return "0" + n;
|
||||
return n;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
var imgPath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||
+ 'Chuck' + '/'
|
||||
+ 'chuck.png';
|
||||
for (var key in this.animationDef) {
|
||||
var start = this.animationDef[key][0];
|
||||
var end = this.animationDef[key][1];
|
||||
|
||||
var callback = function(mesh) {
|
||||
self.mesh = mesh;
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
var texturePaths = [];
|
||||
for (var i = start; i <= end; i++) {
|
||||
texturePaths.push(Settings.GRAPHICS_PATH + "Animation/WithArms/ChuckAnimations0" + padF(i) + ".png");
|
||||
}
|
||||
|
||||
var callback = function(mesh) {
|
||||
self.animatedMeshes[key] = mesh;
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
};
|
||||
|
||||
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, { visible: false, pivot: "mb" });
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("view/createMesh",
|
||||
10,
|
||||
36,
|
||||
0,
|
||||
0,
|
||||
imgPath,
|
||||
callback
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Doll.prototype.render = function() {
|
||||
if(this.actionState) {
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.animatedMeshes[this.actionState],
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO
|
||||
}
|
||||
);
|
||||
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO + 4,
|
||||
y: (this.body.GetPosition().y * Settings.RATIO) - 29
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Doll.prototype.lookAt = function(x, y) {
|
||||
var oldLookDirection = this.lookDirection;
|
||||
Parent.prototype.lookAt.call(this, x, y);
|
||||
|
||||
if(oldLookDirection != this.lookDirection) {
|
||||
for(var key in this.animatedMeshes) {
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.animatedMeshes[key],
|
||||
{
|
||||
xScale: this.lookDirection
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: implement destroy
|
||||
|
||||
return Doll;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ function (Parent, Settings, DomController, Box2D) {
|
|||
| Box2D.Dynamics.b2DebugDraw.e_jointBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
|
||||
| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue