Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - GrimPanda

Pages: [1]
help / indexOf() and FlxPoint
« on: Sat, Jul 23, 2011 »
If I have an array of FlxPoints, how would I use indexOf() to see if a FlxPoint already exists inside the array?


Code: [Select]
var pointArray:Array = new Array();
pointArray.push(new FlxPoint(0,0));
pointArray.push(new FlxPoint(0,1));
pointArray.push(new FlxPoint(1,1));
pointArray.push(new FlxPoint(1,3));

//The following line should not execute (IE a FlxPoint of 1,1 exists above)
if (!pointArray.indexOf(1,1)) pointArray.push(new FlxPoint(1,1);

So in the example, I have a point index of 1,1 in the array, but I have no idea how to actually check for that value... Thanks!!

help / Best method to embed resources?
« on: Tue, Jul 12, 2011 »
I hope I can phrase this in a manner that makes sense.

I've always wondered which is better when you embed resources in flash/flixel.  Some sprites, like buttons or panel backgrounds I may use in multiple classes/states.  Yet, others will only be used in one class/state.

So my question is... is it better to A) Throw all the sprite/resource embeds in one class and just include it on each class.  B)  Embed each resource individually per class, even if I'm embedding the same resources multiple times throughout different classes.  C)  Make a Resource class for common embeds (fonts, buttons, etc) and individually embed resources unique to only one class.

I'm wondering if including a central Resource class is a memory waste if I don't need all the other embeds on it at that time?  I prefer the central location for organization, but if it's a memory waste, then I'll change my code.

Hope that makes sense. 

help / Setting Button Width
« on: Fri, Jul 8, 2011 »
I've been away from Flixel for several releases, so perhaps this is just something that I just can't find in the docs.

I'm trying to create a button.  This button will get it's text from an external data source, and it's length will be unknown to me at run time.  It's basically a user name, and is formatted into the correct font, size, color etc as an FlxText object.  I then get the width of that string in pixels through a custom function.  Everything is great so far.

Now I need a button to place this FlxText on and set the width of that button to the width of the string in the FlxText object. (plus padding etc).  So I drop a new button down, set the label to my FlxText Object, and then theoritically, I would set the width of the button as needed.

Code: [Select]
_myBtn = new FlxButton(100, 100, '', goDoStuff);
_myBtn.label = _myTxt;
_myBtn.width = 200;  //_myTxt.pixelWidth

Line 3 above silently does nothing.  It actually get's it width from my function there, but I can put in a fixed width (so we can avoid 'your function isn't returning a valid value') and it still will not set the button width. 

FlxSprite.createGraphic() is gone (I'm using 2.55), and FlxButton.loadGraphic() is looking for a class object embed, which I don't want to use since the button is a variable width at runtime.  (although I would love to use a graphic for the button that can resize itself gracefully, but that seems a bit complicated.  I was thinking of doing something like a mid section that tiles a background, and then capping the ends with the 'end images', as you would do in CSS for example.  But this seems like a headache in as3).

I know setting a button width has got to be mindnumbingly easy, but somehow I'm hitting a wall here.  Any idea how to accomplish this easily, or why FlxButton.width isn't doing anything in my code?

Thanks a ton.

Pages: [1]