스프리시스가없는 애니메이션 스프라이트
-
21-12-2019 - |
문제
cocos2d-js에서 애니메이션 스프라이트를 만들려고하지만, Cocos2d-iphone 프로젝트에서 한 것처럼 스프리트 시트를 사용하고 싶지는 않습니다.
NSMutableArray *animationFrames = [NSMutableArray array];
int frameCount = 0;
for(int i = 1; i <= 9; ++i)
{
CCSpriteFrame *spriteFrame = [CCSpriteFrame frameWithImageNamed:[NSString stringWithFormat:@"hero-%d.png",i]];
[animationFrames addObject:spriteFrame];
}
NSLog(@"cria sprite com frames");
_player = [CCSprite spriteWithSpriteFrame:animationFrames.firstObject];
.
cocos2d-js에서 어떻게 할 수 있습니까?Cocos2D-JS 문서에서 동일한 기능을 찾지 못했습니다.
해결책
코드는 다음 코드가 조금 더 복잡합니다.그러나 그것은 작동하고 파일에서 스프라이트를로드하고 애니메이션을 함께 넣고 스프라이트의 런스션에서 그것을 사용합니다 (animframe은 빈 배열 "이"cclayer입니다.
var str = "";
for (var i = 1; i < 9; i++) {
str = "mosquito_fly" + (i < 10 ? ("0" + i) : i) + ".png";
var texture = cc.textureCache.addImage("res/Murbiks/"+str);
var spriteFrame = cc.SpriteFrame.create(texture,cc.rect(0,0,96,96));
animFrames.push(spriteFrame);
}
var animation = cc.Animation.create(animFrames, 0.06+Math.random()*0.01, 10);
var animate = this.animateMostafa = cc.Animate.create(animation);
// Create sprite and set attributes
mostafa = cc.Sprite.create(res.Mostafa_single_png);
mostafa.attr({
x: 0,
y: 0,
scale: 0.60+Math.random()*0.3,
rotation: 0
});
this.addChild(mostafa, 0);
. 제휴하지 않습니다 StackOverflow