admin管理员组文章数量:1122826
I wanted to do a cool transition effect with random stickers filling your screen and then peeling off one by one but whenever I switch states the substate closes despite being told not to. It's just like switching states forcefully kills any substates that are currently open. this is how the substate's code looks like:
package;
import flixel.addons.transition.FlxTransitionableState;
import flixel.util.FlxTimer;
import flixel.FlxState;
import flixel.FlxSprite;
import flixel.FlxG;
import flixel.FlxCamera;
import flixel.group.FlxGroup;
class StickerTransition extends MusicBeatSubstate
{
var numStickers:Int;
var stickerx:Float = -100;
var stickery:Float = -100;
var stickerArray:Array<FlxSprite> = [];
var curStickerNum:Int = 0;
public static var shouldStick:String = '';
var speeee = 100;
var timer:FlxTimer;
var nextTarget:FlxState;
var stickerCamera:FlxCamera;
public static var switchingState:Bool = false;
public function new(target:FlxState)
{
super();
resetVariables();
nextTarget = target;
stickerCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height);
stickerCamera.bgColor.alpha = 0;
FlxG.cameras.add(stickerCamera, false);
numStickers = Std.parseInt(Paths.getTextFromFile('images/stickers/howmuch.txt', false));
while(stickery <= FlxG.height)
{
addSticker(FlxG.random.int(1, numStickers), stickerx, stickery);
}
FlxG.random.shuffle(stickerArray);
shouldStick = 'yeah';
}
override function create()
{
if (timer != null) timer.cancel(); // Cancel existing timer
timer = new FlxTimer(); // Assign new timer
timer.start(1 / speeee + FlxG.random.float(-0.005, 0.005), function(tmr:FlxTimer) {
timerTick();
}, 0);
}
function resetVariables()
{
curStickerNum = 0;
shouldStick = '';
stickerx = -100;
stickery = -100;
stickerArray = [];
switchingState = false;
}
public function stateLoaded()
{
shouldStick = 'nah';
switchingState = false;
}
function showSticker()
{
FlxG.sound.play(Paths.sound('sticker/'+FlxG.random.int(1, 8)));
add(stickerArray[curStickerNum]);
curStickerNum++;
if (curStickerNum == stickerArray.length)
{
shouldStick = '';
if(nextTarget != null)
{
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
switchingState = true;
FlxG.switchState(nextTarget);
}
}
}
function removeSticker()
{
FlxG.sound.play(Paths.sound('sticker/'+FlxG.random.int(1, 8)));
remove(stickerArray[curStickerNum]);
curStickerNum--;
if(curStickerNum < 0)
{
shouldStick = '';
close();
}
}
function timerTick()
{
if (shouldStick == 'yeah')
{
showSticker();
}
if (shouldStick == 'nah')
{
removeSticker();
}
}
function addSticker(num:Int, x:Float, y:Float)
{
var stickeridk:FlxSprite = new FlxSprite(x, y);
stickeridk.loadGraphic(Paths.image('stickers/'+num));
stickeridk.angle = FlxG.random.int(-45, 45);
var randscale:Float = FlxG.random.float(0.85, 1.1);
stickeridk.scale.x = randscale;
stickeridk.scale.y = randscale;
stickeridk.cameras = [stickerCamera];
stickeridk.antialiasing = ClientPrefs.globalAntialiasing;
stickeridk.updateHitbox();
//add(stickeridk);
stickerx += stickeridk.width / 2;
if (stickerx >= FlxG.width - 50)
{
stickerx = -100;
stickery += stickeridk.height / 2;
}
stickerArray.push(stickeridk);
//trace('made sticker');
}
override public function destroy()
{
if(switchingState) return;
super.destroy();
trace('destroyed.');
}
override public function close()
{
if(switchingState) return;
super.close();
resetVariables();
FlxG.cameras.remove(stickerCamera);
stickerCamera.destroy();
stickerCamera = null;
trace('closed.');
}
}
I tried to return the close and destroy functions, but to no use.
本文标签: haxeflixelFlxSubState force closing on state switchStack Overflow
版权声明:本文标题:haxeflixel - FlxSubState force closing on state switch - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299739a1930566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论