ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:21.49KB ,
资源ID:30119792      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/30119792.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(AndEngine进阶之自定义Tiled精灵.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

AndEngine进阶之自定义Tiled精灵.docx

1、AndEngine进阶之自定义Tiled精灵AndEngine内置了一个TiledSprite类,可以传入TiledTextureRegion的纹理以构造一个可以连续播放的精灵,但必须要先制作好一张动画序列图片,俗称Tiled图。但有时候在游戏项目开发中,美术人员本来的工作量已经很大,而且这种Tiled在需要修改时也带来了工作量。在IPhone的cocos2d里的精灵类有一个runAction的方法可以播放一组序列图片以达到动画功能,但这种方式在使用的时候稍嫌麻烦,于是我封装了一个自定义Tiled精灵类。view plain1. packagecom.weedong.sprite;2. 3.

2、importstaticorg.anddev.andengine.util.constants.Constants.VERTEX_INDEX_X;4. importstaticorg.anddev.andengine.util.constants.Constants.VERTEX_INDEX_Y;5. 6. importjava.util.Arrays;7. 8. importjavax.microedition.khronos.opengles.GL10;9. 10. importorg.anddev.andengine.collision.RectangularShapeCollision

3、Checker;11. importorg.anddev.andengine.collision.ShapeCollisionChecker;12. importorg.anddev.andengine.entity.primitive.BaseRectangle;13. importorg.anddev.andengine.entity.scene.Scene;14. importorg.anddev.andengine.entity.scene.Scene.IOnAreaTouchListener;15. importorg.anddev.andengine.entity.shape.IS

4、hape;16. importorg.anddev.andengine.entity.shape.RectangularShape;17. importorg.anddev.andengine.input.touch.TouchEvent;18. importorg.anddev.andengine.opengl.texture.Texture;19. importorg.anddev.andengine.opengl.texture.region.TextureRegion;20. importorg.anddev.andengine.opengl.texture.region.Textur

5、eRegionFactory;21. importorg.anddev.andengine.opengl.texture.region.buffer.TextureRegionBuffer;22. importorg.anddev.andengine.opengl.texture.source.ITextureSource;23. importorg.anddev.andengine.opengl.util.GLHelper;24. importorg.anddev.andengine.util.MathUtils;25. importorg.anddev.andengine.util.con

6、stants.TimeConstants;26. 27. importcom.weedong.scene.ITextureLoadManager;28. importcom.weedong.utils.TextureUtils;29. 30. /*31. *自定义精灵,几乎可以实现像cocos2d一般的使用非tiled图片进行动画播放的功能32. *用法:在构造函数里传入相关的图片即可33. *author34. *35. */36. publicclassCustomTiledSpriteextendsBaseRectangle37. 38. privatestaticfinalintLOO

7、P_CONTINUOUS=-1;39. privatebooleanmAnimationRunning;40. privatelongmAnimationProgress;41. privatelongmAnimationDuration;42. privatelongmFrameEndsInNanoseconds;43. 44. privateintmFirstTileIndex;45. privateintmInitialLoopCount;46. privateintmLoopCount;47. privateIAnimationListenermAnimationListener;48

8、. 49. privateintmFrameCount;50. privateintmFrames;51. 52. privateTextureRegionaryTextureRegion=null;53. privateTextureRegionmCurrentTextureRegion=null;54. 55. privateIOnAreaTouchListeneronAreaTouchListener;56. privateScenemScene;57. 58. /*59. *构造方法60. *parampX61. *parampY62. *paramscene63. *paramary

9、TextureSource传入TextureSource以构造64. */65. publicCustomTiledSprite(floatpX,floatpY,Scenescene,ITextureSourcearyTextureSource)66. this(pX,pY,scene,aryTextureSource,false);67. 68. 69. /*70. *构造方法71. *parampX72. *parampY73. *paramscene74. *paramaryTextureSource传入TextureSource以构造75. *parambFlippedHorizont

10、al图片是否水平翻转76. */77. publicCustomTiledSprite(floatpX,floatpY,Scenescene,ITextureSourcearyTextureSource,booleanbFlippedHorizontal)78. super(pX,pY,aryTextureSource0.getWidth(),aryTextureSource0.getHeight();79. this.mScene=scene;80. loadAnimationResource(scene,aryTextureSource,bFlippedHorizontal);81. 82

11、. 83. /*84. *构造方法85. *parampX86. *parampY87. *paramscene88. *paramaryTexture传入TextureRegion以构造89. */90. publicCustomTiledSprite(floatpX,floatpY,Scenescene,TextureRegionaryTexture)91. super(pX,pY,aryTexture0.getWidth(),aryTexture0.getHeight();92. this.mScene=scene;93. this.aryTextureRegion=aryTexture

12、;94. mCurrentTextureRegion=aryTextureRegion0;95. this.initBlendFunction();96. 97. 98. /*99. *注意,若使用此构造函数,请实例化精灵后,一定要使用100. *loadAnimationResource方法加载资源101. *parampX102. *parampY103. */104. publicCustomTiledSprite(floatpX,floatpY)105. super(pX,pY,0,0);106. 107. 108. /*109. *加载动画资源110. *author111. *pa

13、ramscene当前的场景112. *paramaryTextureSource资源113. *parambFlippedHorizontal是否水平翻转图片114. */115. publicvoidloadAnimationResource(Scenescene,ITextureSourcearyTextureSource,booleanbFlippedHorizontal)116. inttextureWidth=aryTextureSource0.getWidth();117. inttextureHeight=aryTextureSource0.getHeight();118. th

14、is.setWidth(textureWidth);119. this.setHeight(textureHeight);120. textureWidth=TextureUtils.getTextureCloseWidth(textureWidth);121. textureHeight=TextureUtils.getTextureCloseHeight(textureHeight);122. 123. aryTextureRegion=newTextureRegionaryTextureSource.length;124. for(inti=0;ithis.mAnimationDurat

15、ion)149. this.mAnimationProgress%=this.mAnimationDuration;150. if(this.mInitialLoopCount!=LOOP_CONTINUOUS)151. this.mLoopCount-;152. 153. 154. 155. if(this.mInitialLoopCount=LOOP_CONTINUOUS|this.mLoopCount=0)156. finalintcurrentFrameIndex=this.calculateCurrentFrameIndex();157. 158. if(this.mFrames=n

16、ull)159. this.setCurrentTileIndex(this.mFirstTileIndex+currentFrameIndex);160. else161. this.setCurrentTileIndex(this.mFramescurrentFrameIndex);162. 163. else164. this.mAnimationRunning=false;165. if(this.mAnimationListener!=null)166. this.mAnimationListener.onAnimationEnd(this);167. 168. 169. 170.

17、171. 172. publicvoidsetCurrentTileIndex(intindex)173. this.mCurrentTextureRegion=aryTextureRegionindex;174. this.updateVertexBuffer();175. mCurrentTextureRegion.getTextureBuffer().update();176. 177. 178. publicvoidstopAnimation()179. this.mAnimationRunning=false;180. 181. 182. publicvoidstopAnimatio

18、n(finalintpTileIndex)183. this.mAnimationRunning=false;184. this.setCurrentTileIndex(pTileIndex);185. 186. 187. privateintcalculateCurrentFrameIndex()188. finallonganimationProgress=this.mAnimationProgress;189. finallongframeEnds=this.mFrameEndsInNanoseconds;190. finalintframeCount=this.mFrameCount;

19、191. for(inti=0;ianimationProgress)193. returni;194. 195. 196. returnframeCount-1;197. 198. 199. publicCustomTiledSpriteanimate(finallongpFrameDurationEach)200. returnthis.animate(pFrameDurationEach,true);201. 202. 203. publicCustomTiledSpriteanimate(finallongpFrameDurationEach,finalbooleanpLoop)204

20、. returnthis.animate(pFrameDurationEach,(pLoop)?LOOP_CONTINUOUS:0,null);205. 206. 207. publicCustomTiledSpriteanimate(finallongpFrameDurationEach,finalintpLoopCount)208. returnthis.animate(pFrameDurationEach,pLoopCount,null);209. 210. 211. publicCustomTiledSpriteanimate(finallongpFrameDurationEach,f

21、inalbooleanpLoop,finalIAnimationListenerpAnimationListener)212. returnthis.animate(pFrameDurationEach,(pLoop)?LOOP_CONTINUOUS:0,pAnimationListener);213. 214. 215. publicCustomTiledSpriteanimate(finallongpFrameDurationEach,finalintpLoopCount,finalIAnimationListenerpAnimationListener)216. finallongframeDurations=newlongaryTextureRegion.length;217. Arrays.fill(frameDurations,pFrameDurationEach);218. returnthis

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1