Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
engine
CocosCreator v2.1.2
Explanation
In the new version CocosCreator of material for us to join the system, and have built-in resources for our use in the new project.
Let's look at what the material is grayed out!
step
First, dragged into a picture.
Then get two buttons.
Then let us create a new script!
(TS and JS care of small partners, I have given! Just the same, ha ha.)
First JS
cc.Class({
extends: cc.Component,
properties: {
sprite: cc.Sprite,
m0: cc.Material,
m1: cc.Material
},
click_0 () {
this.sprite.setMaterial(0, this.m0);
},
click_1 () {
this.sprite.setMaterial(0, this.m1);
}
});
TS
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Sprite) sprite: cc.Sprite = null;
@property(cc.Material) m0: cc.Material = null;
@property(cc.Material) m1: cc.Material = null;
click_0 () {
this.sprite.setMaterial(0, this.m0);
}
click_1 () {
this.sprite.setMaterial(0, this.m1);
}
}
Then we put the first ordinary material dragged, dragged into a second set of gray material.
test
Learned of it, O (∩_∩) O ~~
How kind, simple!
Add my blog :( QQ group inside the project, the group has a file oh)
706176551
we study together!