cocos-lua r囧r小猫 2021-12-24 09:41 194阅读 0赞 function YZMGame33:initAnimate(path,row, col, width, height, delay) local perWidth = width/col; local perHeight = height/row; local animation = cc.Animation:create(); for i=1,row do for j=1,col do local spFrame = cc.SpriteFrame:create(path,cc.rect((j-1)\*perWidth,(i-1)\*perHeight,perWidth,perHeight)); animation:addSpriteFrame(spFrame); end end animation:setDelayPerUnit(delay or 0.2); animation:setLoops(-1); local animate = cc.Animate:create(animation); return animate; end function YZMGame33:initMenu() local menu = cc.Menu:create() menu:setPosition(cc.p(0, self.bg\_bottom:getPositionY()-80)) self:addChild(menu); self.btn\_start = self:initButton("yzm/yzm\_button\_bt\_start.png",179,210); self.btn\_start:addTo(menu); self.btn\_start:setPosition(cc.p(1030, 48)); self.btn\_stop = self:initButton("yzm/yzm\_button\_bt\_stop.png",179,210); self.btn\_stop:setPosition(cc.p(1030, 48)); self.btn\_stop:setVisible(false); self.btn\_stop:addTo(menu); self.btn\_auto = self:initButton("yzm/yzm\_button\_bt\_auto.png",131,192); self.btn\_auto:setPosition(cc.p(875,48)); self.btn\_auto:addTo(menu); end function YZMGame33:initButton(path, width, height) local stateNum = 3; local menuItemImage = cc.MenuItemImage:create(); for i=1,stateNum do local btn\_state = cc.SpriteFrame:create(path, cc.rect(0,(i-1)\*height/3,width,height/3)); if i == 1 then menuItemImage:setNormalSpriteFrame(btn\_state); elseif i == 2 then menuItemImage:setSelectedSpriteFrame(btn\_state); else menuItemImage:setDisabledSpriteFrame(btn\_state); end end return menuItemImage; end 转载于:https://www.cnblogs.com/sujiehaojava/p/7667713.html
还没有评论,来说两句吧...