fix DragState null camera error
This commit is contained in:
@@ -11,7 +11,7 @@ import openfl.geom.Rectangle;
|
|||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
|
|
||||||
typedef DragState = {
|
typedef DragState = {
|
||||||
camera:FlxCamera,
|
camera:Null<FlxCamera>,
|
||||||
debugLayer:DebugLayer,
|
debugLayer:DebugLayer,
|
||||||
enabledSprites:Array<KissExtendedSprite>,
|
enabledSprites:Array<KissExtendedSprite>,
|
||||||
selectedSprites:Array<KissExtendedSprite>,
|
selectedSprites:Array<KissExtendedSprite>,
|
||||||
@@ -44,7 +44,6 @@ class DragToSelectPlugin extends FlxBasic {
|
|||||||
|
|
||||||
public function enableSprite(s:KissExtendedSprite, ?state:FlxState, ?camera:FlxCamera) {
|
public function enableSprite(s:KissExtendedSprite, ?state:FlxState, ?camera:FlxCamera) {
|
||||||
if (state == null) state = FlxG.state;
|
if (state == null) state = FlxG.state;
|
||||||
if (camera == null) camera = FlxG.camera;
|
|
||||||
if (!dragStates.exists(state)) {
|
if (!dragStates.exists(state)) {
|
||||||
dragStates[state] = {
|
dragStates[state] = {
|
||||||
camera: camera,
|
camera: camera,
|
||||||
@@ -54,6 +53,7 @@ class DragToSelectPlugin extends FlxBasic {
|
|||||||
firstCorner: null,
|
firstCorner: null,
|
||||||
secondCorner: null
|
secondCorner: null
|
||||||
};
|
};
|
||||||
|
if (camera == null) camera = FlxG.camera;
|
||||||
dragStates[state].debugLayer.cameras = [camera];
|
dragStates[state].debugLayer.cameras = [camera];
|
||||||
state.add(dragStates[state].debugLayer);
|
state.add(dragStates[state].debugLayer);
|
||||||
} else {
|
} else {
|
||||||
@@ -77,14 +77,17 @@ class DragToSelectPlugin extends FlxBasic {
|
|||||||
var dragState = dragStates[FlxG.state];
|
var dragState = dragStates[FlxG.state];
|
||||||
dragState.debugLayer.clear();
|
dragState.debugLayer.clear();
|
||||||
|
|
||||||
|
var camera = dragState.camera;
|
||||||
|
if (camera == null) camera = FlxG.camera;
|
||||||
|
|
||||||
// have to skip a frame after justPressed, so KissExtendedSprites
|
// have to skip a frame after justPressed, so KissExtendedSprites
|
||||||
// can get first access to the mouse input
|
// can get first access to the mouse input
|
||||||
if (FlxMouseControl.dragTarget == null) {
|
if (FlxMouseControl.dragTarget == null) {
|
||||||
if (wasJustPressed && FlxMouseControl.clickTarget == null) {
|
if (wasJustPressed && FlxMouseControl.clickTarget == null) {
|
||||||
deselectSprites();
|
deselectSprites();
|
||||||
dragState.firstCorner = FlxG.mouse.getWorldPosition(dragState.camera);
|
dragState.firstCorner = FlxG.mouse.getWorldPosition(camera);
|
||||||
}
|
}
|
||||||
dragState.secondCorner = FlxG.mouse.getWorldPosition(dragState.camera);
|
dragState.secondCorner = FlxG.mouse.getWorldPosition(camera);
|
||||||
if (dragState.firstCorner != null && dragState.selectedSprites.length == 0) {
|
if (dragState.firstCorner != null && dragState.selectedSprites.length == 0) {
|
||||||
var rounded1 = dragState.firstCorner.copyTo();
|
var rounded1 = dragState.firstCorner.copyTo();
|
||||||
var rounded2 = dragState.secondCorner.copyTo();
|
var rounded2 = dragState.secondCorner.copyTo();
|
||||||
|
@@ -106,13 +106,13 @@ class KissExtendedSprite extends flixel.addons.display.FlxExtendedSprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _dragToSelectEnabled = false;
|
var _dragToSelectEnabled = false;
|
||||||
public function enableDragToSelect(?state:FlxState) {
|
public function enableDragToSelect(?state:FlxState, ?camera:FlxCamera) {
|
||||||
var plugin = FlxG.plugins.get(DragToSelectPlugin);
|
var plugin = FlxG.plugins.get(DragToSelectPlugin);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
plugin = new DragToSelectPlugin();
|
plugin = new DragToSelectPlugin();
|
||||||
FlxG.plugins.add(plugin);
|
FlxG.plugins.add(plugin);
|
||||||
}
|
}
|
||||||
plugin.enableSprite(this, state, thisCamera());
|
plugin.enableSprite(this, state, camera);
|
||||||
_dragToSelectEnabled = true;
|
_dragToSelectEnabled = true;
|
||||||
}
|
}
|
||||||
public function disableDragToSelect(?state:FlxState) {
|
public function disableDragToSelect(?state:FlxState) {
|
||||||
|
Reference in New Issue
Block a user