制作一款HTML5 RPG游戏引擎教程(三).docx





《制作一款HTML5 RPG游戏引擎教程(三).docx》由会员分享,可在线阅读,更多相关《制作一款HTML5 RPG游戏引擎教程(三).docx(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、今天我们先看实现后的代码:javascriptview plaincopy1. varcurtain=newLCurtainSample3();2. addChild(curtain);就两行,已经达到最简单了。那么接下来就来看看是如何实现它的。由于有很多种幕布效果,因此我只为大家实现常用的3种作为sample,大家可以借鉴一下,写出更美观的幕布。1,LCurtainSample1这个是一个基础幕布,效果是左右合拢。看看构造器中的代码:javascriptview plaincopy1. functionLCurtainSample1(speed,onClosing,onComplete)2.
2、 vars=this;3. base(s,LSprite,);4. if(!speed)speed=LStage.width/100;5. if(!onClosing)6. s.onClosing=function();7. else8. s.onClosing=onClosing;9. 10. if(!onComplete)11. s.onComplete=function();12. else13. s.onComplete=onComplete;14. 15. s.mode=close;16. s.width1=0;17. s.width2=0;18. s.isDoClosing=fal
3、se;19. s.speed=speed;20. s.addEventListener(LEvent.ENTER_FRAME,s.onshow);21. 这个类是继承自LSprite类,有三个参数,分别是:幕布合拢/展开的速度,幕布合拢后调用此函数,幕布展开后调用此函数。mode 属性顾名思义,它是用来表示接下来的工作的。当为close时说明要合拢。我们在其中定义两个属性:width1,width2,它们分别表示两块幕布显示的宽度,通过调节宽度来实现合拢。另外定义了isDoClosing来判断是否已经合拢。用speed来保存幕布移动速度,方便以后使用。然后我们给自身加一个时间轴事件,在时间轴事
4、件中调用onshow方法绘画幕布。onshow中的完整代码:javascriptview plaincopy1. LCurtainSample1.prototype.onshow=function(s)2. s.graphics.clear();3. s.graphics.drawRect(1,black,0,0,s.width1,LStage.height,true,black);4. s.graphics.drawRect(1,black,LStage.width-s.width2,0,s.width2,LStage.height,true,black);5. if(s.width1=LS
5、tage.width/2)6. s.mode=open;7. if(s.isDoClosing=false)8. s.onClosing();9. s.isDoClosing=true;10. 11. 12. if(s.mode=close)13. s.width1+=s.speed;14. s.width2+=s.speed;15. elseif(s.mode=open)16. s.width1-=s.speed;17. s.width2-=s.speed;18. if(s.width1=LStage.height/2)30. s.mode=open;31. if(s.isDoClosing
6、=false)32. s.onClosing();33. s.isDoClosing=true;34. 35. 36. if(s.mode=close)37. s.height1+=s.speed;38. s.height2+=s.speed;39. elseif(s.mode=open)40. s.height1-=s.speed;41. s.height2-=s.speed;42. if(s.height1=LStage.height/2)34. s.mode=open;35. if(s.isDoClosing=false)36. s.onClosing();37. s.isDoClosi
7、ng=true;38. 39. 40. if(s.mode=close)41. s.height1+=s.speed;42. s.height2+=s.speed;43. s.width1+=s.speed;44. s.width2+=s.speed;45. elseif(s.mode=open)46. s.height1-=s.speed;47. s.height2-=s.speed;48. s.width1-=s.speed;49. s.width2-=s.speed;50. if(s.height10)51. s.mode=stop;52. 53. elseif(s.mode=stop)
8、54. s.graphics.clear();55. s.removeEventListener(LEvent.ENTER_FRAME,s.onshow);56. s.onComplete();57. 58. 效果如下:4,切换场景上面我们实现了幕布类,接下来就要实战一下了。首先我们找几张图片:还有一张接着就用到了我们的幕布类实现切换场景,代码如下:javascriptview plaincopy1. 2. 3. 4. 5. Curtain幕布6. 7. 8. 9. init(30,legend,600,400,main);10. varbackindex=1;11. varloadlist=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 制作一款HTML5 RPG游戏引擎教程三 制作 一款 HTML5 RPG 游戏 引擎 教程

限制150内