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.


Messages - argon_vile

Pages: [1]
1
help / Bug: FlxU.rotatePoint() does not work?
« on: Fri, May 23, 2014 »
FlxU.rotatePoint does not work. The parameters are (X, Y, PivotX, PivotY, Angle), and it is supposed to rotate a point in 2D space around the pivot.

  • FlxU.rotatePoint(10, 10, 20, 10, 0) returns [10, -10]. Since we are rotating by 0 degrees, it should just return the original point, [10, 10]
  • FlxU.rotatePoint(10, 10, 20, 10, 90) returns [40, 1]. It should return [20, 0] -- the original point was left of the pivot, so by rotating 90 degrees, we should now be directly above the pivot.

It looks like line 568, "PivotY+Y", is supposed to be "PivotY-Y"? I see no reason why someone would want to add two points in space to eachother to determine a vector of rotation. After making this change, the code works OK.

2
I also encountered the "single-line right-justification" problem with the hack. I fixed it by deleting the "If it's a single, centered line of text" workaround. This workaround was carried forward from FlxText, but it's unnecessary here. After deleting it, the code works fine with either a single line of centered text or multiple lines.

Code: [Select]
package 
{
import org.flixel.FlxText;
import flash.text.TextField;
import flash.display.BitmapData;
import flash.text.TextFormat;
/**
* An extended version of the FlxText class.
* Adds a resize function for adjusting the width,
* and also handles pixel text properly, even on centered text.
*
* Unfortunately, it's not all that efficient.
*
* @author Truefire
*/
public class FlxTextPlus extends FlxText
{
/**
* Internal reference to a bunch of Flash <code>TextField</code> objects.
* We use these to position each line of the text to avoid anti-aliasing.
* Hacks FTW!
*/
protected var _textFields:Vector.<TextField>

/**
* Creates a new <code>FlxTextPlus</code> object at the specified position.
*
* @param X The X position of the text.
* @param Y The Y position of the text.
* @param Width The width of the text object (height is determined automatically).
* @param Text The actual text you would like to display initially.
* @param EmbeddedFont Whether this text field uses embedded fonts or nto
*/
public function FlxTextPlus(X:Number,Y:Number,Width:uint,Text:String = null,EmbeddedFont:Boolean = true)
{
super(X, Y, Width, Text, EmbeddedFont);
}

/**
* Resizes the text field, updating the pixels and everything.
*
* @param  W                The new width of the text.
*/
public function resize(W:uint):void
{
_textField.width = width = W;
_regen = true;
calcFrame();
}

/**
* Internal function to update the current animation frame.
*/
override protected function calcFrame():void
{
if(_regen)
{

//Need to generate a new buffer to store the text graphic
var i:uint = 0;
var nl:uint = _textField.numLines;
height = 0;
while(i < nl)
height += _textField.getLineMetrics(i++).height;
height += 4; //account for 2px gutter on top and bottom
_pixels = new BitmapData(width,height,true,0);
frameHeight = height;
_textField.height = height*1.2;
_flashRect.x = 0;
_flashRect.y = 0;
_flashRect.width = width;
_flashRect.height = height;
_regen = false;

//generate our single line text fields;
var heightCounter:int;
_textFields = new Vector.<TextField>();
i = 0;
while (i < nl)
{
var tf:TextField = new TextField();
tf.y = heightCounter;
tf.width = _textField.width;
tf.embedFonts = _textField.embedFonts;
tf.selectable = false;
tf.sharpness = 100;
tf.multiline = false;
tf.wordWrap = false;
tf.text = _textField.getLineText(i);
tf.defaultTextFormat = _textField.defaultTextFormat;
tf.setTextFormat(_textField.defaultTextFormat);
if(tf.text .length <= 0)
tf.height = 1;
else
tf.height = 30;
var lPos:Number = _textField.getLineMetrics(i).x;
if ( lPos != Math.round(lPos)) { tf.x = Math.round(lPos)-lPos; }
heightCounter += _textField.getLineMetrics(i++).height;
_textFields.push(tf);
}
}
else //Else just clear the old buffer before redrawing the text
_pixels.fillRect(_flashRect,0);

if((_textField != null) && (_textField.text != null) && (_textField.text.length > 0))
{
//Now that we've cleared a buffer, we need to actually render the text to it
var format:TextFormat = _textField.defaultTextFormat;
var formatAdjusted:TextFormat = format;
_matrix.identity();
//Render a single pixel shadow beneath the text
if(_shadow > 0)
{
i = 0;
while (i < _textFields.length)
{
_textFields[i].setTextFormat(new TextFormat(formatAdjusted.font,formatAdjusted.size,_shadow,null,null,null,null,null,formatAdjusted.align));
_matrix.translate(1+_textFields[i].x,1+_textFields[i].y);
_pixels.draw(_textFields[i],_matrix,_colorTransform);
_matrix.translate(-1-_textFields[i].x,-1-_textFields[i].y);
_textFields[i].setTextFormat(new TextFormat(formatAdjusted.font, formatAdjusted.size, formatAdjusted.color, null, null, null, null, null, formatAdjusted.align));
i++;
}
}
//Actually draw the text onto the buffer
i = 0;
while (i < _textFields.length)
{
_matrix.translate(_textFields[i].x, _textFields[i].y);
_pixels.draw(_textFields[i],_matrix,_colorTransform);
_textFields[i].setTextFormat(new TextFormat(format.font, format.size, format.color, null, null, null, null, null, format.align));
_matrix.translate(-_textFields[i].x,-_textFields[i].y);
i++;
}
}

//Finally, update the visible pixels
if((framePixels == null) || (framePixels.width != _pixels.width) || (framePixels.height != _pixels.height))
framePixels = new BitmapData(_pixels.width,_pixels.height,true,0);
framePixels.copyPixels(_pixels,_flashRect,_flashPointZero);
}
}
}

3
help / Re: Gapless Audio Looping
« on: Wed, Jun 12, 2013 »
I know this is an old thread, but I found a slightly cleaner solution to this gapless music problem. I've attached MusicLoop.as, which you can invoke like this:

MusicLoop.play(Embed.SfxBonusTune0, 26)

This lets you set a start position to the track, and behaves just like every other FlxSound.

Pages: [1]