Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411613 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 09, 2024, 07:47:59 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Flixel button problems
Pages: [1]
Print
Author Topic: Flixel button problems  (Read 3204 times)
Pishtaco
Level 10
*****


View Profile WWW
« on: December 13, 2009, 11:22:21 AM »

I've run into a couple of problems with buttons in Flixel. One is that I want to have a scrollable level with a fixed Hud, with clickable buttons on it. It seems rather hard in Flixel to set the scrollFactor of a button, but I've fixed this by adapting the button class a bit.

A weirder thing is that in the MenuState that the game starts in, I've put in a button to start the first level. Then in the playstate, the button still seems to be there. It isn't rendered, but clicking in roughly that spot (now scrolled) restarts the level.

The state-switching code in Flixel is rather opaque to me. I assume things like buttons aren't meant to be persistent between states, so either me or flixel is doing something wrong. I wonder, is anything about states meant to be persistent, or are they supposed to be made from scratch each time they are switched to? I'm pretty new to Flash.
Logged

increpare
Guest
« Reply #1 on: December 13, 2009, 11:27:48 AM »

Quote
A weirder thing is that in the MenuState that the game starts in, I've put in a button to start the first level. Then in the playstate, the button still seems to be there. It isn't rendered, but clicking in roughly that spot (now scrolled) restarts the level.
That's weird.  Yeah nothing usually should persist between states.  Is the button declared as a static member variable? (It probably shouldn't be); states should be created and destroyed as you switch between them, so no non-static info should persist (usually layers tend to be declared as private static variables, but yeah they don't count I guess).
Logged
Pishtaco
Level 10
*****


View Profile WWW
« Reply #2 on: December 13, 2009, 11:33:14 AM »

The button creation code is just this:
Code:
var buttonText:FlxText = new FlxText(0, 0, 200, "Click for level 1", 0xffffffff, null, 8, "center");
this.add(new FlxButton(FlxG.width/2-100, FlxG.height/2, buttonText, onClick1));
in the menustate constructor.

So what's up with the static layers? Are they meant to persist?
Logged

increpare
Guest
« Reply #3 on: December 13, 2009, 11:37:30 AM »

Yeah that definitely shouldn't survive a state-change.

Have you tried adding a "if (this==null) output error message" in onclick1 and see what happens when you press it when it has persisted into the next state?

(I don't fully understand the logic behind declaring the layers as static)
Logged
Pishtaco
Level 10
*****


View Profile WWW
« Reply #4 on: December 13, 2009, 11:41:52 AM »

Have you tried adding a "if (this==null) output error message" in onclick1 and see what happens when you press it when it has persisted into the next state?
Just tried that, and nothing shows up.
Logged

increpare
Guest
« Reply #5 on: December 13, 2009, 11:44:28 AM »

yeah that's not right.

have you tried copying, say, the title screen state class from Mode and seeing if that exhibits similar behaviour?
Logged
Μarkham
Level 10
*****



View Profile WWW
« Reply #6 on: December 13, 2009, 01:03:06 PM »

What version of Flixel are you running?  The button issue was fixed last week a little before v1.37.

The version is up to v1.43 now, with a lot more features, but some of the functions had paramaters switched around in 1.40, so updating to that will require you to modify some of your "var this = new FlxWhatever" lines.
Logged

Pishtaco
Level 10
*****


View Profile WWW
« Reply #7 on: December 13, 2009, 01:26:00 PM »

Aha, looks like I'm using version 1.32. Which is weird; I could swear I only downloaded this version yesterday.
Logged

Pishtaco
Level 10
*****


View Profile WWW
« Reply #8 on: December 13, 2009, 02:34:38 PM »

Okay, got it working with 1.43  Beer!.

The button persistence is gone. Button scrolling is now weirder, though. I've set the buttons scroll factor to 0 (using the synch-scroll-with-layer thing). But the button still scrolls around the screen, and highlights when you put the mouse over it. However nothing happens when you click it, if it's moved; the clickable area stays where it should be. Anyway, I can more or less see how to fix this.
Logged

AdamAtomic
*BARF*
Level 9
*


hostess w/ the mostest


View Profile WWW
« Reply #9 on: December 14, 2009, 11:50:49 AM »

if you figure out what's up with tehb uttons and want to post the issue to either github:

http://github.com/AdamAtomic/flixel/issues

Or to the flixel forums Release section:

http://flixel.org/forums/index.php?board=4.0

I would totally appreciate it!  I've been trying to get the buttons ship-shape since last week and thought I had them fixed, apparently not!  It might be that buttons just don't play nice yet with the layer sync thing, but would love to get it resolved anyways
Logged

cup full of magic charisma
Pishtaco
Level 10
*****


View Profile WWW
« Reply #10 on: December 14, 2009, 01:36:07 PM »

Thanks very much for flixel  Wizard

I've hacked it to work for fixed buttons. I'm not getting how the scrolling stuff works so I've left it for now. I posted about the issue (and about something with the default button graphic) on github.
Logged

agj
Level 10
*****



View Profile WWW
« Reply #11 on: December 15, 2009, 12:15:47 PM »

I'm really new to Flixel, so I may just not get it, but shouldn't you be putting the button in a layer, and adjust the scroll factor of that layer rather than of the button?
Logged

Pishtaco
Level 10
*****


View Profile WWW
« Reply #12 on: December 15, 2009, 01:21:34 PM »

I'm really new to Flixel, so I may just not get it, but shouldn't you be putting the button in a layer, and adjust the scroll factor of that layer rather than of the button?

That's what I'm doing. The problem is something to do with the text and graphics of the button scrolling indepently of the button, I think.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic