CVP认证学习笔记--李天宇016使用纹理缓存创建精灵
来源:互联网 发布:linux终端界面 编辑:程序博客网 时间:2024/06/05 05:05
对于纹理的合理使用,可以降低IO的消耗,因此通过这节课后,以后加载精灵,最好都使用TextureCache.addImage();这样下次使用时将直接返回该纹理。引用之前加载的纹理可以减少GPU与CPU的内存消耗。顺便复习了一下上周学习的内容单点触摸和动作。附上API链接供参考:http://api.cocos.com/cn/de/d33/classcocos2d_1_1_texture_cache.html#details
代码如下:
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
this._super();
var size = cc.winSize;
var bg_texture = cc.textureCache.addImage("res/bg.jpg");
var hero1_texture = cc.textureCache.addImage("res/h2.png");
var bg = new cc.Sprite(bg_texture);
this.addChild(bg,0);
bg.setPosition(size.width/2,size.height/2);
var hero = new cc.Sprite(hero1_texture);
hero.setTag(100);
this.addChild(hero,1);
hero.setScale(0.1);
var act1 = new cc.RotateTo(2,180);
var act2 = new cc.FadeTo(2,1);
var act3 = new cc.FadeIn(2);
var act4 = new cc.RotateTo(2,360);
hero.runAction(cc.sequence(act1,act2,act3,act4));
hero.setPosition(200,200);
return true;
},
onEnter:function(){
this._super();
cc.eventManager.addListener({
event:cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches:true,
onTouchBegan:this.touchbegan.bind(this),
onTouchMoved:this.touchmoved,
onTouchEnded:this.touchended,
},this);
},
touchbegan:function(touch,event){
var nowhero = event.getCurrentTarget().getChildByTag(100);
var act = new cc.moveTo(2,touch.getLocationX(),touch.getLocationY());
nowhero.runAction(act);
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
最后附上作业链接:
http://www.cocoscvp.com/usercode/2016_04_22/9a5d3f6b39c64a368256ecc5b90124f54625a576/
- CVP认证学习笔记--李天宇016使用纹理缓存创建精灵
- CVP认证学习笔记--李天宇018spriteBatchNode使用
- CVP认证学习笔记--李天宇021纹理打包文件读取
- CVP认证学习笔记--李天宇001添加文字层
- CVP认证学习笔记--李天宇002添加图片层
- CVP认证学习笔记--李天宇004实现自定义场景
- CVP认证学习笔记--李天宇006场景切换特效
- CVP认证学习笔记--李天宇011节点的Action
- CVP认证学习笔记--李天宇012组合动作
- CVP认证学习笔记--李天宇014点击英雄
- CVP认证学习笔记--李天宇015实现绘图节点
- CVP认证学习笔记--李天宇020实现切图帧动画
- CVP认证学习笔记--李天宇022使用animationEditor编辑帧动画
- CVP认证学习笔记--李天宇023使用animationEditor编辑骨骼动画
- CVP认证学习笔记--李天宇026对数组的使用
- CVP认证学习笔记--李天宇003实现文本菜单层
- CVP认证学习笔记--李天宇005实现多场景切换
- CVP认证学习笔记--李天宇007节点的锚点和坐标
- 169. Majority Element
- 随机验证码javascript
- 京东三级菜单
- CVP认证学习笔记--李天宇013在Node的生命周期和图层种处理触摸
- CVP认证学习笔记--李天宇015实现绘图节点
- CVP认证学习笔记--李天宇016使用纹理缓存创建精灵
- 约瑟夫环
- CVP认证学习笔记--李天宇017图片加载的进度实现
- CVP认证学习笔记--李天宇018spriteBatchNode使用
- CVP认证学习笔记--李天宇019实现帧动画处理
- CVP认证学习笔记--李天宇020实现切图帧动画
- CVP认证学习笔记--李天宇021纹理打包文件读取
- CVP认证学习笔记--李天宇022使用animationEditor编辑帧动画
- spring boot 学习笔记(005)提交json对象