CVP认证学习笔记--李天宇016使用纹理缓存创建精灵
对于纹理的合理使用,可以降低IO的消耗,因此通过这节课后,以后加载精灵,最好都使用TextureCache.addImage();这样下次使用时将直接返回该纹理。引用之前加载的纹理可以减少GPU 与CPU 的内存消耗。顺便复习了一下上周学习的内容单点触摸和动作。附上API链接供参考:http://api.cocos.com/cn/de/d33/classcocos2d_1_1_textur
对于纹理的合理使用,可以降低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/
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐


所有评论(0)