首页 cocoscameratargetTexture应用之小地图与残影实现

cocoscameratargetTexture应用之小地图与残影实现

举报
开通vip

cocoscameratargetTexture应用之小地图与残影实现     cocoscameratargetTexture应用之小地图与残影实现                  1.效果 2.原理        残影与小地图原理是应用camera的属性targetTexture实现的,因为targetTexture是指定摄像机将拍摄到的东西渲染到指定的RenderTexture上面,通过对指定的RenderTexture进行特殊处理来达到残影的效果。这么做的好处是如果我想要很多东西出现残影、只需要创建出残影的一组图片就能对多个物体进行统一的残影显示。3代码const{cccl...

cocoscameratargetTexture应用之小地图与残影实现
     cocoscameratargetTexture应用之小地图与残影实现                  1.效果 2.原理        残影与小地图原理是应用camera的属性targetTexture实现的,因为targetTexture是指定摄像机将拍摄到的东西渲染到指定的RenderTexture上面,通过对指定的RenderTexture进行特殊处理来达到残影的效果。这么做的好处是如果我想要很多东西出现残影、只需要创建出残影的一组图片就能对多个物体进行统一的残影显示。3代码const{ccclass,property}=cc._decorator;@ccclassexportdefaultclassMoveShadowextendscc.Component{@property(cc.Sprite)shadow_sprite:cc.Sprite=null;@property(cc.Camera)shadow_camera:cc.Camera=null;@property(cc.Node)shadowNode:cc.Node=null;@property(cc.Node)privatecanvas_node:cc.Node=null;@property(cc.Sprite)privatemap_spirte:cc.Sprite=null;@property(cc.Camera)privatemap_Camera:cc.Camera=null;start(){this.schedule(this.moveShadow,0.1,cc.macro.REPEAT_FOREVER);this.shadow_sprite.node.on(cc.Node.EventType.TOUCH_MOVE,this.heroMove,this);//创建一个RenderTextureletrenderTexture=newcc.RenderTexture();//初始化大小renderTexture.initWithSize(this.canvas_node.width,this.canvas_node.height);//创建一个SpriteFrameletspriteFrame=newcc.SpriteFrame();spriteFrame.setTexture(renderTexture);//设置camera将渲染的内容制定到新建的RenderTexturethis.shadow_camera.targetTexture=renderTexture;//将新建的SpriteFrame设置给显示残影的图片this.shadowNode.children.map((item,index)=>{index=this.shadowNode.childrenCount-index-1;//由于坐标系的问题需要将y轴进行反转item.scaleY=-1;item.opacity=200-30*index;item.getComponent(cc.Sprite).spriteFrame=spriteFrame;});//小地图原来一样lettexture_map=newcc.RenderTexture();texture_map.initWithSize(this.map_spirte.node.width,this.map_spirte.node.height);letsf_map=newcc.SpriteFrame();sf_map.setTexture(texture_map);this.map_Camera.targetTexture=texture_map;this.map_spirte.node.scaleY=-1;this.map_spirte.spriteFrame=sf_map;cc.tween(this.shadow_sprite.node).repeatForever(cc.tween().to(3,{angle:180}).to(3,{angle:0})).start();}onDestroy(){this.unschedule(this.moveShadow);}privateheroMove(event:cc.Event.EventTouch){this.shadow_sprite.node.setPosition(this.node.convertToNodeSpaceAR(event.getLocation()));}/***移动动画*/privatemoveShadow(){this.shadowNode.children.map((item,index)=>{index=this.shadowNode.childrenCount-index-1;lettargetPos=this.shadow_sprite.node.position;if(item.position.sub(targetPos).mag()<0.5){return;}item.stopAllActions();item.runAction(cc.moveTo(index*0.1+0.2,newcc.Vec2(targetPos.x,targetPos.y)));});}} -全文完-
本文档为【cocoscameratargetTexture应用之小地图与残影实现】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
资教之佳
暂无简介~
格式:doc
大小:261KB
软件:Word
页数:9
分类:互联网
上传时间:2023-06-19
浏览量:10