/
render_to_sprite.js
42 lines (33 loc) · 1.21 KB
/
render_to_sprite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Learn cc.Class:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
sprite: {
default: null,
type: cc.Sprite
},
camera: {
default: null,
type: cc.Camera
}
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
let texture = new cc.RenderTexture();
texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height);
let spriteFrame = new cc.SpriteFrame();
spriteFrame.setTexture(texture)
this.sprite.spriteFrame = spriteFrame;
this.camera.targetTexture = texture;
},
// update (dt) {},
});