标签:cocox
学习Cocox,真的是相当麻烦,IDE的支持太差了,Cocox的各种版本也是多种多样,我先研究的是用Lua语言开发,但是学习起来还是蛮有趣的,我喜欢这种学习。下面基本的数学知识在Cocox的几种应用:
1、跳动的小球(向量的应用)
local direction=cc.p(math.random(-1,1),math.random(-1,1))
cc.pNormalize(direction)
local dot=display.newDrawNode():addTo(self):center()
dot:drawDot(cc.p(0,0),10,cc.c4f(1.0,1.0,1.0,1.0))
self:getScheduler():scheduleScriptFunc(function()
local px,py=dot:getPosition()
if px<0 or px>display.width then
direction.x=direction.x*-1
elseif py<0 or py>display.height then
direction.y=direction.y*-1
end
dot:pos(px+direction.x*10,py+direction.y*10)
end,0,false)2、小球跟着方块一起旋转(世界坐标和本地坐标的应用)
local rect=display.newDrawNode():addTo(self):center()
rect:drawRect(cc.p(0,0),cc.p(300,300),cc.c4f(1.0,0,0,1.0))
-- self:add(rect)
local dot=display.newDrawNode():addTo(rect):pos(20,20)
dot:drawDot(cc.p(0,0),10,cc.c4f(1.0,1.0,1.0,1.0))
self:getScheduler():scheduleScriptFunc(function()
rect:rotation(rect:getRotation()+1)
-- local px,py=dot:getPosition();
-- print(px,py)
local p=dot:convertToWorldSpace(cc.p(0,0))
print(p.x,p.y)
end,0,false)
rect:size(300,300);
rect:setAnchorPoint(cc.p(0.5,0.5))
3、小球做椭圆运动(三角函数的应用)
local angle=0
local dot=display.newDrawNode():addTo(self):pos(20,20):center()
dot:drawDot(cc.p(0,0),10,cc.c4f(1.0,1.0,1.0,1.0))
self:getScheduler():scheduleScriptFunc(function()
dot:setPositionX(display.cx+math.cos(angle)*110+0.1)
dot:setPositionY(display.cy+math.sin(angle)*100+0.1)
angle=angle+0.1
end,0,false)标签:cocox
原文地址:http://blog.csdn.net/scboyhj__/article/details/45126197