cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
7.16k stars 1.83k forks source link

[bug] Tween property type was changed to plain object #17186

Closed dumganhar closed 3 months ago

dumganhar commented 3 months ago

Currently, if we tween the custom type MyVec2 like the following.

    class MyVec2 {
        constructor(x = 0, y = 0) {
            this.x = x;
            this.y = y;
        }
        x = 0;
        y = 0;
    }

    class MyTarget {
        pos = new MyVec2();
    }

    const target = new MyTarget();
    tween(target).to(1, { pos: new MyVec2(100, 100) }).start();
    ......
    // run 60 frames

    // target.pos will be `{ x: 100, y: 100}` which is a plain object , but it should be an instance of `MyVec2` of which type should not be changed.