简单的圆弧运动,
local circleBg = cc.Sprite:create("240.png")circleBg:setPosition(640,360)
self:addChild(circleBg)
local circle = cc.Sprite:create("headpic/cc_headpic62.png")circle:setScale(0.3)
self:addChild(circle)
local moveTimes = 1
local pos = {x =640,y=360}
local radius = 120
local t = 1
local radian = 2.0 * 3.1415926 / ( t/(cc.Director:getInstance():getAnimationInterval()) )
self:runAction( cc.RepeatForever:create( cc.Sequence:create(
cc.CallFunc:create(function ( )
local _radian = radian * moveTimes
local x = radius * math.sin(_radian)
local y = radius * math.cos(_radian)
local _pos = {x = circle:getPositionX(),y = circle:getPositionY()}
circle:setPosition(pos.x + x,pos.y + y )
local __pos = {x = circle:getPositionX(),y = circle:getPositionY()}
-- 计算用来图片的转向
local K = math.atan( (__pos.x - _pos.x) / (__pos.y - _pos.y))
local rat = K*180/3.14159265
if __pos.y >= pos.y and __pos.x <= pos.x then
rat = rat
elseif __pos.y >= pos.y and __pos.x > pos.x then
rat = 180 + rat
elseif __pos.y <= pos.y and __pos.x > pos.x then
rat = 180 + rat
else
rat = rat
end
circle:setRotation(rat);
moveTimes = moveTimes + 1
end),
cc.DelayTime:create(1/60)
)))