简体   繁体   English

移相器-Game.Physics.Arcade.moveToPointer不起作用?

[英]Phaser - Game.Physics.Arcade.moveToPointer not working?

I am trying to move one sprite to the center of another sprite, which is a child of a Group object, using game.physics.arcade.moveToPointer(sprite,speed,pointer,maxTime). 我试图使用game.physics.arcade.moveToPointer(sprite,speed,pointer,maxTime)将一个精灵移动到另一个精灵的中心,另一个精灵是Group对象的子代。

Here is an example: game.physics.arcade.moveToPointer(ball,100,cups.children[0].body.center, 1000); 这是一个示例:game.physics.arcade.moveToPointer(ball,100,cups.children [0] .body.center,1000);

I am calling this in the create function, after creating my sprite called ball, a group called cups, and the children of that group. 在创建我的名为ball的精灵,一个名为cups的组以及该组的子级之后,我在create函数中调用了此函数。 I am also enabling physics on all of them, so that they can be moved. 我还对所有这些启用了物理学,以便可以移动它们。

I also tried moving it to the update function, but my ball still does not move towards the center of cups.children[0] 我也尝试将其移至更新功能,但我的球仍未移向cups.children [0]的中心

What am I doing wrong? 我究竟做错了什么?

UPDATE: Using 更新:使用

ball.rotation = game.physics.arcade.moveToPointer(ball,100,game.input.activePointer,1000; 

In my update() function will move the ball to the mouse, yet cups.children[index].body.center does not work, even though it is also a Pointer object, like game.input.activePointer. 在我的update()函数中,球将移到鼠标上,尽管cups.children [index] .body.center仍然是Pointer对象(例如game.input.activePointer),但它不起作用。 I have verified with console.log(cups.children[0].body.center) that it is not null.... 我已经用console.log(cups.children [0] .body.center)验证了它不为null。

Well, I found a work around by using game.physics.arcade.moveToObject(sprite,targetSprite,speed); 好吧,我通过使用game.physics.arcade.moveToObject(sprite,targetSprite,speed);找到了解决方法。

Will mark this as the answer for anyone else that might have the same problem with moveToPointer 会将其标记为对moveToPointer可能存在相同问题的其他任何人的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM