0
나는 잠시 동안 스프라이트 시트 이동을 시도하고 easeljs 문서에있는 다양한 방법을 시도했다. 그래도 나는 피 묻은 일을 할 수 없다. 그래서 당신 중 일부가 그것을 볼 수 있기를 바랬습니다.createjs 스프라이트 시트가 움직이지 않는다.
내가 사용하는 스프라이트 시트는 160x40이고 1 스프라이트는 40x40입니다.
가 여기에 애니메이션을해야 내 적 기능입니다 : (라인 25 틱은 창조 이동 기능에서에서 gotoAndPlay입니다.) 요청으로
var enemyWidth = 40;
var enemyHeight = 40;
function Enemy(number) {
this.number = number;
this.id = 'enemy';
var randomStartLoc = new locationOutsidePlayfield();
enemyLoc = new locationOutsidePlayfield();
this.x = randomStartLoc.x;
this.y = randomStartLoc.y;
this.health = 100;
//The damage a collision the enemy with a player does
this.damage = 30;
var target = new Target(this.x, this.y);
this.velX = target.velX;
this.velY = target.velY;
this.hitScore = 25;
this.killScore = this.hitScore*2;
var spriteSheet = new createjs.SpriteSheet({
images: ["resources/sprites/enemy_spritesheet.png"],
frames: {width:40, height:40},
animations: {
walk: [0, 3]
}
});
this.sprite = new createjs.BitmapAnimation(spriteSheet);
this.sprite.currentFrame = 0;
this.sprite = new createjs.BitmapAnimation(spriteSheet);
this.sprite.x = this.x;
this.sprite.y = this.y;
this.sprite.width = enemyWidth;
this.sprite.height = enemyHeight;
this.collide = function(arrayIndex, bullet) {
if (bullet) {
this.health -= player.damage;
}
if (this.health <= 0) {
//Generate a number between 0 and 10. If it's 1(10% chance) a powerup will be made on the spot of the death.
var percentage = Math.round(getRandomNumber(0, 10));
//If the percentage is one and there are no powerUps on the stage it's okay to add a powerup.
if (percentage < 6 && powerUp.length == 0) {
var pwrp = new Powerup(this.x, this.y);
powerUp.push(pwrp);
if (!powerUpLayer) {
powerUpLayer = new createjs.Container();
stage.addChild(powerUpLayer);
}
}
//Increase the score
score.increaseScore(this.killScore);
//Delete the object
delete this;
//Remove the sprite
enemyLayer.removeChild(this.sprite);
//Remove the enemy and the bullets from their array
enemies.splice(arrayIndex, 1);
for (var i in this.bullets) {
ammoLayer.removeChild(this.bullets[i].sprite);
delete this.bullets[i];
}
this.bullets = [];
} else {
//If the enemy didnt die, update the score with the hit score.
score.increaseScore(this.hitScore);
}
countEnemies();
}
this.draw = function() {
//enemyLayer.draw();
}
this.move = function() {
this.sprite.gotoAndPlay("walk");
//Set a boolean that will check later on if the enemy should change direction. Therefore getting a new X an Y.
var directionChange = false;
this.x += this.velX;
this.y += this.velY;
this.sprite.x = this.x;
this.sprite.y = this.y;
if (this.y <= -150) {
directionChange = true;
}
if (this.y >= (stage.canvas.height-this.sprite.height)+150) {
directionChange = true;
}
if (this.x <= -150) {
directionChange = true;
}
if (this.x >= (stage.canvas.width-this.sprite.width)+150) {
directionChange = true;
}
if (directionChange == true) {
var target = new Target(this.x, this.y);
this.velX = target.velX;
this.velY = target.velY;
}
}
this.flickr = function() {
this.sprite.alpha = 0.5;
var enem = this.sprite;
setTimeout(function() {
enem.alpha = 1;
}, 100);
}
this.bullets = [];
}
적 생성 기능.
var enemies = [];
var newEnemiesAmount;
var oldEnemiesAmount;
function createEnemies(amount) {
oldEnemiesAmount = (amount > 0) ? amount : oldEnemiesAmount;
newEnemiesAmount = amount+(Math.floor(oldEnemiesAmount)/5)
//Create a layer to spawn the enemies on
enemyLayer = new createjs.Container();
//Loop through the amount wanted.
for (var i = 0; i < newEnemiesAmount; i++) {
enemy = new Enemy(i);
createEnemyBullet(enemy);
//push the object in an array and add it to the newly made layer
enemies.push(enemy);
enemyLayer.addChild(enemy.sprite);
}
stage.addChild(enemyLayer);
}
스프라이트 시트 표시가 전혀 보이지 않습니까? 적 (Enemy)이 생성 된 곳, 스프라이트가 스테이지에 추가 된 곳 또는 스테이지가 업데이트 된 곳의 애플리케이션에 대한 코드를 표시하지 않습니다. 아마도 컨텍스트를 표시 할 수 있습니까? – Lanny
예. 시퀀스의 첫 번째 이미지가 보입니다. 프로젝트는 꽤 거대해 바이올린은 정직하지 못합니다. 나는 spritesheet를 만들 때 어리석은 실수를하기를 바랬다. 게다가. 스테이지가 시세 표시로 업데이트되므로 문제가되지 않아야합니다. 나는 적의 창조물을 내 포스트에 추가 할 것이다. 그래서 당신이 이것을 읽을 때까지는 거기에 있어야합니다 ;-) – CaptainCarl
나는 뛰어 내리고있는 것을 보지 못합니다 - SpriteSheet를 스파이크로 격리 시켜서 작동하는지 확인하십시오 - 뭔가 다른 것으로 의심됩니다. 외부 적으로 영향을 미친다. – Lanny