Is it possible to use collidePoint in a world update method?


(Nate ) #1

Title says what I am wondering… I am still messing around with making text clickable, this is what I have.

Variables:

   private var selectText:Text = new Text("Option One");  
   private var clickMe:Entity; 

In my world begin()

   clickMe = addGraphic(selectText);
   clickMe.setHitbox(selectText.textWidth, selectText.textHeight);

In my world update()

if (collidePoint(selectText.x, selectText.y, this.mouseX, this.mouseY))
    {
       if (Input.mouseReleased)click();
    }
    super.update();

My click()

public function click():void
   {
      trace("clicking");
   }

I keep getting all sorts of errors from the collidePoint function which is telling me it only is expecting three parameters which I know is not correct… also I have tried passing it clickMe.x and clickMe.y but that doesn’t work because I am setting it equal to a string?

I am lost any help would be great! If I take out the update method the text appears with a hitbox around it, I am just trying to make it actually do something when I click the hitbox! Thanks guys!


(Jonathan Stoler) #2

World.collidePoint does take three parameters: a string for the type you want to collide against, an x coordinate, and a y coordinate. The implementations for World.collidePoint() and Entity.collidePoint() are different.


(Nate ) #3

Thank you, I had no idea… well awkward… lol

Would I be able to do Entity.collidePoint() inside of my World class update method?

EDIT: I did clickMe.collidePoint and it works fine now… Sorry for the confusion and thank you for the schooling!