How to define label offset in FlxButton

205 views
Skip to first unread message

Rabí Hernández Corona

unread,
Sep 25, 2014, 2:29:10 AM9/25/14
to haxef...@googlegroups.com
Hello,
I have a FlxButton with a custom image, and I need to offset the label. I have not idea for wath is the sintax. Can you help me?

Andrei Regiani

unread,
Sep 25, 2014, 4:45:49 AM9/25/14
to haxef...@googlegroups.com
As far as I remember, you can access the label directly: FlxButton.label (FlxText). Example:

button.label.x = 50;
button
.label.y = 50;
// as well change other properties like size, color, etc

Rabí Hernández Corona

unread,
Sep 25, 2014, 1:59:08 PM9/25/14
to haxef...@googlegroups.com
It was the first thing that I've tried. It doesn't return any error, but there's no visible result.

Andrei Regiani

unread,
Sep 25, 2014, 2:06:01 PM9/25/14
to haxef...@googlegroups.com
This should do the trick :)

button.labelOffset.set(50, 50);

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/_0qXrlfGmVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.
Visit this group at http://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/d8635ec1-ae4f-4c90-a716-a154fc12bad2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Gama11

unread,
Sep 25, 2014, 2:09:08 PM9/25/14
to haxef...@googlegroups.com
No, it shouldn't, it's not labelOffset but labelOffsets, an Array<Int> that defines the offsets for each button status. You should be able to use button.label.offset as a "global offset" though, that seems more convenient.

x / y position changes to the button label will be overriden by internal logic.

On Thursday, September 25, 2014 8:06:01 PM UTC+2, Andrei Regiani wrote:
This should do the trick :)

button.labelOffset.set(50, 50);
On Thu, Sep 25, 2014 at 8:59 PM, Rabí Hernández Corona <rabi.he...@gmail.com> wrote:
It was the first thing that I've tried. It doesn't return any error, but there's no visible result.

El jueves, 25 de septiembre de 2014 03:45:49 UTC-5, Andrei Regiani escribió:
As far as I remember, you can access the label directly: FlxButton.label (FlxText). Example:

button.label.x = 50;
button
.label.y = 50;
// as well change other properties like size, color, etc



On Thursday, September 25, 2014 9:29:10 AM UTC+3, Rabí Hernández Corona wrote:
Hello,
I have a FlxButton with a custom image, and I need to offset the label. I have not idea for wath is the sintax. Can you help me?

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/_0qXrlfGmVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+unsubscribe@googlegroups.com.

Andrei Regiani

unread,
Sep 25, 2014, 2:13:32 PM9/25/14
to haxef...@googlegroups.com
Yep, sorry, I took my snippet from an old project (Gorilla Go!), API has changed since then. As always :)

Rabí Hernández Corona

unread,
Sep 25, 2014, 5:17:55 PM9/25/14
to haxef...@googlegroups.com
Well, I've seen that labelOffsets is an FlxPoint, but it's a little hard to find the correct syntax (I'm almost new in haxe and haxefliel). Looking in the FlxTypedButton class, I figure to use

        btn.labelOffsets = [FlxPoint.get(0,10)];
and it works, but honestly I don understan the whole logic.


El jueves, 25 de septiembre de 2014 13:09:08 UTC-5, Gama11 escribió:
No, it shouldn't, it's not labelOffset but labelOffsets, an Array<Int> that defines the offsets for each button status. You should be able to use button.label.offset as a "global offset" though, that seems more convenient.

x / y position changes to the button label will be overriden by internal logic.

On Thursday, September 25, 2014 8:06:01 PM UTC+2, Andrei Regiani wrote:
This should do the trick :)

button.labelOffset.set(50, 50);
On Thu, Sep 25, 2014 at 8:59 PM, Rabí Hernández Corona <rabi.he...@gmail.com> wrote:
It was the first thing that I've tried. It doesn't return any error, but there's no visible result.

El jueves, 25 de septiembre de 2014 03:45:49 UTC-5, Andrei Regiani escribió:
As far as I remember, you can access the label directly: FlxButton.label (FlxText). Example:

button.label.x = 50;
button
.label.y = 50;
// as well change other properties like size, color, etc



On Thursday, September 25, 2014 9:29:10 AM UTC+3, Rabí Hernández Corona wrote:
Hello,
I have a FlxButton with a custom image, and I need to offset the label. I have not idea for wath is the sintax. Can you help me?

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/_0qXrlfGmVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.

varomix WEY

unread,
Sep 25, 2014, 11:08:19 PM9/25/14
to haxef...@googlegroups.com
this works MyButton.labelOffsets[0].x = 30;

just tested

Gama11

unread,
Sep 26, 2014, 5:57:11 AM9/26/14
to haxef...@googlegroups.com
There is one offset in the array for each button state. Only setting the first like varomix suggested would lead to issues when the button state changes.

Ideally, you'd do something like this:

var customOffset = 10;
button.labelOffsets[FlxButton.NORMAL].x += customOffset;
button.labelOffsets[FlxButton.PRESSED].x += customOffset;
button.labelOffsets[FlxButton.HIGHLIGHT].x += customOffset;

Or much simpler, just set button.label.offset like I suggested earlier and leave labelOffsets alone. However, here you have to subtract:

button.label.offset.x -= customOffset;

You can think of label.offset as a global modifier. The offsets in labelOffsets are relative to it, and depend on the current button status.

Rabí Hernández Corona

unread,
Sep 26, 2014, 10:44:42 AM9/26/14
to haxef...@googlegroups.com
Thanks, Gama11!  That's a full explanation. Now I understand perfectly.

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/_0qXrlfGmVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.
Visit this group at http://groups.google.com/group/haxeflixel.

For more options, visit https://groups.google.com/d/optout.



--
Rabí Hernández Corona
Reply all
Reply to author
Forward
0 new messages