怎么获得由预制资源所产生的节点的y坐标?

比如说我有一个预制资源APrefab,
在onload运行了如下代码
var A1 = cc.instantiate(this.APrefab);
this.node.addChild(A1);
A1.setPosition(this.A1Position());
这个APrefab是一个会在Y轴上按一定速度运动的资源,那么之后要怎样每帧获取A1的Y坐标呢?无论是用
this.APrefab.getPositionY()
this.APrefab.node.getPositionY()
this.A1.getPositionY()
this.A1.node.getPositionY()
试过好几种,都会报错呢

报了什么错?

这样就可以

var y = this.A1.y;

TypeError: this.A1 is undefined
onload是正常的,A1有按我设置的出现在模拟器中
我在update中写的是
var aaaa = this.A1.getPositionY();
var bbbb = this.Player.getPositionY();
if (aaaa - bbbb > 1500) {
this.A1.destroy();
this.SpawnA1();
}
试着按你说的,改成var aaaa = this.A1.y;结果还是提示this.A1 is undefined
小白我是第一次做游戏,图也画了,p也p完了,结果被这些脚本问题卡着,表示不知道问题出在哪里···

你没有对 this.A1 赋值吧。。。

onLoad 里面设置

this.A1 = A1;

嗯,按你说的做,终于成功了,非常感谢!但是怎么理解这个this.A1 = A1呢?像我这里有个Player节点,这个节点不用this.Player = Player,却能取到它的Y坐标。(在properties传入资源的时候,Player的type是node,A1的是prefab,是不是和这个有关呢?)

先仔细学习一下 js 的语法吧,那里面都有介绍的