CameraTools.calculateScrollBounds
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
|
||||
<haxelib name="kiss"/>
|
||||
<haxelib name="kiss-flixel"/>
|
||||
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
||||
|
||||
<haxelib name="hscript"/>
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import flixel.FlxCamera;
|
||||
import flixel.math.FlxRect;
|
||||
import flixel.math.FlxVector;
|
||||
import flixel.graphics.FlxGraphic;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.FlxG;
|
||||
import flixel.input.mouse.FlxMouseEventManager;
|
||||
|
||||
|
@@ -6,6 +6,8 @@
|
||||
(prop &mut :ScenData data null)
|
||||
(prop :FlxCamera worldCamera (new FlxCamera))
|
||||
|
||||
(var SCROLL_BOUND_MARGIN 200)
|
||||
|
||||
(method &override :Void create []
|
||||
(super.create)
|
||||
(set data (ScenData.coreData))
|
||||
@@ -17,19 +19,20 @@
|
||||
|
||||
(let [valleydy (Scenario.fromBasFile "Blades of Avernum Scenarios/Valley of Dying Things/valleydy.bas")]
|
||||
(addSprites
|
||||
// 2D nth >:)
|
||||
(nth valleydy.outdoorSections 0 2))
|
||||
// 2D nth -- pretty cool
|
||||
(nth valleydy.outdoorSections 0 2)))
|
||||
|
||||
(prop &mut :FlxSprite border (new FlxSprite))
|
||||
(set border (SpriteSheet.fromWholeBmp "${data.data}/Game Graphics/G801.bmp"))
|
||||
(worldCamera.addBorder border)
|
||||
(let [testRed (.makeGraphic (new FlxSprite 0 0) 16 16 FlxColor.RED)]
|
||||
(set testRed.cameras [worldCamera])
|
||||
(add testRed))))
|
||||
|
||||
(add tileSprites)
|
||||
(worldCamera.calculateScrollBounds tileSprites SCROLL_BOUND_MARGIN))
|
||||
|
||||
(var SELECTED_COLOR FlxColor.LIME)
|
||||
(var NORMAL_COLOR FlxColor.WHITE)
|
||||
(var CLIFF_HEIGHT 22)
|
||||
(var :FlxTypedGroup<FlxSprite> tileSprites (new FlxTypedGroup))
|
||||
|
||||
(method :Void addSprites [:TileMap map]
|
||||
(let [&mut rowStartX 0
|
||||
@@ -55,7 +58,7 @@
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite)))
|
||||
(tileSprites.add tileSprite)))
|
||||
|
||||
// TODO add any items
|
||||
|
||||
@@ -72,7 +75,7 @@
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite))))
|
||||
(tileSprites.add tileSprite))))
|
||||
(+= x (/ FLOOR_WIDTH 2))
|
||||
(+= y (/ FLOOR_HEIGHT 2))))
|
||||
(-= rowStartX (/ FLOOR_WIDTH 2))
|
||||
|
@@ -10,6 +10,9 @@ import flixel.math.FlxPoint;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxG;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.FlxObject;
|
||||
import flixel.group.FlxGroup;
|
||||
import kiss_flixel.GroupTools;
|
||||
|
||||
using Lambda;
|
||||
|
||||
|
@@ -81,3 +81,15 @@
|
||||
camera.zoom += (FlxG.mouse.wheel * elapsed * speed);
|
||||
}
|
||||
}#)
|
||||
|
||||
(function calculateScrollBounds <>[:FlxObject T] [:FlxCamera camera :FlxTypedGroup<T> group &opt :Float margin]
|
||||
(let [r (GroupTools.calculateBounds group margin)]
|
||||
(camera.setScrollBoundsRect r.x r.y r.width r.height)))
|
||||
|
||||
(function extendScrollBounds [:FlxCamera camera :FlxObject object &opt :Float margin]
|
||||
// if the given object is out of bounds, extend the bounds
|
||||
(let [r (object.getRotatedBounds)]
|
||||
(setMin camera.minScrollX (- r.left margin))
|
||||
(setMin camera.minScrollY (- r.top margin))
|
||||
(setMax camera.maxScrollX (+ r.right margin))
|
||||
(setMax camera.maxScrollY (+ r.bottom margin))))
|
@@ -11,6 +11,7 @@ import nat.BoolExpInterp;
|
||||
import nat.components.Images;
|
||||
import nat.components.Positions;
|
||||
import nat.components.Scale;
|
||||
using kiss_flixel.CameraTools;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class EntrySprite extends FlxExtendedSprite {}
|
||||
|
@@ -41,6 +41,7 @@
|
||||
(prop &mut :FlxPoint fixedOffset)
|
||||
|
||||
(method savePos []
|
||||
(FlxG.camera.extendScrollBounds this PlayState.SCROLL_BOUND_MARGIN)
|
||||
(withWritableComponents archive e [positions Positions]
|
||||
(dictSet positions positionKey (object x (cast this.x Float) y (cast this.y Float) z 0.0))))
|
||||
|
||||
|
@@ -1,9 +1,6 @@
|
||||
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
|
||||
|
||||
// TODO store a map of Entry IDs -> EntrySprites.
|
||||
// TODO handleChanges() will need to kill every changed Entry's sprite and make a new one
|
||||
// TODO make the EntrySprite constructor assign the entry a serialized position component
|
||||
// maybe by writing a Map<String, Point> positions component so there can be multiple?
|
||||
|
||||
(method &override :Void create []
|
||||
(super.create)
|
||||
@@ -98,7 +95,8 @@
|
||||
(prop &mut :EntrySpriteSystem spriteSystem)
|
||||
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
|
||||
(archive.addSystem spriteSystem)
|
||||
(archive.processSystems this))
|
||||
(archive.processSystems this)
|
||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||
|
||||
(method &override :Void update [:Float elapsed]
|
||||
(super.update elapsed)
|
||||
@@ -214,7 +212,7 @@
|
||||
(set chooseNextEntry _chooseNextEntry)
|
||||
(_chooseNextEntry)))
|
||||
|
||||
|
||||
(var SCROLL_BOUND_MARGIN 200)
|
||||
(method handleChanges [:Archive archive :ChangeSet changeSet]
|
||||
(doFor e changeSet
|
||||
// process the WikipediaImageSystem and run spriteSystem process on newly created entries that get one
|
||||
@@ -222,6 +220,8 @@
|
||||
// Do a second loop through the systems, so Playground systems that trigger Core systems have their effects processed
|
||||
(archive.processSystems this)
|
||||
|
||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN)
|
||||
|
||||
// Entries whose data changed to remove them from the sprite pool will already have been removed
|
||||
// by refreshEntry()
|
||||
(when (spriteSystem.entries.exists e.id)
|
||||
|
Reference in New Issue
Block a user