Last active
August 29, 2015 14:15
-
-
Save vkgtaro/a747eea4ebdeb85d3d25 to your computer and use it in GitHub Desktop.
cocos2d-js でアニメーションを読み込む関数書いた ref: http://qiita.com/vkgtaro/items/e9fa63f0b6a54c7dba50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var animationLoad = function (animation_name, width, height, turn_point, count, delay_time, image_path) { | |
var x_count = 0; | |
var y_count = 0; | |
var frames_array = []; | |
for (var i = 0; i < count; i++ ) { | |
var current_x = width * x_count; | |
var current_y = height * y_count; | |
var frame = cc.SpriteFrame.create( | |
image_path, | |
cc.rect( current_x, current_y, width, height ) | |
); | |
frames_array.push(frame); | |
if ( i % turn_point ) { | |
x_count = 0; | |
y_count++; | |
} | |
else { | |
x_count++; | |
} | |
} | |
var animation = cc.Animation.create(frames_array, delay_time); | |
cc.AnimationCache.getInstance().addAnimation(animation, animation_name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loadAnimation = function (animation_name, width, height, turn_point, count, delay_time, image_path) { | |
var x_count = 0; | |
var y_count = 0; | |
var frames_array = []; | |
for (var i = 1; i < count; i++ ) { | |
var current_x = width * x_count; | |
var current_y = height * y_count; | |
var frame = cc.SpriteFrame.create( | |
image_path, | |
cc.rect( current_x, current_y, width, height ) | |
); | |
frames_array.push(frame); | |
if ( turn_point == 1 || i % turn_point == 0 ) { | |
x_count = 0; | |
y_count++; | |
} | |
else { | |
x_count++; | |
} | |
} | |
var animation = cc.Animation.create(frames_array, delay_time); | |
cc.AnimationCache.getInstance().addAnimation(animation, animation_name); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
animationLoad("a", 320, 240, 3, 15, 1/20, "parapara_anime.png"); | |
var anim_cache = cc.AnimationCache.getInstance(); | |
var a = anim_cache.getAnimation("a"); | |
a.setRestoreOriginalFrame(true); | |
var anim = cc.Animate.create(a); | |
var anim_sprite = cc.Sprite.create(); | |
anim_sprite.setTextureRect(cc.rect(0, 0, 320, 240)); | |
anim_sprite.setPosition(200, 200); | |
this.addChild(anim_sprite); | |
anim_sprite.runAction(cc.RepeatForever.create(anim)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadAnimation("a", 320, 240, 3, 15, 1/20, "parapara_anime.png"); | |
var anim_cache = cc.AnimationCache.getInstance(); | |
var a = anim_cache.getAnimation("a"); | |
a.setRestoreOriginalFrame(true); | |
var anim = cc.Animate.create(a); | |
var anim_sprite = cc.Sprite.create(); | |
anim_sprite.setTextureRect(cc.rect(0, 0, 320, 240)); | |
anim_sprite.setPosition(200, 200); | |
this.addChild(anim_sprite); | |
anim_sprite.runAction(cc.RepeatForever.create(anim)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment