Hello! I was trying to figure out how to solve this earlier, by asking about how to tell if a button is being held. But I'm still having a little bit of trouble with it. I'm trying to make a platformer, and I'm trying to figure out how to have the player look idle when nothing is being pressed, and swap to a running version while the player is moving the character. I just can't figure out how to tell when the player is moving the character. How might I accomplish this?
When you press a direction on the d-pad the player will attempt to move in that direction and the update
event in the player script will be called.
When you hold a direction on the d-pad the behaviour depends on these config values:
config.inputRepeat
config.inputRepeatDelay
config.inputRepeatBetween
By default config.inputRepeat = 1
which means the game will treat holding a direction like it is being repeatedly pressed, at a rate defined by the "inputRepeat" config values.
In other words you can tell if the player is holding a direction (and therefore attempting to move the player character) using the update
event in the player script.
You could try swapping the player to a running version in the update
event. To swap back to idle you could also set a variable that gets reduced every frame in the game's loop
event, and if 0 swaps the player to idle.
In the player
script:
on update do
swap "player running"
player_running = 5
end
In the game
script:
on loop do
if player_running>0 then
player_running--
if player_running==0 then
tell event.player to
swap "player idle"
end
end
end
end
There are others ways you could do it do, that's just one idea!