cocos 图片放缩变化

原文链接: cocos 图片放缩变化

上一篇: 使用缓存和优先队列解决同步消息乱序的问题

下一篇: 使用 artipub 多平台发布博客

效果如下

up-7e7a462fc8ac431ecb2af96d2b8e9e965d0.gif

也可以实现类似10的次方的效果, 一边平移一边缩放, 模拟视角移动和上升

up-6ac04a2e514f08252c13fbf0a14de2bcd88.gif

简单放缩

const { ccclass, property } = cc._decorator;

const maxSize = 100;
const minSize = 20;

@ccclass
export default class NewClass extends cc.Component {
  @property(cc.Prefab)
  boxPrefab: cc.Prefab;

  boxList: cc.Node[] = [];
  onLoad() {
    const prevBtn: cc.Button = this.node.getChildByName("prev");
    const nextBtn: cc.Button = this.node.getChildByName("next");
    console.log(this.node, prevBtn);
    prevBtn.on(cc.Node.EventType.MOUSE_UP, () => this.left());
    nextBtn.on(cc.Node.EventType.MOUSE_UP, () => this.right());
    // 一共有5个box, 1,2,3,4,5
    // 3在中间最大
    // 2,4在两边小一点
    // 4,5 是在外面
    for (let i = 0; i < 3; i++) {
      const box = cc.instantiate(this.boxPrefab);
      this.node.addChild(box);
      box.height = i === 1 ? maxSize : minSize;
      box.width = i === 1 ? maxSize : minSize;
      box.x = (i - 1) * 200;
      this.boxList[i] = box;
    }
  }
  right() {
    cc.tween(this.boxList[2])
      .to(1, {
        width: 0,
        height: 0,
        x: 400,
      })
      .start();
    cc.tween(this.boxList[1])
      .to(1, {
        width: 20,
        height: 20,
        x: 200,
      })
      .start();
    cc.tween(this.boxList[0])
      .to(1, {
        width: 100,
        height: 100,
        x: 0,
      })
      .start();
    this.boxList[2] = this.boxList[1];
    this.boxList[1] = this.boxList[0];
    const box = cc.instantiate(this.boxPrefab);
    this.node.addChild(box);
    box.height = 0;
    box.width = 0;
    box.x = -400;
    this.boxList[0] = box;
    cc.tween(box)
      .to(1, {
        width: 20,
        height: 20,
        x: -200,
      })
      .start();
  }
  left() {
    console.log("left");
    cc.tween(this.boxList[0])
      .to(1, {
        width: 0,
        height: 0,
        x: -400,
      })
      .start();
    cc.tween(this.boxList[1])
      .to(1, {
        width: 20,
        height: 20,
        x: -200,
      })
      .start();
    cc.tween(this.boxList[2])
      .to(1, {
        width: 100,
        height: 100,
        x: 0,
      })
      .start();
    this.boxList[0] = this.boxList[1];
    this.boxList[1] = this.boxList[2];
    const box = cc.instantiate(this.boxPrefab);
    this.node.addChild(box);
    box.height = 0;
    box.width = 0;
    box.x = 400;
    this.boxList[2] = box;
    cc.tween(box)
      .to(1, {
        width: 20,
        height: 20,
        x: 200,
      })
      .start();
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值