Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions net/flashpunk/Engine.as
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@
FP.elapsed *= FP.rate;
_last = _time;

// update console
if (FP._console) FP._console.update();

// update loop
if (!paused) update();

// update console
if (FP._console) FP._console.update();

// update input
Input.update();

Expand Down
30 changes: 29 additions & 1 deletion net/flashpunk/Mask.as
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.flashpunk
{
import flash.display.Graphics;
import flash.geom.Point;
import flash.utils.Dictionary;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
Expand Down Expand Up @@ -45,7 +46,7 @@
}

/** @private Collide against an Entity. */
private function collideMask(other:Mask):Boolean
protected function collideMask(other:Mask):Boolean
{
return parent.x - parent.originX + parent.width > other.parent.x - other.parent.originX
&& parent.y - parent.originY + parent.height > other.parent.y - other.parent.originY
Expand Down Expand Up @@ -78,6 +79,33 @@

}

/** @private Projects this mask points on axis and returns min and max values in projection object. */
public function project(axis:Point, projection:Object):void
{
var cur:Number,
max:Number = Number.NEGATIVE_INFINITY,
min:Number = Number.POSITIVE_INFINITY;

cur = -parent.originX * axis.x - parent.originY * axis.y;
if (cur < min) min = cur;
if (cur > max) max = cur;

cur = (-parent.originX + parent.width) * axis.x - parent.originY * axis.y;
if (cur < min) min = cur;
if (cur > max) max = cur;

cur = -parent.originX * axis.x + (-parent.originY + parent.height) * axis.y;
if (cur < min) min = cur;
if (cur > max) max = cur;

cur = (-parent.originX + parent.width) * axis.x + (-parent.originY + parent.height)* axis.y;
if (cur < min) min = cur;
if (cur > max) max = cur;

projection.min = min;
projection.max = max;
}

