使用corona开发电子书的童鞋一定为不能方便的实现“翻书卷页”效果而纠结苦恼,现在大家有福了,今天放出一个在corona中巧妙使用遮罩来实现的卷页效果,先上图:
核心代码:
-- The following function will turn the page "back"local function gotoPrevious( curlPage, time )local time = time or 500 curlPage.isVisible = truelocal hideCurl = function()curlPage.isVisible = falseturnGroup:setMask( nil )endtransition.to( turnGroup, {maskX=display.contentWidth*0.5+100, time=time } )transition.to( curlPage, { rotation=45, x=display.contentWidth+(display.contentWidth*0.10), y=display.contentHeight + (display.contentHeight*0.25), time=time, onComplete=hideCurl })end -- The following function will turn the page "forward"local function gotoNext( currentPage, curlPage, time )-- add "pages" to page turning groupturnGroup:insert( currentPage )turnGroup:insert( curlPage ) -- mask should match dimensions of content (e.g. content width/height)local curlMask = graphics.newMask( "mask_320x480.png" )turnGroup:setMask( curlMask ) -- set initial mask positionturnGroup.maskX = display.contentWidth * 0.5+100turnGroup.maskY = display.contentHeight * 0.5 -- prepare the page-to-be-turned and the curl imagecurrentPage:setReferencePoint( display.BottomLeftReferencePoint )curlPage:setReferencePoint( display.BottomRightReferencePoint )curlPage.rotation = 45curlPage.x = display.contentWidth+(display.contentWidth*0.10)curlPage.y = display.contentHeight + (display.contentHeight*0.25)curlPage.isVisible = true -- show pagecurl animation and transition away (next page should already be in position)local time = time or 500transition.to( turnGroup, { maskX=-display.contentWidth*0.75, time=time } )transition.to( curlPage, { rotation=0, x=0, y=display.contentHeight+20, time=time} )curlPage.yScale = curlPage.y * 0.2end提醒:本代码只提供解决思路和方法,并没有进行代码的健壮性测试,请大家根据自己项目需要进行相关的完善和改进工作。