A combination of using anyJustPressed and insert fixed things. Thanks!
W
wrldwzrd89
@wrldwzrd89
0
Reputation
3
Posts
649
Profile views
0
Followers
0
Following
Posts made by wrldwzrd89
-
RE: Creating and adding a FlxSprite in response to user input hangs my game!
-
RE: Creating and adding a FlxSprite in response to user input hangs my game!
I am checking for FlxG.keys.anyPressed([SPACE]) and setting the result to the _space variable.
Also, forgot to mention this earlier, but this game has a public GitHub repository, here. If anyone needs to look at full code, it's there.
-
Creating and adding a FlxSprite in response to user input hangs my game!
Here's the gist of what I'm trying to do:
class PlayState extends FlxState { private function generatePiece():FungalPiece { return new FungalPiece(FungalPieceColor.Red, FungalPieceType.Single, this, 40, 64); } public function nextPiece():Void { var _nextPiece = generatePiece(); add(_nextPiece); } }
package; import flixel.FlxSprite; import flixel.FlxG; import flixel.math.FlxPoint; class FungalPiece extends FlxSprite { private var speed:Float = 200; private var _active:Bool = true; private var _playState:PlayState; public function new(color:FungalPieceColor, type:FungalPieceType, play:PlayState, ?X:Float=0, ?Y:Float=0, ?active:Bool=true) { super(X, Y); _active = active; _playState = play; // a bunch of code here to initialize the image } private function movement():Void { if (_active) { // move the piece code goes here if (_space) // if user presses the SPACE key { _active = false; _playState.nextPiece(); } } } }
When nextPiece() gets called, the current piece is locked, and a new piece is generated and is supposed to be added to the PlayState. This is causing the game to hang / freeze. There's got to be a "correct" way to do this; I just do not know what it is!