加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

创建帧动画

发布时间:2020-12-14 19:00:08 所属栏目:百科 来源:网络整理
导读:该函数只适用于cocos2dx 2.2.5 --创建帧动画--[[ FrameWidth 帧动画宽 FrameHeight 帧动画高 imageFile 图片文件 默认循环播放]]--local function createAnim(FrameWidth,FrameHeight,imageFile)local tex = CCTextureCache:sharedTextureCache():addImage(i

该函数只适用于cocos2dx 2.2.5

--创建帧动画
	--[[
	   FrameWidth 帧动画宽
	   FrameHeight 帧动画高
	   imageFile  图片文件
	   默认循环播放
	]]--
	local function createAnim(FrameWidth,FrameHeight,imageFile)	
		local tex = CCTextureCache:sharedTextureCache():addImage(imageFile)
		frame0 = CCSpriteFrame:createWithTexture(tex,CCRectMake(0,FrameWidth,FrameHeight))
		frame1 = CCSpriteFrame:createWithTexture(tex,CCRectMake(FrameWidth*1,FrameHeight))
			
		local spriteDog = CCSprite:createWithSpriteFrame(frame0)	
		spriteDog:setPosition(CCPoint(100,100))
		spriteDog:setVisible(true)
		
		animFrames = CCArray:createWithCapacity(2);
		animFrames:addObject(frame0);
		animFrames:addObject(frame1);	
		
		animation = CCAnimation:createWithSpriteFrames(animFrames,0.5)
		animate = CCAnimate:create(animation);
		spriteDog:runAction(CCRepeatForever:create(animate))
		return spriteDog	
	end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读