Scrolling Game Development Kit Forum
SGDK Version 2 => Help, Errors, FAQ => Topic started by: durnurd on 2008-12-14, 11:58:29 AM
-
I'm trying to display a message when the player is within a plan and presses button 1. Then, to dismiss it, they press button 1 again. However, since the player is still in the plan, the message shows up again. Is there a method to get around this silliness?
-
Isn't there a "WasTouching" function that determines whether the player was touching the plan before versus just started touching it?
-
I don't want the message to show up when they first touch the plan. If they're inside the plan, and the message is not showing, and they press button 1, show it. If the message IS showing, hide it.
-
initial touch only? (SGDK1 terms) or else only appears when you press (1)
-
Or add a counter set to 0 initially that increments on running of the rule, then have the message only run when the counter is = to 0.
-
I don't want the message to show up when they first touch the plan. If they're inside the plan, and the message is not showing, and they press button 1, show it. If the message IS showing, hide it.
In that case, don't you just need to turn on the "InitialOnly" option of the "IsInputPressed" function? Or is your problem determining that the message is already showing? Can you use a map flag for that?
-
My thought was that this really shouldn't need to be complicated. My suggestion: when displaying a message that has freezeInputs selected, don't change oldInputs. Then, when the message disappears, copy the input state as it was when the message displayed into oldInputs. This may seem more complicated up front, but you only have to do it once.
Or, if that doesn't appeal to you, just copy the current inputs into oldInputs when the message is dismissed. This makes sense in any case, whether the message input handling happens before or after the sprite handling.
-
I just noticed that this could be a problem, because the message doesn't know what sprite, if any, it's freezing. Still, there's got to be a simpler way.
-
OK, I didn't fully understand the problem before, but now I do. One solution is to use a different button to trigger the message than you use to dismiss the message :).
It also seems to work if you cut the "inputs = 0" line in SpriteBase.MapPlayerToInputs and paste it inside the if block below. Whaddya think, is that a sound solution?
-
OK, that's no good either because if you're moving while you trigger the message, you won't stop moving until you dismiss it. Here's my "final answer" - change GeneralRules.cs:
Replace the declaration of dismissReleased with
private static byte[] dismissPhase = null;
Replace the code after dismissPressed is set and before FreezeInputs is checked in PlayerPressButton with:
// dismissPhase[x]:
// 0 = No frames have passed yet
// 1 = Frames have passed and the dismiss button was initially pressed
// 2 = Frames have passed and the dismiss button is not pressed
// 3 = Dismiss button was not pressed, but now it is.
if (dismissPhase == null)
dismissPhase = new byte[Project.MaxPlayers];
if (dismissPressed)
{
if ((dismissPhase[msg.player] == 0) || (dismissPhase[msg.player] == 2))
dismissPhase[msg.player]++;
}
else
{
if (dismissPhase[msg.player] < 2)
dismissPhase[msg.player] = 2;
else if (dismissPhase[msg.player] > 2)
{
DismissMessage(i);
dismissPhase[msg.player] = 0;
}
}
-
woo, yay, and such