multiple cameras, an optimization, dragging
This commit is contained in:
@@ -6,6 +6,7 @@ import flixel.FlxG;
|
||||
import flixel.FlxState;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.math.FlxRandom;
|
||||
|
@@ -1,8 +1,16 @@
|
||||
(prop &mut :Jigsawx jigsaw)
|
||||
(prop &mut :FlxCamera pieceCamera)
|
||||
(prop &mut :FlxCamera uiCamera)
|
||||
|
||||
(method &override :Void create []
|
||||
(set FlxG.cameras.bgColor FlxColor.TRANSPARENT)
|
||||
(set pieceCamera FlxG.camera)
|
||||
(set uiCamera (new FlxCamera))
|
||||
(pieceCamera.copyFrom FlxG.camera)
|
||||
(set FlxG.camera pieceCamera)
|
||||
(FlxG.cameras.add uiCamera)
|
||||
(FlxG.plugins.add (new FlxMouseControl))
|
||||
(set bgColor FlxColor.GRAY)
|
||||
(set bgColor FlxColor.TRANSPARENT)
|
||||
(super.create))
|
||||
(method &override :Void update [:Float elapsed]
|
||||
(super.update elapsed)
|
||||
@@ -52,6 +60,7 @@
|
||||
(rewardSprite.updateHitbox)
|
||||
(rewardSprite.screenCenter)
|
||||
|
||||
(set pieceCamera.zoom rewardSprite.scale.x)
|
||||
|
||||
(set rewardSprites (new FlxTypedGroup))
|
||||
|
||||
@@ -75,16 +84,22 @@
|
||||
(let [jig (nth jigsaw.jigs i)
|
||||
pos (nth startingPoints i)
|
||||
s (new FlxExtendedSprite pos.x pos.y)
|
||||
mask (new FlxSprite)]
|
||||
source (new FlxSprite)
|
||||
mask (new FlxSprite)
|
||||
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
||||
(-= pos.x jig.xy.x)
|
||||
(-= pos.y jig.xy.y)
|
||||
(set s.draggable true)
|
||||
(s.enableMouseDrag false true)
|
||||
|
||||
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
||||
|
||||
(mask.makeGraphic graphicWidth graphicHeight FlxColor.TRANSPARENT true)
|
||||
(drawPieceShape mask jig FlxColor.BLACK)
|
||||
|
||||
(FlxSpriteUtil.alphaMask s rewardSprite.pixels mask.pixels)
|
||||
(s.setGraphicSize (Std.int rewardSprite.width) (Std.int rewardSprite.height))
|
||||
(s.updateHitbox)
|
||||
|
||||
(set s.cameras [pieceCamera])
|
||||
|
||||
(rewardSprites.add s)))
|
||||
(add rewardSprites))))
|
||||
@@ -130,7 +145,8 @@
|
||||
|
||||
(method makeText [:Entry e]
|
||||
(let [label (HabitModel.activeLabel e)
|
||||
text (new FlxText 0 textY 0 (+ label.label (* label.points "+")))]
|
||||
text (new FlxText 0 textY 0 (+ label.label (* label.points "+")) 16)]
|
||||
(set text.color color)
|
||||
(set text.cameras [uiCamera])
|
||||
(+= textY text.height)
|
||||
(entryTexts.add text)))
|
@@ -17,6 +17,7 @@ class JigsawPiece{
|
||||
public var sideData: JigsawPieceData;
|
||||
private var first: Vec2;
|
||||
public var xy: Vec2;
|
||||
public var wh: Vec2;
|
||||
public var row: Int;
|
||||
public var col: Int;
|
||||
public function new( xy_: Vec2
|
||||
@@ -43,6 +44,16 @@ class JigsawPiece{
|
||||
// WEST side
|
||||
if( sideData.west != null ) createHoriSide( lb, lt, sideData.west, WEST );
|
||||
points.push( lt );
|
||||
|
||||
var maxX = 0.0;
|
||||
var maxY = 0.0;
|
||||
for (point in points) {
|
||||
if (point.x > maxX)
|
||||
maxX = point.x;
|
||||
if (point.y > maxY)
|
||||
maxY = point.y;
|
||||
}
|
||||
wh = new Vec2(maxX, maxY);
|
||||
}
|
||||
public function getPoints(): Array<Vec2> {
|
||||
return points;
|
||||
|
Reference in New Issue
Block a user