Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polished_project_ts在creator 2.1.0下运行拾取不到星星的bug #22

Open
whg333 opened this issue Jan 28, 2019 · 0 comments
Open

Comments

@whg333
Copy link

whg333 commented Jan 28, 2019

因为Player.ts下的getCenterPos返回的是只有x和y的cc.v2

getCenterPos () {
    //var centerPos = cc.v2(this.node.x, this.node.y + this.node.height/2);
    //必须改成下面带有z坐标的v3,上面注释掉的v2不行
    var centerPos = cc.v3(this.node.x, this.node.y + this.node.height/2, 0);
    return centerPos;
}

从而导致如下Star.ts里getPlayerDistance 计算距离dist的结果为NaN了

getPlayerDistance () {
    // 根据 player 节点位置判断距离
    var playerPos = this.game.player.getCenterPos();
    // 根据两点位置计算两点之间距离
    var dist = this.node.position.sub(playerPos).mag();
    return dist;
 }

debug看了下是因为cc.Node的getPosition返回的是Vec3而不是Vec2,所以this.node.position.sub(playerPos).mag()结果就是NaN了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant