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,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,下层响应完毕。



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值