How can I add hitbox to an Image.createRect?


(Nate ) #1

I have a class where I make a rectangle and I would like to have it clickable but I can’t seem to figure this out. I just want the rectangle to be clicked. Rectangle is declared as an Image.

    rectangle = Image.createRect(500, 50, 0xFF0000);
    addGraphic(rectangle);

This is my update method:

override public function update():void
	{
		if (collidePoint(rectangle.x, rectangle.y, world.mouseX, world.mouseY))
		{
			if (Input.mouseReleased) click();
		}
	}
	
	public function click():void
	{
		trace("clicking");
	}

(Nate ) #2

I figured it out by setting rectangle = graphic then setting a hit box!