Need a G key command
ZeroRaven
Member Posts: 33
I'm working on a rtype WWII game and I want to have the G key when pressed once, drop the gear or raise the gear.
The Gear animation is a 5 frame animation, and presently only plays when G is held down. And then I cant seem to get the gear to raise unless its just back to frame 1 of animation right then. Any thoughts?
The Gear animation is a 5 frame animation, and presently only plays when G is held down. And then I cant seem to get the gear to raise unless its just back to frame 1 of animation right then. Any thoughts?
Comments
Make a new Boolean attribute called:
gearState (set it to false to start with)
Make a behavior:
When key G is pressed AND when gearState = false
Play the drop gear animation AND set gearState to True
Make another behavior:
When key G is pressed AND when gearState = True
Play the raise gear animation AND set gearState to False
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
This is how its set up right now:
Rule: When ALL are happening
Key: Recieves press "G" is "Down"
Attribute: if "self.gearstate" is "False"
Do:
Animate: Frames set from Gear up o Gear down
Change Attribute: Set "self.gearstate" to "True"
and Vice versa for the "Gear up" animation.
Hi @ZeroRaven I'm not sure why the version @jamie_c gave you isn't working as it should, so perhaps try this other method:
Rule: When key G is down
Rule: ---nested in above--- When self.gearstate is false
Animate gear up to gear down
Change attribute self.gearstate to true
Otherwise
Animate gear down to gear up
Change attribute self.gearstate to false
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
When you say ~Nested in above~ Do you mean create another Rule INSIDE the rule that exists?
Or do you mean as I've already set it up, just add the gear up animation in the "else" section.
Downside seems to be that when G is not being pressed the gear up animation plays and I can only have gear down as long as G is pressed.
Have I missed a step?
"Nested in above": yes, the second rule inside the first.
The "else" section is the same as the Otherwise section... Ah, I see; OK, if the animation plays even when G is not being pressed, then the rules can't be nested properly.
But either gear up or down will only work as long as G is pressed with this setup; I didn't realise you wanted differently, sorry.... give me 10 minutes and I'll be back with a solution for you.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Then you can stop and reverse the animation whenever you want. I am not at my Mac right now, else I could help you better . (
Lump Apps and My Assets
Hi again @ZeroRaven Sorry for the delay in getting back to you (it was a bit of a long 10 minutes!)....
I've sorted a way for for each animation to play in full when the G key is pressed (and even when released, as you want); also i've included a timer so that if the G key is pressed during an animation, it won't affect it.
So hopefully the following will do exactly what you're after now:
Make a boolean, let's call it Gswitch
Remake your attribute called gearstate as an integer
------------
Rule: When key G is down AND self.Gswitch is false
Rule--- nested in above--- When self.gearstate = 0
Change Attribute self.gearstate to 1
Otherwise
Rule: When self.gearstate = 1
Change Attribute self.gearstate to 2
-------------
Rule: When self.gearstate = 1
Change Attribute self.Gswitch to true
Animate ---gear up to down
Timer: After ? seconds ---- length of time of animation
Change Attribute self.Gswitch to false
------------
Rule: When self.gearstate = 2
Change Attribute self.Gswitch to true
Animate ---gear down to up
Timer: After ? seconds ---- length of time of animation
Change Attribute self.gearstate to 0
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
*bump* thread for @ZeroRaven if solution above still needed...
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
rule: when g is pressed && gearsdown = false, then gearsdown = true
rule: when g is pressed && gearsdown = true, then gearsdown = false
Note: it doesn't matter what method you use to toggle the boolean above^^
rule: if gearsdown = true, then animate gears-going-down
rule: if gearsdown = false, then animate gears-going-up
the reason some of the others wouldn't work is because the animation was inside the rule that g must be down, so therefore the animation would only go when g was down. But, by using a separate rule you can avoid the problem, because the boolean gearsdown doesn't revert back after g is lifted
Animation plays once, and the refuses to accept another toggle even when held down.
I may need to have the gear lowering conditional to certain points, and not player controlled as I'd hoped.
Just a question though and aplogies if it's already mentioned.
When you press G the gear animates down. And you want that to go all the way down even if G is no longer being pressed.
Then press G again and it goes all the way pack up with out stoping even if G is not being pressed ??
http://www.filedropper.com/landinggear
And @socks It never occured to me to use a mouse click to toggle gear. Thanks for another thought to it too.
Hopefully the other guys info or @Socks test file helps you out; still, as a matter of record, here is a test file of my suggestion, with part of an explosion sequence in place of the gears up and down, as an example only:
To mention again, pressing the G key won't do anything if one of the animation sequences is still playing. As soon as a sequence has played, the G key will trigger the animation again. This flips from one to the other as you want:
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-----------------------------
rule:
key press G
if game.gear = false
Do:
rule:
if game.newgear = 0
do:
change attribute: game.newgear = 1
--------------------------------
Rule:
if game.newgear = 1
do:
change attribute: set game.gear = true
Animate: Gear Down
Timer: after 1 second (run to completion)
- Constrain game.gear = false
----------------------------------
Rule:
if game.newgear = 2
Do:
Animate: gear up
Timer: after 1 second (run to completion)
- Change atrribute: game.newgear = 0
------------------------------------
Please forgive my shorthand.
I used the setup from your example as a template more or less. Now the gear down animation plays perfectly. Can these rules be "prototype" specific or must it be "instance" specific?
Do I need to make a copy of block 1 to handle the game.newgear 1 change to 2?
They can be either, whichever you prefer, in this case.... I guess you'll want them prototype specific which is fine as no other actor attribiutes are referenced.
To do this, make the attributes newgear and gear as self attributes (in the prototype in the Inspector, as I'm sure you know) and it should work out fine.
PS in your shorthand programming above, there seems to be the Otherwise section missing, but I guess that's included in your actual file....
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thanks @gyroscope , your a big help.