import cocos import cocos.actions as ac
๐ ac.MoveTo(position, time)
positon์ ์ขํ๋ก time์๊ฐ ๋์ ์์ง์ด๊ธฐ
sprite๋ฅผ 3์ด๋์ (250, 300)์์น๋ก ์์ง์ฌ๋ผ.
sprite.do(ac.MoveTo((250, 300), 3))
๐ ac.JumpTo(position, height, jumps, duration)
๐ ac.RotateTo(Angle, time)
๐ ac.ScaleTo(size, time)
๐ ac.Blink(times, duration)
๐ ac.FadeIn(time)
& ac.FadeOut(time)
๐ ac.Delay(time)
time๋์ ๋์ํ์ง ์๊ณ ๊ธฐ๋ค๋ฆฌ๊ธฐ
ex) 2์ด ๋์ ๊ธฐ๋ค๋ฆฐ ํ (500, 300)์์น๋ก 1์ด ๋์ ์์ง์ด๊ธฐ
sprite.do(ac.Delay(2)+ ac.MoveTo((500, 300), 1))
๐ป Sample Code
import cocos
import cocos.actions as ac
if __name__ == '__main__':
cocos.director.director.init(caption='Actions 101')
layer = cocos.layer.Layer()
sprite = cocos.sprite.Sprite('tank.png', position=(200, 200))
sprite.do(ac.MoveTo((250, 300), 3))
layer.add(sprite)
scene = cocos.scene.Scene(layer)
cocos.director.director.run(scene)
๐ ac.Place(pos_vec)
๐ ac.Hide()
& ac.show()
๐ ac.ToggleVisibility(bool)
sprite.do(ac.ToggleVisibility(true))
def func1():
print ("hello")
action = CallFunc(func1)
sprite.do(action)
def func2(sprite):
print ("hello")
action = CallFuncS(func2)
sprite.do(action)
ac.MoveBy((80, 0), 3) + ac.Delay(3) + ac.CallFunc(sprite.kill) )
ac.MoveBy((80, 0), 3) | ac.RotateBy(90, 2) )
ac.MoveBy((80, 0), 3) | ac.RotateBy(90, 2) + ac.CallFunc(sprite.kill) )
โ duration ๊ฐ๊ฒฉ์ผ๋ก sprite์ ์์ ๋ฐ๊พธ๊ธฐ
class Hit(ac.IntervalAction):
def init(self, duration=0.5):
self.duration = duration
def update(self, t):
self.target.color = (255, 255 * t, 255 * t)
โ sprite๋ฅผ 2์ด๋์ 3๋ฒ ๊น๋นก์ด๋ฉฐ 3์ด๋์ ์์ ๋ฐ๊พผ๋ค
sprite.do(ac.Blink(3,2) + Hit(3))