Jump to content

Can't check speed of each moving sprite in group


Recommended Posts

So I'm moving sprites across the screen with moveToXY and continually checking the velocity (in the updates function) to see if the sprite makes it to its destination, like so:



if ((player.body.speed > 0) && (reachedDestination(player,destination))) {

    player.body.velocity.x = 0;
    player.body.velocity.y = 0;



This works fine, until I add the player to a group, and try to call this function on each member of the group:



    units.foreach(function(unit) {

    if ((unit.body.speed > 0) && (reachedDestination(unit,destination))) {

    unit.body.velocity.x = 0;
    unit.body.velocity.y = 0;



For some reason, unit.body.speed always shows up undefined. unit.body.velocity.x or y doesn't work either. I'm baffled as to why the function works on a single object but not on multiple. 
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...