Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending a flxuibutton and using the 9scaling #19

Closed
gltovar opened this issue Sep 24, 2013 · 34 comments
Closed

extending a flxuibutton and using the 9scaling #19

gltovar opened this issue Sep 24, 2013 · 34 comments

Comments

@gltovar
Copy link
Contributor

gltovar commented Sep 24, 2013

i was having an issue that I outlined here:
HaxeFlixel/flixel#650

but maybe this is way simpler than i am thinking:
I have an button that extends FlxUIButton

and in the constructor I call super, then I call load loadGraphicSlice9 and in ( ["assets/gfx/ui/buttons/button_blue.png"], 18, 18, ["6,6,11,11"] );

this works and you can see a 18 by 18 button in the application..

I just trying to figure out the proper way to adjust the size of the button using the 9 slicing. I've tried resize() (erros) changing width and height ad different times (pre and post constructor) and different values in the loadGraphicSlice9 spot.

thanks in advance for the advice/help

@larsiusprime
Copy link
Member

resize() is what you should be using. Adjusting width and height directly will not cause the 9slice asset to resize itself correctly.

What errors are you getting? And can you post a gist?

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

at the moment the build looks broken from the latest commits . there is an issue on flixel side, but there might be some flixel ui things too:
https://gist.github.com/gltovar/6705065

when the build is fixed I can get into is some more =] I wanted to see if the latest changes fixed it

@larsiusprime
Copy link
Member

I'm in the process of getting a pull request accepted to flixel:
HaxeFlixel/flixel#647

Maybe switch to my flixel fork's dev branch temporarily until it goes through?

I've just updated flixel-ui's dev branch with my latest stuff.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

sure i'll do that one, one sec.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

https://gist.github.com/gltovar/6705447
so here is the basics looks like any resizing of a button is causing an issue:
at the most basic level, say you create a XML button:
button id="btn0" use_def="button" x="0" y="-5" label="$START_GAME" width="300" height="200"
(had to remove the xml i pasted here, but its just a standard button using the button blue skin)

this is causing an error on FlxSprite line 618 the frame (FlxFrame) object is null. If I add a few null checks up the line, then the item is rendered improperly (not resized at all) Im going to double check this now, just to make sure the latest updates didn't fix it.

@larsiusprime
Copy link
Member

Interesting. Let me know if it's still broken in latest updates, then I'll try to repro.

@larsiusprime
Copy link
Member

I assume this is flash target? or CPP?

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

flash at the moment, haven't tried a cpp target yet

@larsiusprime
Copy link
Member

what's your "button" definition, if I may ask? Is it custom or are you using an included definition?

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

oh, but even before using the xml, I was just manually doing a: this.loadGraphicSlice9( ["assets/gfx/ui/buttons/button_blue.png"], 18, 18, ["6,6,11,11"] ); on a button and it also causes the error.
I was planning on calling resize(w,h) afterwards or setting the values in the loadGraphicSlice9 and adding the source values.

here is a gist of the xml i am using: https://gist.github.com/gltovar/6705563 its a near copy of one of the examples in the RPG interface.

@larsiusprime
Copy link
Member

okay thanks. And confirmed the latest updates don't fix it?

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

doesn't look like it.
im getting that error on your flixel branch (after updating FlxAnimationController line 507 to remove gotoandstop reference to a frameindex)

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

if I do a null check for frame on line 618 on flxsprite this is what it renders out http://screencast.com/t/llc2l4An9ah7

@larsiusprime
Copy link
Member

Thanks for bearing with me. I'm trying to repro now.

@larsiusprime
Copy link
Member

Okay, think I've repro'd. Let's narrow this thing down.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

i was thinking this part of flxSprite::LoadGraphic() might be the issue:

if (!Std.is(Graphic, TextureRegion))
{
region = new Region(0, 0, Width, Height);
region.width = cachedGraphics.bitmap.width;
region.height = cachedGraphics.bitmap.height;
}

because in the future updateFrameData() might have the wrong parameters for the region

    {
        framesData = cachedGraphics.tilesheet.getSpriteSheetFrames(region, null);
    }

    frame = framesData.frames[0];

but i don't pin down what is going wrong there

@larsiusprime
Copy link
Member

good thoughts, might be related to the recent refactoring in flixel animation system!

@larsiusprime
Copy link
Member

what's strange is the RPG Interface in flixel-demos still seems to compile just fine. Does that work for you?

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

it compiles, but breaks when i click on save or battle. but at the moment I'm trying to make sure I have the latest flixel-demos in my libs... its taking its sweet time

What im looking for in the demos is for a button that isn't the default width/height of 80 by 20

@gltovar
Copy link
Contributor Author

gltovar commented Sep 25, 2013

ok with the latest demo code i can see the rpg interface working again. I'll look at the button code to see if I can see differences

@larsiusprime
Copy link
Member

I might have started to find your error but I'll have to finish investigating tomorrow. Let me know what you find.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 26, 2013

so in toying around i found that if i change the save menu's button size (big_button_blue) in the xml. Looks like when the bounds (at least hight wise) gets bigger or equal than the original image size (54px in this case) the error gets hit. So the slightly larger buttons in the save menu are just being scaled to 34px but if you change it to 54 or bigger then its breaks (53 works)

So i think there is some merit to the region, and where ever the size of a sprite is kept being an issue but haven't quite find the root cause just yet.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 26, 2013

I noticed that line 288 of FlxUITyped Button has this:
if(all.height > H){

but i think it should see if src_h should be taken into account if its set, right? (going to try it, but not sure if i'm interpreting src_w and src_h correctly

@gltovar
Copy link
Contributor Author

gltovar commented Sep 26, 2013

nice i think that was the problem:
http://screencast.com/t/wmBwNJl3TE
(dont mind the unlocalized vars, I skipped the main menu and jumped straight into the save screen for debugging, so firetongue never got inited)

on line 288 i changed it to:
if( (_src_h != -1 && all.height > _src_h) || all.height > H){

@gltovar
Copy link
Contributor Author

gltovar commented Sep 26, 2013

ok so now setting the buttons size in the xml is fixed i just tried doing it manually though code:
this.loadGraphicSlice9( ["assets/gfx/ui/buttons/button_blue.png"], p_width, p_height, ["6,6,11,11"], 18, 18 );

http://screencast.com/t/2Zw9EY7MoWt and here is the result

So im going to hunt down why it isn't setting the proper height (it should take up the whole bottom right corner. looks like its defaulting to the standard button height.

@larsiusprime
Copy link
Member

Thanks so much for looking into this for me, I've been kind of busy the
last few days!

On Thu, Sep 26, 2013 at 6:24 PM, gltovar notifications@github.com wrote:

ok so now setting the buttons size in the xml is fixed i just tried doing
it manually though code:
this.loadGraphicSlice9( ["assets/gfx/ui/buttons/button_blue.png"],
p_width, p_height, ["6,6,11,11"], 18, 18 );

http://screencast.com/t/2Zw9EY7MoWt and here is the result

So im going to hunt down why it isn't setting the proper height (it should
take up the whole bottom right corner. looks like its defaulting to the
standard button height.


Reply to this email directly or view it on GitHubhttps://github.com//issues/19#issuecomment-25211987
.

www.fortressofdoors.com -- Games, Art, Design

@gamedevsam
Copy link
Contributor

Open source collaboration for the win! Great work gltovar.

@larsiusprime
Copy link
Member

Okay, so line 288 looks like I might have a logic error. What it's supposed to do is look at the asset and determine whether it looks like a stacked asset with multiple frames, or is just one frame. To do that, it checks if the object's height (all.height) is greater than the target button frame height (H).

However, this fails to account for the fact that we're 9-slice-scaling, which means the source asset is probably going to be pretty dang small. So if the standard source rectangle is, say, 10x10, and I want a button that's 300x300, 30 < 300 and the algorithm will guess wrong.

Checking vs. the source width and height should work correctly, however.

So.... I might have to just stop trying to be smart here, and demand that the user supply metadata if they're using a 9-slice asset.

@larsiusprime
Copy link
Member

I think I can have my cake and eat it too!

So, from now on, if you only have one asset provided, it throws an error if src_w and src_h aren't defined as that's an ambiguous situation.

HOWEVER, during the loading phase, Flixel-UI does have enough information to know what to do. It knows when you're using an "all" asset, so it can calculate the proper src_w and src_h at that time and pass it along, if the user hasn't supplied his/her own values.

@larsiusprime
Copy link
Member

Working on some patches. Hopefully this will fix some things.

@larsiusprime
Copy link
Member

Okay, think I've fixed it. RPG Interface is working again, and I've fixed the offending line of code. Hopefully this fixes your issues (and artifacts) without causing new problems....

Please confirm whether this is fixed for you and I'll close this issue.

@gltovar
Copy link
Contributor Author

gltovar commented Sep 27, 2013

sure thing i'll check it out shortly. thanks =]

@gltovar
Copy link
Contributor Author

gltovar commented Sep 28, 2013

It is looking good =] thanks so much

the last part of the issue i was having was using the method incorrecly because of a glitch in the code hinting in sublime text: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=14227 it was masking some of the actually parameters because it was thinking the commas in the string literal for the slicing were satisfying other parameters

leading to this:
this.loadGraphicSlice9( ["assets/gfx/ui/buttons/button_blue.png"], p_width, p_height, ["6,6,11,11"],18, 18 );

instead of this:
this.loadGraphicSlice9( ["assets/gfx/ui/buttons/button_blue.png"], p_width, p_height, ["6,6,11,11"],FlxUI9SliceSprite.TILE_NONE,-1,false, 18, 18 );

and one of the 18's was being used for tile mode or maybe ratio. (i think)

I am glad to have helped fix this issue, and thanks again so much for the help!

@larsiusprime
Copy link
Member

Cool, let's close this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants