cocos2d3.5新手引导

游戏中,新手引导经常要用到。这次是基于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,下层响应完毕。

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...