Hi. I am displaying text when the mouse hovers above some buttons.
package Talents
{
import net.flashpunk.Entity;
import net.flashpunk.Graphic;
import net.flashpunk.graphics.Graphiclist;
import net.flashpunk.graphics.Text;
import net.flashpunk.Mask;
import net.flashpunk.graphics.Stamp;
import net.flashpunk.utils.Input;
import net.flashpunk.FP;
import flash.geom.Point;
public class Agility_Dagger extends Entity
{
protected var normal:Graphic;
protected var hover:Graphic;
protected var down:Graphic;
protected var clicked:Boolean = false;
protected var label:Text;
protected var normalStamp:Stamp = new Stamp(Assets.AGILITY_DAGGER);
protected var text:String = "Dagger \n Testtesttesttest."
public function Agility_Dagger(p:Point)
{
x = p.x;
y = p.y;
//Assign the button graphic states to variables
normal = normalStamp;
hover = new Stamp(Assets.AGILITY_DAGGER_HOVER);
down = new Stamp(Assets.AGILITY_DAGGER_DOWN);
graphic = normal;
setHitboxTo(normalStamp);
}
override public function update():void
{
super.update();
if (graphic != normal)
{
label = new Text(text, 10, 70, { size: 30, color: 0xFFFFFF, width: normalStamp.width - 30, align: "center" } );
}else
{
label = null;
}
//If the mouse is colliding with this button
if (collidePoint(x, y, world.mouseX, world.mouseY))
{
if (Input.mousePressed) clicked = true;
if (clicked) graphic = down;
else graphic = hover;
if (clicked &&Input.mouseReleased) click();
}
else
{
if (clicked) graphic = hover;
else graphic = normal;
}
//If mouse was released
if (Input.mouseReleased) clicked = false;
}
protected function click():void
{
trace("click");
}
override public function render():void
{
super.render();
renderGraphic(label);
}
protected function renderGraphic(graphic:Graphic):void
{
if (graphic && graphic.visible)
{
if (graphic.relative)
{
_point.x = x;
_point.y = y;
}
else _point.x = _point.y = 0;
_camera.x = world ? world.camera.x : FP.camera.x;
_camera.y = world ? world.camera.y : FP.camera.y;
graphic.render(renderTarget ? renderTarget : FP.buffer, _point, _camera);
}
}
protected var _point:Point = FP.point;
protected var _camera:Point = FP.point2;
}
}
But if the button is too far to the right, the entire text isn’t visible. How do I make it always show the entire text, no matter where the button is? Thanks