2014-07-26 3 views
0

저는 EaselJS SpriteSheets를 사용하고 있는데 어떻게하면 영웅을 부드럽게 움직일 수 있는지 알고 싶습니다. SpriteSheet가 "실행"애니메이션을 재생하고 프레임 5에있는 경우, 프레임 6, 7, 8, 8, 8, 7, 6, 5를 움직여야하고 영웅이 멈추지 않도록 0으로 멈춰야합니다. 어떻게하면됩니까? 프레임이 연속 아니라는 것을EaselJS는 현재 프레임을 기반으로 프레임을 움직입니다.

my SpriteSheet

참고 :

여기 내 SpriteSheet의 그들은, 0에서 4까지 4 사용되지 9 프레임 8. 다음 5-0로 이동합니다.

function changeAnimation(obj, frameOrAnimation) { 
    if (obj.animation != frameOrAnimation) { 
     obj.animation = frameOrAnimation; 
     obj.gotoAndPlay(frameOrAnimation); 
    } 
} 

기능 사용 :

다음
user.hero.bmp = new createjs.Bitmap("Graphics/Fox.png"); 
user.hero.bmp.cache(0, 0, user.hero.bmp.image.width, user.hero.bmp.image.height); 
var data = new createjs.SpriteSheet({ 
    images: [user.hero.bmp.cacheCanvas], 
    frames: { 
     width: 30, 
     height: 40 
    }, 
    animations: { 
     stand: 0, 
     run: { 
      frames: [0,1,2,3,4,4,4,3,2,1,0,5,6,7,8,8,8,7,6,5], 
      next: true, 
      speed: .75 
     } 
    } 
}); 
user.hero = new createjs.Sprite(data, "stand"); 
// Removed lots of non-relevant things here 
movableObjContainer.addChild(user.hero); 
movableObj.push(user.hero); 

내가 애니메이션 사이에서 변경하는 데 사용하는 기능입니다 :

여기 내 SpriteSheet 코드의 changeAnimation(user.hero, "stand");

여기 일이다 전자 가장 중요한 부분, 시세 내에서 실행 애니메이션 논리 : 때

if ((user.input.left || user.input.right) && !user.hero.jumping) { 
    changeAnimation(user.hero, "run"); 
} else if (!user.hero.jumping && user.hero.animation != "stopFalling" && user.hero.animation != "almostFalling") { 
    changeAnimation(user.hero, "stand"); 
} 

답변