Can Graphiclist get the property of a button?


(Sharon Shalom Iluz) #1

Can Graphiclist get the property of a button ?

i am made 2 graphic images and put it in one graphiclist

and i want that graphiclist to have a button function

on mouse pressed

can someone help me with this


(Jonathan Stoler) #2

This sounds like a good thing to create an Entity subclass for.

This thread should lead you in the right direction.


(Sharon Shalom Iluz) #3
private var _head:Image = new Image(HEAD);
private var _body:Image = new Image(BODY);
private var _hero:Graphiclist = new Graphiclist(body, head);

graphic = _hero;

what i would like to do is to have like a mouse eventlistner to hero to trigger a function i don’t know how to do it i try hitbox and matching the x and y of duck doesn’t work .

please help thanks


(Jacob Albano) #4

Please explain what it is you hope to accomplish. Do you want the whole graphic to behave as a single button, each image in it to be its own button, or something totally different?

We can’t help you unless we understand your issue.


(Sharon Shalom Iluz) #5

ok thanks im sorry if im not able to explain it properly

so i have a character with a animated head and an animated body

i put both of those part into the graphiclist witch is working

and what i am trying to do is to have that graphiclist to be a button so that i can trigger a function to change the animation of the character look.

so yes a simple button is what i am looking for.

i what to get a really cool animation in my game


(Jacob Albano) #6

Does the entity you have the graphic on have a hitbox and a type? There’s no easy way to automatically create a hitbox based on a Graphiclist, but you can set it manually and tweak it as necessary.

After that, here’s what I use for button logic:


override public function update():void
{
    var hover:Boolean = world.collidePoint(type, world.mouseX, world.mouseY) == this;

    if (Input.mousePressed && hover)
    {
        this.pressed = true;
    }

    if (!hover)
    {
        this.pressed = false;
    }

    if (this.pressed && Input.mouseReleased)
    {
        // do button press
    }
}


(Sharon Shalom Iluz) #7

but i dont want the hole stage to be clickable just the hero the character


(Jacob Albano) #8

What? I didn’t say anything about that.

You have a character entity, right? Set its hitbox and type in the constructor:

setHitbox(60, 100); // 60 wide, 100 high. adjust as necessary
type = "myAwesomeCharacter";

The collision check will only be valid when your mouse is over the character.


(Sharon Shalom Iluz) #9

ok thanks i will try this as soon as i get home thanks alot


(Sharon Shalom Iluz) #10

its not working!

i am only looking for on pressed state but i don’t see how is it reffering to my graphiclist as the object listening for the click


(Jacob Albano) #11

It’s not. The entity is, and it uses the hitbox to tell if the mouse is over it.


(Sharon Shalom Iluz) #12

yes my character is an entity


(Sharon Shalom Iluz) #13

i get an error on pressed ? this.pressed


(Jacob Albano) #14

You should have a property called pressed on your character/button. I thought that would be obvious, sorry.

private var pressed:Boolean;

(Sharon Shalom Iluz) #15

oh hey great it works wow thank you so much thank you so much finally i can move on lol

i got stuck on this for a couple of days but i see what you did there so very cool thanks again