创建帧动画

前端之家收集整理的这篇文章主要介绍了创建帧动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

函数只适用于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
原文链接:https://www.f2er.com/cocos2dx/347164.html

猜你在找的Cocos2d-x相关文章