Author Topic: FlxButtonPlus and scrollFactor. onClick Issue.  (Read 2589 times)

wrik

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Hi!

I am currently working on a grid of level buttons (much like you'd find in Angry Birds), behind the buttons the map for level1 scrolls from left to right and vice versa until the player clicks on a level button.

I am using FlxButtonPlus for the buttons and in order for them to stay static on screen during the scroll sequence I have set the scrollFactor.x/y = 0.

The button's image and text appear fine on screen however the 'clickable' area of the button disappears off screen during the scroll sequence.

I've included the code for my button grid below, am I missing an attribute or something?

Any help greatly appreciated!


Code: [Select]
private function displayLevelMenu(totalLevels : int):* {
levelButtonSprite = new FlxSprite;
levelButtonSprite.loadGraphic(levelButtonPNG, false, false, 32, 32, false);

var gridOffsetX : int = 24;
var gridOffsetY :int = 50;
var count : int = 0;

for (var column : int = 0; column < 3; column++) {
for (var row : int = 0; row < 7; row++) {
count++;
if (count > totalLevels) break;
var button : FlxButtonPlus = new FlxButtonPlus(gridOffsetX + (40 * row), gridOffsetY + (50 * column), changeState, [count.toString()], count.toString(), 32, 32);
button.loadGraphic(levelButtonSprite, levelButtonSprite);

button.buttonNormal.scrollFactor.x = 0;
button.buttonNormal.scrollFactor.y = 0;
button.buttonHighlight.scrollFactor.x = 0;
button.buttonHighlight.scrollFactor.y = 0;
button.textNormal.scrollFactor.x = 0;
button.textNormal.scrollFactor.y = 0;
button.textHighlight.scrollFactor.x = 0;
button.textHighlight.scrollFactor.y = 0;

add(button);
}
}

}

caladan21ph

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: FlxButtonPlus and scrollFactor. onClick Issue.
« Reply #1 on: Tue, Jun 16, 2015 »
I'm also having this problem. When I scroll the camera, it seems as if the rect used to check for mouseover is left in the original position.
Anyone have the answer to this question?
Check out my game journal: http://alternatdev.wordpress.com

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: FlxButtonPlus and scrollFactor. onClick Issue.
« Reply #2 on: Tue, Jun 16, 2015 »
I'm also having this problem. When I scroll the camera, it seems as if the rect used to check for mouseover is left in the original position.
Anyone have the answer to this question?

I haven't run into this - have you trying updating the button?

caladan21ph

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: FlxButtonPlus and scrollFactor. onClick Issue.
« Reply #3 on: Wed, Jun 17, 2015 »
Hi, solved my problem. It seems that FlxButtonPlus checks if the mouse is hovering over a button using screen coordinates. I just added a new parameter to FlxButtonPlus to check for either screen or world coordinates( and set it to check for world coordinates) and it worked.

Code: [Select]
if (FlxMath.mouseInFlxRect(_worldCoords, buttonNormal.rect))
{
offAll = false;

if (FlxG.mouse.justPressed())
{
_status = PRESSED;
}

if (_status == NORMAL)
{
_status = HIGHLIGHT;
}
}
Check out my game journal: http://alternatdev.wordpress.com