local function logoShake()
--rand_n = range * math.sin(math.rad(time*speed+offset))
local rand_x = 0.1*math.sin(math.rad(time*0.5+4356))
local rand_y = 0.1*math.sin(math.rad(time*0.37+5436))
local rand_z = 0.1*math.sin(math.rad(time*0.2+54325))
logo:setRotation3D({x=math.deg(rand_x),y=math.deg(rand_y),z=math.deg(rand_z)})
time = time+1
end
self.logoSchedule = cc.Director:getInstance():getScheduler():scheduleScriptFunc(logoShake,0,false)
其实这段代码可以看作是
local rand_x = 0.1*math.sin(math.rad(time))
local rand_y = 0.1*math.sin(math.rad(time))
local rand_z = 0.1*math.sin(math.rad(time))
通过math.rad 把time限制为360以内得一个弧度,再通过 math.sin 转换为一个区间数值[-x,x],
最后 *0.1 将摆动幅度降低,这样就实现了一个 x,y,z轴上的来回摇摆