Add: animal sprite sheet
This commit is contained in:
+51
-24
@@ -1,12 +1,16 @@
|
||||
function Animal(type, x, y) {
|
||||
function Animal(type, index, x, y) {
|
||||
this.animalType = type;
|
||||
|
||||
this.sprite = null;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
|
||||
this.sprite = game.add.sprite(this.posX, this.posY); //, "snail_run1"); // this.spriteFrameNames.run1);
|
||||
// this.sprite = game.add.sprite(this.posX, this.posY); //, "snail_run1"); // this.spriteFrameNames.run1);
|
||||
this.sprite = game.add.sprite(this.posX, this.posY, "animals");
|
||||
this.sprite.anchor.set(0.5);
|
||||
this.sprite.animations.add("stand", [index * 2]);
|
||||
this.sprite.animations.play("stand");
|
||||
this.sprite.animations.add("run", [index * 2, index * 2 + 1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +21,15 @@ Animal.prototype.setScale = function(value) {
|
||||
Animal.prototype.setIconSprite = function(species) {
|
||||
this.setSpecies(species);
|
||||
|
||||
this.spriteFrameNames = this.loadSpriteNames();
|
||||
this.sprite.loadTexture(this.spriteFrameNames.run1);
|
||||
// this.spriteFrameNames = this.loadSpriteNames();
|
||||
// this.sprite.loadTexture(this.spriteFrameNames.run1);
|
||||
}
|
||||
|
||||
Animal.prototype.setSpecies = function(species) {
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
/*
|
||||
Animal.prototype.loadSpriteNames = function() {
|
||||
let spriteNames = {};
|
||||
|
||||
@@ -35,6 +40,7 @@ Animal.prototype.loadSpriteNames = function() {
|
||||
|
||||
return spriteNames;
|
||||
}
|
||||
*/
|
||||
|
||||
Animal.prototype.setAlpha = function(value) {
|
||||
this.sprite.alpha = value;
|
||||
@@ -44,14 +50,15 @@ Animal.prototype.setAlpha = function(value) {
|
||||
Animal.prototype.tweenAnimation = function(animationType) {
|
||||
switch(animationType) {
|
||||
case Animal.ANIMATION_TYPE_CHANGE:
|
||||
this.sprite.width = 200;
|
||||
this.sprite.height = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150, height: 150 }, 500, Phaser.Easing.Bounce.Out, true);
|
||||
this.sprite.width = 100;
|
||||
this.sprite.height = 100;
|
||||
game.add.tween(this.sprite).to( { width: 50, height: 50 }, 500, Phaser.Easing.Bounce.Out, true);
|
||||
break;
|
||||
|
||||
case Animal.ANIMATION_TYPE_DAMAGE:
|
||||
this.sprite.width = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150 }, 500, Phaser.Easing.Bounce.In, true);
|
||||
this.sprite.width = 100;
|
||||
this.sprite.height = 50;
|
||||
game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Bounce.In, true);
|
||||
// game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Elastic.Out, true);
|
||||
break;
|
||||
|
||||
@@ -59,23 +66,28 @@ Animal.prototype.tweenAnimation = function(animationType) {
|
||||
}
|
||||
|
||||
Animal.prototype.setupAnimation = function() {
|
||||
this.spriteFrameNames = this.loadSpriteNames();
|
||||
this.playingSpriteFrameName = this.spriteFrameNames.run1;
|
||||
this.animationFrameID = 1;
|
||||
this.animationSpeedSec = 1000 / this.species.runningFPS;
|
||||
// this.spriteFrameNames = this.loadSpriteNames();
|
||||
// this.playingSpriteFrameName = this.spriteFrameNames.run1;
|
||||
// this.animationFrameID = 1;
|
||||
// this.animationSpeedSec = 1000 / this.species.runningFPS;
|
||||
|
||||
this.stopAnimation();
|
||||
this.animateionUpdate();
|
||||
// this.animateionUpdate();
|
||||
}
|
||||
|
||||
Animal.prototype.startAnimation = function(species) {
|
||||
this.sprite.animations.play("run", 5, true);
|
||||
|
||||
/*
|
||||
this.setSpecies(species);
|
||||
this.setupAnimation();
|
||||
|
||||
if(this.timerEvent === null)
|
||||
this.timerEvent = game.time.events.loop(this.animationSpeedSec, this.animateionUpdate, this);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
Animal.prototype.animateionUpdate = function() {
|
||||
this.animationFrameID = 1 - this.animationFrameID;
|
||||
|
||||
@@ -87,12 +99,17 @@ Animal.prototype.animateionUpdate = function() {
|
||||
this.sprite.width = 150;
|
||||
this.sprite.height = 150;
|
||||
}
|
||||
*/
|
||||
|
||||
Animal.prototype.stopAnimation = function() {
|
||||
this.sprite.animations.stop("run");
|
||||
|
||||
/*
|
||||
if(this.timerEvent !== null) {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
this.timerEvent = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -113,8 +130,12 @@ Animal.typingCount = function(speciesData, gameType) {
|
||||
}
|
||||
|
||||
Animal.loadResources = function() {
|
||||
game.load.spritesheet('animals', '../../../resources/image/character/animal/animals.png', 50, 50);
|
||||
|
||||
|
||||
game.load.image('snail_shadow', '../../../resources/image/character/animal/snail/shadow.png');
|
||||
|
||||
/*
|
||||
game.load.image('snail_icon', '../../../resources/image/character/animal/snail/run2.png');
|
||||
game.load.image('snail_run1', '../../../resources/image/character/animal/snail/run1.png');
|
||||
game.load.image('snail_run2', '../../../resources/image/character/animal/snail/run2.png');
|
||||
@@ -154,6 +175,7 @@ Animal.loadResources = function() {
|
||||
game.load.image('eagle_icon', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
game.load.image('eagle_run1', '../../../resources/image/character/animal/eagle/run1.png');
|
||||
game.load.image('eagle_run2', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -168,16 +190,21 @@ Animal.ANIMATION_TYPE_DAMAGE = 1;
|
||||
|
||||
|
||||
Animal.SPECIES_DATA = [
|
||||
{ "species" : "snail", "runningFPS" : 1.1, "practiceTypingCount" : 0, "testTypingCount" : 0 },
|
||||
{ "species" : "turtle", "runningFPS" : 2.2, "practiceTypingCount" : 5, "testTypingCount" : 20 },
|
||||
{ "species" : "cat", "runningFPS" : 3.3, "practiceTypingCount" : 10, "testTypingCount" : 50 },
|
||||
{ "species" : "lion", "runningFPS" : 4.4, "practiceTypingCount" : 15, "testTypingCount" : 100 },
|
||||
{ "species" : "rabbit", "runningFPS" : 5.5, "practiceTypingCount" : 20, "testTypingCount" : 200 },
|
||||
{ "species" : "ostrich", "runningFPS" : 7.7, "practiceTypingCount" : 25, "testTypingCount" : 300 },
|
||||
{ "species" : "horse", "runningFPS" : 9.9, "practiceTypingCount" : 30, "testTypingCount" : 400 },
|
||||
{ "species" : "dog", "runningFPS" : 12.2, "practiceTypingCount" : 35, "testTypingCount" : 500 },
|
||||
{ "species" : "cheetah", "runningFPS" : 16, "practiceTypingCount" : 40, "testTypingCount" : 600 },
|
||||
{ "species" : "eagle", "runningFPS" : 20, "practiceTypingCount" : 50, "testTypingCount" : 700 }
|
||||
{ "species" : "snail", "fps" : 1.1, "practiceTypingCount" : 0, "testTypingCount" : 0 },
|
||||
{ "species" : "turtle", "fps" : 2.2, "practiceTypingCount" : 5, "testTypingCount" : 20 },
|
||||
{ "species" : "chick", "fps" : 3.3, "practiceTypingCount" : 10, "testTypingCount" : 40 },
|
||||
{ "species" : "mouse", "fps" : 4.4, "practiceTypingCount" : 15, "testTypingCount" : 70 },
|
||||
{ "species" : "chicken", "fps" : 5.5, "practiceTypingCount" : 20, "testTypingCount" : 100 },
|
||||
{ "species" : "pig", "fps" : 7.7, "practiceTypingCount" : 25, "testTypingCount" : 150 },
|
||||
{ "species" : "cat", "fps" : 9.9, "practiceTypingCount" : 30, "testTypingCount" : 200 },
|
||||
{ "species" : "deer", "fps" : 12.2, "practiceTypingCount" : 40, "testTypingCount" : 250 },
|
||||
{ "species" : "kangaroo", "fps" : 16, "practiceTypingCount" : 50, "testTypingCount" : 300 },
|
||||
{ "species" : "rabbit", "fps" : 20, "practiceTypingCount" : 60, "testTypingCount" : 350 },
|
||||
{ "species" : "dog", "fps" : 20, "practiceTypingCount" : 80, "testTypingCount" : 400 },
|
||||
{ "species" : "zebra", "fps" : 20, "practiceTypingCount" : 100, "testTypingCount" : 450 },
|
||||
{ "species" : "ostrich", "fps" : 20, "practiceTypingCount" : 120, "testTypingCount" : 500 },
|
||||
{ "species" : "lion", "fps" : 20, "practiceTypingCount" : 140, "testTypingCount" : 600 },
|
||||
{ "species" : "cheetah", "fps" : 20, "practiceTypingCount" : 160, "testTypingCount" : 700 }
|
||||
];
|
||||
|
||||
Animal.SPRITE_NAMES = {
|
||||
|
||||
@@ -4,14 +4,15 @@ function AnimalList(y) {
|
||||
|
||||
var animalCount = Animal.SPECIES_DATA.length;
|
||||
var lineWidth = GAME_SCREEN_SIZE.x - AnimalList.MARGIN_X * 2;
|
||||
console.log("lineWidth : " + lineWidth);
|
||||
// console.log("lineWidth : " + lineWidth);
|
||||
var offsetAnimal = lineWidth / (animalCount - 1);
|
||||
console.log("animalCount : " + animalCount);
|
||||
console.log("offsetAnimal : " + offsetAnimal);
|
||||
// console.log("animalCount : " + animalCount);
|
||||
// console.log("offsetAnimal : " + offsetAnimal);
|
||||
|
||||
for(var i = 0; i < animalCount; i++) {
|
||||
this.animals[i] = new Animal(
|
||||
Animal.TYPE_ICON,
|
||||
i,
|
||||
AnimalList.MARGIN_X + offsetAnimal * i,
|
||||
y
|
||||
);
|
||||
@@ -19,7 +20,9 @@ function AnimalList(y) {
|
||||
}
|
||||
|
||||
this.activeAnimalIndex = 0;
|
||||
// this.activate(this.activeAnimalIndex);
|
||||
this.activate(this.activeAnimalIndex);
|
||||
this.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE);
|
||||
}
|
||||
|
||||
AnimalList.prototype.activate = function(index) {
|
||||
@@ -55,5 +58,5 @@ AnimalList.prototype.tweenAnimation = function(animationType) {
|
||||
}
|
||||
|
||||
|
||||
AnimalList.MARGIN_X = 160;
|
||||
AnimalList.MARGIN_X = 100;
|
||||
AnimalList.ALPHA_INACTIVE = 0.1;
|
||||
Reference in New Issue
Block a user