cocos2d3.5新手引导
发布时间:2020-12-14 21:27:02 所属栏目:百科 来源:网络整理
导读:游戏中,新手引导经常要用到。这次是基于3.5版本。 思路:创建遮罩,显示区触摸,下层响应。 让引导层继承widget local Guide = class("Guide",function ()return ccui.Widget:create()end) 把 guide设置描点为self:setAnchorPoint(cc.p(0,0))。这样方便坐标
游戏中,新手引导经常要用到。这次是基于3.5版本。 思路:创建遮罩,显示区触摸,下层响应。 让引导层继承widget
local Guide = class("Guide",function () return ccui.Widget:create() end) 把guide设置描点为self:setAnchorPoint(cc.p(0,0))。这样方便坐标计算。 这样可以方便处理触摸区域的响应。通过点击的落点是否在显示区域,然后设置self.listener:setSwallowTouches(true),可以向下层穿透,响应事件; function OperationalView:onTouchBegan(touch_,event_) print(" OperationalView:onTouchBegan began") local pos = touch_:getLocation() self._touchPos = cc.p(pos.x,pos.y) if self._blackBg then else self._listener:setSwallowTouches(false) end if rectIntersectsPoint(self._stencil:getBoundingBox(),cc.p(pos.x,pos.y)) then self._listener:setSwallowTouches(false) end return true end
遮罩可以使用cc.LayerColor:create(cc.c4b(0,0))来创建 实现镂空 self._clippingNode = cc.ClippingNode:create() self._clippingNode:addChild(self._stencil) self._clippingNode:setStencil(self._stencil) self._clippingNode:setInverted(true) self._stencil可以是图片资源,也可以使用cc.DrawNode:create()来创建; 对于下层的响应,设计框架时,按钮的监听事件都通过统一回调处理。或者把widget封装多一层。响应按钮事件后通知guide,下层响应完毕。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |