cc.Sprite

 cc.Sprite

1: 游戏中显示一个图片,通常我们把这个叫做”精灵” sprite;
2: cocos creator如果需要显示一个图片,那么需要在节点上挂一个精灵组件,为这个组件指定要显示的图片(SpriteFrame); 
3: 显示一个图片的步骤:
     (1) 创建一个节点;
     (2) 添加一个组件;
     (3) 要显示的图片(SpriteFrame)拖动到SpriteFrame;
     (4) 配置图片的SIZE_MODE:  
             a: CUSTOM 大小和CCNode的大小一致;
             b: RAW 原始的图片大小;
             c:  TRIMMED 大小为原始图片大小, 显示的内容是裁剪掉透明像素后的图片;
     (5) trim: 是否裁剪掉 图片的透明区域, 如果勾选,就会把完全透明的行和列裁掉, 做帧动画的时候,我们一般是用原始大小不去透明度,动画,不至于抖动;
4: 精灵更换spriteFame;
5: 快捷创建带精灵组件的节点;

 

    properties: {

        // 编辑器, 代码, 资源的动态加载spriteFrame对象, 
        sprite_frame: {
            default: null,
            type: cc.SpriteFrame,
        },

        // 编辑器绑定你要的组件;
        sprite: {
            default: null,
            type: cc.Sprite,
        },
    },

    // use this for initialization
    onLoad: function () {
        this.sp = this.getComponent(cc.Sprite); 
        this.sp.spriteFrame = this.sprite_frame;
    }

 

图片模式
1: simple: 精灵最普通的模式, 选择该模式后,图片将缩放到指定的大小;
2: Tiled: 平铺模式, 图片以平铺的模式,铺地板砖的模式,铺到目标大小上;
3: Slice: 九宫格模式,指定拉伸区域;
4: Filled: 设置填充的方式(圆,矩形),可以使用比例来裁剪显示图片(只显示的比例);

 

九宫格的使用
1: 指定拉伸区域, 让图片在拉伸的时候某些区域不会改变;比如圆角,聊天气泡等;
2: 九宫格能省图片资源, (对话框);
3: 编辑九宫格,来制定缩放区域;
4: 体会对话框背景的九宫拉伸;  

 

Filled模式
1: 配置Filled模式
2: 配置Filled模式, 设置为Radius参数;
3: 配置Radius的参数模式,
  中心: 位置坐标(0, 1小数), (0, 0)左下脚, (1, 1) 右上角 (0.5, 0.5) 中心点;
  Fill Start 开始的位置: 0 ~1, 右边中心点开始,逆时针走;  
  Fill Range: 填充总量(0, 1];
  FillRange为正,那么就是逆时针,如果为负,那么就是顺时针;
4: 个性化时间进度条案例;
5: 游戏中道具的时间进度显示都可以;

 

    properties: {

        sprite: {
            default: null,
            type: cc.Sprite,
        },

        action_time: 15,
    },

    // use this for initialization
    onLoad: function () {
        // 获取组件的实例,代码获取,编辑器绑定
        var node = this.node.getChildByName("time_bar");
        this.sp = node.getComponent(cc.Sprite);
        // end 

        // this.now_time = 0;
        this.now_time = this.action_time;
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        
        this.now_time += dt;
        var percent = this.now_time / this.action_time; // -->百分比
        if (percent >= 1)  {
            percent = 1;
            this.now_time = 0; // 重新开始
        }

        this.sp.fillRange = percent;        

    },

 

转载于:https://www.cnblogs.com/he-bo/p/9900146.html

constructor(name: string); constructor(); constructor(csNode?: CS.UnityEngine.GameObject, followCSActiveInHierarchy?: boolean, isCanvas?: boolean); constructor(arg1?: CS.UnityEngine.GameObject | string, followCSActiveInHierarchy: boolean = false, isCanvas: boolean = false) { let name: string | undefined = undefined; if (typeof arg1 === "string") { name = arg1; } super(name); let needSync = false; let csNode: CS.UnityEngine.GameObject | undefined; if (typeof arg1 === "string") { csNode = Node.newCSNode(arg1); } else { csNode = arg1; if (csNode) { needSync = true; if (followCSActiveInHierarchy) { this.activeInHierarchy = csNode.activeInHierarchy; } } } if (!csNode) { csNode = Node.newCSNode("cc_unknown_node"); } this.cs = csNode; this.active = csNode.activeSelf; let newProgressBarComp: ProgressBar | null = null; { if (this.hasCSComponentByCS(CS.UnityEngine.RectTransform)) { this.addComponent("cc.UITransform"); } // init component if (this.hasCSComponentByCS(CS.UnityEngine.SpriteRenderer)) { const spriteCom = this.addComponent("cc.Sprite") as Sprite; if (spriteCom) { spriteCom.initFromExistsCSNode(); } } if (this.hasCSComponentByCS(CS.UnityEngine.UI.Button)) { this.addComponent("cc.Button"); } if (this.hasCSComponentByCS(CS.TMPro.TextMeshPro) || this.hasCSComponentByCS(CS.UnityEngine.UI.Text)) { this.addComponent("cc.Label"); } if (this.hasCSComponentByCS(CS.Bridge.ProgressBarConfig)) { newProgressBarComp = this.addComponent("cc.ProgressBar") as ProgressBar; } if (this.hasCSComponentByCS(CS.UnityEngine.Animator)) { this.addComponent("cc.Animation") as Animation; } if (this.hasCSComponentByCS(CS.UnityEngine.TrailRenderer)) { const comp = this.addComponent("cc.MotionStreak") as MotionStreak; comp.cs = this.getCSComponentByCS(CS.UnityEngine.TrailRenderer)!; } if ( this.hasCSComponentByCS(CS.UnityEngine.UI.HorizontalLayoutGroup) || this.hasCSComponentByCS(CS.UnityEngine.UI.VerticalLayoutGroup) || this.hasCSComponentByCS(CS.UnityEngine.UI.GridLayoutGroup) ) { this._hasCSLayoutGroupComponent = true; } } if (needSync) { this._syncUnityNodeStatusToNode(isCanvas); } this._syncCSHierarchy(false, followCSActiveInHierarchy); if (newProgressBarComp) { newProgressBarComp.initByCSProgressBarConfig(this, this.getCSComponentByCS(CS.Bridge.ProgressBarConfig)!); } // eslint-disable-next-line @typescript-eslint/no-unused-expressions this.uuid; // refresh uuid this.on(NodeEventType.ACTIVE_IN_HIERARCHY_CHANGED, (node: Node) => { this._setActivateNode(node.active); // eslint-disable-next-line @typescript-eslint/no-unused-expressions this.uuid; // refresh uuid }); this.on(NodeEventType.COMPONENT_ADDED, (com: Component) => { // 清除缓存 this._lastUITransform = undefined; this._lastSprite = undefined; this._lastMask = undefined; this._lastLrot = null; this._markRenderOrderDirty(); }); }帮我解释一下这段代码
03-08
[ { "__type__": "cc.SceneAsset", "_name": "entry", "scene": { "__id__": 1 } }, { "__type__": "cc.Scene", "_name": "New Node", "_active": false, "autoReleaseAssets": true, "_children": [ { "__id__": 2 }, { "__id__": 22 }, { "__id__": 30 } ], "_anchorPoint": { "__type__": "cc.Vec2", "x": 0, "y": 0 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49" }, { "__type__": "cc.Node", "_name": "Canvas", "_id": "a5esZu+45LA5mBpvttspPD", "_children": [ { "__id__": 3 }, { "__id__": 5 }, { "__id__": 8 }, { "__id__": 10 } ], "_components": [ { "__id__": 18 }, { "__id__": 19 }, { "__id__": 20 }, { "__id__": 21 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 375, 667, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_parent": { "__id__": 1 } }, { "__type__": "cc.Node", "_name": "Main Camera", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 4 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Camera", "_cullingMask": -31, "_clearFlags": 4, "_depth": -1, "node": { "__id__": 3 } }, { "__type__": "cc.Node", "_name": "Main Camera", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 6 }, { "__id__": 7 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Camera", "_cullingMask": -2, "_clearFlags": 7, "_depth": -2, "node": { "__id__": 5 } }, { "__type__": "05b01LKIy1MpJ/22zpE6jci", "node": { "__id__": 5 } }, { "__type__": "cc.Node", "_name": "background", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 9 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1650 } }, { "__type__": "cc.Sprite", "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 8 } }, { "__type__": "cc.Node", "_name": "AIControl", "_parent": { "__id__": 2 }, "_children": [ { "__id__": 11 }, { "__id__": 14 } ], "_components": [ { "__id__": 16 }, { "__id__": 17 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Node", "_name": "block", "_parent": { "__id__": 10 }, "_components": [ { "__id__": 12 }, { "__id__": 13 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 11 } }, { "__type__": "cc.BlockInputEvents", "node": { "__id__": 11 } }, { "__type__": "cc.Node", "_name": "模拟鼠标点", "_active": false, "_parent": { "__id__": 10 }, "_components": [ { "__id__": 15 } ], "_contentSize": { "__type__": "cc.Size", "width": 80, "height": 80 } }, { "__type__": "cc.Sprite", "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "f9d4a564-eab2-4b30-807f-44ebc6c3c030" }, "node": { "__id__": 14 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 10 } }, { "__type__": "71c49BSgP9IR7Zj4hKWyzrQ", "blockNode": { "__id__": 11 }, "shuBiaoDian": { "__id__": 14 }, "node": { "__id__": 10 } }, { "__type__": "cc.Canvas", "_fitWidth": true, "_fitHeight": false, "_designResolution": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "node": { "__id__": 2 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 2 } }, { "__type__": "46eeftVLAxEyrbvMwaNsA2p", "node": { "__id__": 2 } }, { "__type__": "da803qpn0xMgrpoqN4fnvfq", "_name": "scene_root", "node": { "__id__": 2 } }, { "__type__": "cc.Node", "_name": "New Node", "_id": "eb9Em8CmRJbLAnaaIWi6pZ", "_parent": { "__id__": 1 }, "_children": [ { "__id__": 23 } ], "_components": [ { "__id__": 28 }, { "__id__": 29 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 375, 667, 0, 0, 0, 0, 1, 1, 1, 1 ] } }, { "__type__": "cc.Node", "_name": "$node_img", "_children": [ { "__id__": 24 } ], "_components": [ { "__id__": 26 }, { "__id__": 27 } ], "_color": { "__type__": "cc.Color", "a": 255, "b": 0, "g": 0, "r": 0 }, "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_parent": { "__id__": 22 } }, { "__type__": "cc.Node", "_name": "New Label", "_parent": { "__id__": 23 }, "_components": [ { "__id__": 25 } ], "_contentSize": { "__type__": "cc.Size", "width": 180, "height": 40.32 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 275.821, -642.446, 0, 0, 0, 0, 1, 1, 1, 1 ] } }, { "__type__": "cc.Label", "_string": "加载中。。。", "_fontSize": 30, "_lineHeight": 32, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 24 }, "_N$string": "加载中。。。" }, { "__type__": "cc.Sprite", "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" }, "node": { "__id__": 23 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "_originalWidth": 100, "_originalHeight": 100, "node": { "__id__": 23 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 22 } }, { "__type__": "71237pk2XpDzaXDhWTLOlQW", "auto_ui": { "__type__": "LodingGuodu_UIBindings", "node_img": { "__id__": 23 } }, "node": { "__id__": 22 } }, { "__type__": "cc.Node", "_name": "New Button", "_active": false, "_id": "a9wI4OoQ5E8Z4gjcWqiUNS", "_children": [ { "__id__": 31 } ], "_components": [ { "__id__": 36 }, { "__id__": 37 }, { "__id__": 38 }, { "__id__": 40 } ], "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 80 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 64.436, 49.714, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_parent": { "__id__": 1 } }, { "__type__": "cc.Node", "_name": "Background", "_objFlags": 512, "_parent": { "__id__": 30 }, "_children": [ { "__id__": 32 } ], "_components": [ { "__id__": 34 }, { "__id__": 35 } ], "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 80 } }, { "__type__": "cc.Node", "_name": "Label", "_objFlags": 512, "_parent": { "__id__": 31 }, "_components": [ { "__id__": 33 } ], "_color": { "__type__": "cc.Color", "a": 255, "b": 0, "g": 0, "r": 0 }, "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 40 } }, { "__type__": "cc.Label", "_string": "查看内存", "_fontSize": 20, "_enableWrapText": false, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$overflow": 1, "_N$cacheMode": 1, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 32 }, "_N$string": "查看内存" }, { "__type__": "cc.Sprite", "_type": 1, "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "node": { "__id__": 31 } }, { "__type__": "cc.Widget", "alignMode": 0, "_alignFlags": 45, "_originalWidth": 100, "_originalHeight": 40, "node": { "__id__": 31 } }, { "__type__": "cc.Button", "_N$transition": 2, "_N$normalColor": { "__type__": "cc.Color", "a": 255, "b": 230, "g": 230, "r": 230 }, "_N$pressedColor": { "__type__": "cc.Color", "a": 255, "b": 200, "g": 200, "r": 200 }, "_N$disabledColor": { "__type__": "cc.Color", "a": 200, "b": 120, "g": 120, "r": 120 }, "_N$normalSprite": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "_N$pressedSprite": { "__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a" }, "_N$hoverSprite": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "_N$disabledSprite": { "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" }, "_N$target": { "__id__": 31 }, "node": { "__id__": 30 } }, { "__type__": "54bdek3CLtOK7ESMMaON2u0", "node": { "__id__": 30 } }, { "__type__": "cc.Button", "clickEvents": [ { "__id__": 39 } ], "node": { "__id__": 30 } }, { "__type__": "cc.ClickEvent", "_componentId": "54bdek3CLtOK7ESMMaON2u0", "handler": "getImageMemory", "target": { "__id__": 30 } }, { "__type__": "54bdek3CLtOK7ESMMaON2u0", "node": { "__id__": 30 } } ]这个是我的项目入口吗
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值