functionMenuLayer:addTouches()
localtouch1,touch2=cc.Touch,cc.Touch
localfunctiononTouchesBegan(touches,event)
print(“TouchesBegan”)
touch1=touches[1]—第一个触点,下标从1开始
touch2=touches[2]—第二个触点
localpos1=touch1:getLocation()—获取触点1的位置
localpos2=touch2:getLocation()—获取触点2的位置
localdelta={
x=pos2.x–pos1.x,
y=pos2.y–pos1.y
}
end
localfunctiononTouchesMoved(touches,sans-serif; font-size:15px; line-height:26px; text-indent:30px">print(“TouchesMoved”)
localfunctiononTouchesEnded(touches,sans-serif; font-size:15px; line-height:26px; text-indent:30px">print(“TouchesEnded”)
—注册多点触摸
locallistener=cc.EventListenerTouchAllAtOnce:create() --单点EventListenerTouchOneByOne():create()
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN)
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED)
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED)
--获取层的事件派发器
localdispatcher=cc.Director:getInstance():getEventDispatcher()
dispatcher:addEventListenerWithSceneGraPHPriority(listener,self)
end
— 定时器
--开启定时器,一般是两种方式
schedulerID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(update,false) --调用的function,调用频率(秒),是否暂停(true,false)
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(schedulerID) -- 取消定时器
第二种:类似c++中的scheduleUpdate()
self:scheduleUpdateWithPriorityLua(update,0)
self:unscheduleUpdate() --取消定时器
local function update(delta)
end
— 进度条
--血条 local bloodBody = cc.Sprite:create(bloodPic) --创建进度条 local bloodProgress = cc.ProgressTimer:create(bloodBody) bloodProgress:setType(cc.PROGRESS_TIMER_TYPE_BAR) --设置为条形 type:cc.PROGRESS_TIMER_TYPE_RADIAL bloodProgress:setMidpoint(cc.p(0,0)) --设置起点为条形坐下方 bloodProgress:setBarChangeRate(cc.p(1,0)) --设置为水平方向 bloodProgress:setPercentage(100) -- 设置初始进度为0 bloodProgress:setPosition(cc.p(0,0)) self:addChild(bloodProgress) 原文链接:https://www.f2er.com/cocos2dx/339931.html