// Mask information.
/** @private */ private var _class:Class;
/** @private */ protected var _check:Dictionary = new Dictionary;
Expand Down
102 changes: 88 additions & 14 deletions net/flashpunk/graphics/Image.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.flashpunk.graphics
{
import flash.display.*;
import flash.geom.*;
import net.flashpunk.masks.Polygon;

import net.flashpunk.*;

Expand Down Expand Up @@ -137,17 +138,38 @@ package net.flashpunk.graphics
* @param width Width of the rectangle.
* @param height Height of the rectangle.
* @param color Color of the rectangle.
* @param alpha Alpha of the rectangle.
* @param fill If the rectangle should be filled with the color (true) or just an outline (false).
* @param thick How thick the outline should be (only applicable when fill = false).
* @param radius Round rectangle corners by this amount.
* @return A new Image object.
*/
public static function createRect(width:uint, height:uint, color:uint = 0xFFFFFF, alpha:Number = 1):Image
public static function createRect(width:uint, height:uint, color:uint = 0xFFFFFF, alpha:Number = 1, fill:Boolean = true, thick:Number = 1, radius:Number = 0):Image
{
var source:BitmapData = new BitmapData(width, height, true, 0xFFFFFFFF);
var graphics:Graphics = FP.sprite.graphics;

var image:Image = new Image(source);
if (color > 0xFFFFFF) color = 0xFFFFFF & color;
graphics.clear();

image.color = color;
image.alpha = alpha;
var thickOffset:Number = 0;
if (fill) {
graphics.beginFill(color, alpha);
} else {
thickOffset = thick * .5;
graphics.lineStyle(thick, color, alpha, false, LineScaleMode.NORMAL, null, JointStyle.MITER);
}

if (radius <= 0) {
graphics.drawRect(0 + thickOffset, 0 + thickOffset, width - thickOffset * 2, height - thickOffset * 2);
} else {
graphics.drawRoundRect(0 + thickOffset, 0 + thickOffset, width - thickOffset * 2, height - thickOffset * 2, radius);
}
graphics.endFill();

var data:BitmapData = new BitmapData(width, height, true, 0);
data.draw(FP.sprite);

var image:Image = new Image(data);
return image;
}

Expand All @@ -156,21 +178,27 @@ package net.flashpunk.graphics
* @param radius Radius of the circle.
* @param color Color of the circle.
* @param alpha Alpha of the circle.
* @param fill If the circle should be filled with the color (true) or just an outline (false).
* @param thick How thick the outline should be (only applicable when fill = false).
* @return A new Image object.
*/
public static function createCircle(radius:uint, color:uint = 0xFFFFFF, alpha:Number = 1):Image
public static function createCircle(radius:uint, color:uint = 0xFFFFFF, alpha:Number = 1, fill:Boolean = true, thick:Number = 1):Image
{
FP.sprite.graphics.clear();
FP.sprite.graphics.beginFill(0xFFFFFF);
FP.sprite.graphics.drawCircle(radius, radius, radius);
var graphics:Graphics = FP.sprite.graphics;

graphics.clear();
if (fill) {
graphics.beginFill(color & 0xFFFFFF, alpha);
graphics.drawCircle(radius, radius, radius);
graphics.endFill();
} else {
graphics.lineStyle(thick, color & 0xFFFFFF, alpha);
graphics.drawCircle(radius, radius, radius - thick * .5);
}
var data:BitmapData = new BitmapData(radius * 2, radius * 2, true, 0);
data.draw(FP.sprite);

var image:Image = new Image(data);

image.color = color;
image.alpha = alpha;

return image;
}

Expand All @@ -188,7 +216,7 @@ package net.flashpunk.graphics
* @param toAlpha Alpha at end of gradient.
* @return A new Image object.
*/
public static function createGradient (width:uint, height:uint, fromX:Number, fromY:Number, toX:Number, toY:Number, fromColor:uint, toColor:uint, fromAlpha:Number = 1, toAlpha:Number = 1):Image
public static function createGradient(width:uint, height:uint, fromX:Number, fromY:Number, toX:Number, toY:Number, fromColor:uint, toColor:uint, fromAlpha:Number = 1, toAlpha:Number = 1):Image
{
var bitmap:BitmapData = new BitmapData(width, height, true, 0x0);

Expand Down Expand Up @@ -227,6 +255,52 @@ package net.flashpunk.graphics
return new Image(bitmap);
}

/**
* Creates a new polygon Image from an array of points.
* @param points An array of coordinates (must be positive) that define the polygon.
* @param color Color of the polygon.
* @param alpha Alpha of the polygon.
* @param fill If the polygon should be filled with the color (true) or just an outline (false).
* @param thick How thick the outline should be (only applicable when fill = false).
* @return A new Image object.
*/
public static function createPolygon(points:Vector.<Point>, color:uint = 0xFFFFFF, alpha:Number = 1, fill:Boolean = true, thick:Number = 1):Image
{
var graphics:Graphics = FP.sprite.graphics;
var p:Point;

var maxX:Number = Number.NEGATIVE_INFINITY;
var maxY:Number = Number.NEGATIVE_INFINITY;

// find max x and y coords
for (var i:int = 0; i < points.length; i++) {
p = points[i];
if (p.x > maxX) maxX = p.x;
if (p.y > maxY) maxY = p.y;
}

if (color > 0xFFFFFF) color = 0xFFFFFF & color;
graphics.clear();

if (fill) {
graphics.beginFill(color, alpha);
} else {
graphics.lineStyle(thick, color, alpha, false, LineScaleMode.NORMAL, null, JointStyle.MITER);
}

graphics.moveTo(points[points.length - 1].x, points[points.length - 1].y);
for (var j:int = 0; j < points.length; j++) {
p = points[j];
graphics.lineTo(p.x, p.y);
}
graphics.endFill();

var data:BitmapData = new BitmapData(maxX, maxY, true, 0);
data.draw(FP.sprite);

return new Image(data);
}

/**
* Updates the image buffer.
*/
Expand Down
Loading