So, right now I am having another problem. Before, my character was able to jump while it’s moving left or right, but now it can’t. Unfortunately, I am not sure where this is happening.
Also, even though the isJumping flag works well now, it has no effect on my other problem. (Character stutters when pressing left or right in mid-air)
EDIT: I was able to solve this problem, by doing this:
local function makeControls(self, event) if anim.isJumping == false then if event.phase == "began" then if self.name == "left" then walk(-1) elseif self.name == "right" then walk(1) end elseif event.phase == "ended" then idle() end return true end end
But now my character won’t stop moving. Problem #2 fixed, problem #1 is back.
I know why this is happening because if the character is jumping, there is no phase to set the character back to idling. But, I don’t know how to fix it.
So what you’ve done, it appears, is disable all horizontal motion when the character is jumping. I assume that’s not what you want…
Here’s a list of things I would “plan” for a game like this, completely without thinking of your specific code at this time:
-
If character is on the ground (foot sensor touching at least 1 ground piece), he can jump.
-
If character is on the ground, his walking animation can happen when the user presses left or right, along with his actual left/right movement.
-
If character is not on the ground (foot sensor touching nothing), he can not jump again (no “air jumps” for this game).
-
If character is not on the ground (is jumping), his animation sequence can not change from the “jump” sequence.
-
If character is not on the ground (is jumping), his walking motion can happen (for an arched jump pattern) but not his walking animation.
-
Once character re-touches ground, his animation sequence goes back to “idle” (I assume).
This isn’t a complete list by any means, but it’s the main points I would consider when approaching a platformer. Please step through these and see how you’ve handled them in your code.
Brent
-
Check.
-
Check. (Unless the problem occurs)
-
Check.
-
Check. (Just got that to work)
-
Check. (Problem afterward, however)
-
Check. (Unless the problem occurs)
The problem I am talking about in this case is that when the user clicks on a button and drags off of it, the player will keep ‘skidding’ (It will move while staying at the end of the jump sequence). This is because of the way I set up my makeControls function. Though, I don’t know how to fix it.
local function makeControls(self, event) if anim.isJumping == false and anim.sequence ~= "jump" then if event.phase == "began" then if self.name == "left" then walk(-1) elseif self.name == "right" then walk(1) end elseif event.phase == "ended" then idle() end return true end end
This was the same problem I was faced with at the beginning of this post. Thank you for the list, it helped me clarify some issues.
Edited the post above.
Ah, now it’s clearer… you’re encountering the “slide off” issue it seems. When a user touches a directional button, but then “slides off” that button without releasing from the screen, something doesn’t “reset” in your game, correct?
Exactly. The character does not go back to its idling stage. Is this a common problem?
Like most things, “slide off” needs to be handled properly. Sorry I didn’t catch this aspect earlier.
Ironically, I’m working on an improved tutorial on this issue at the moment, but it’s not ready yet.
In the meantime, you should check out the sample project “SampleCode > Hardware > InputDevices” in your Corona application folder. It shows how slide-off can be checked using a 4-directional “virtual d-pad” which is basically what you’re doing here.
Brent
Thanks, I will take a peek.
Where is the slide-off check?
It’s not like a specific built-in event, just look at the “onTouchEvent()” function in “main.lua”. Notice how it uses both “began” and “moved” phases, and then sets a “vector” for the direction based on which button is being pushed. Basically, that makes it so that when you “slide off” one part and onto another, the movement vector changes to the new one being pressed (and thus the previous one doesn’t matter).
Great, but the problem occurs when I slide up and away from the joystick. I don’t slide onto another button, I slide away from all of the buttons, and it keeps moving in that direction.
It would appear I misinterpreted your previous post:
Ah, now it’s clearer… you’re encountering the “slide off” issue it seems. When a user touches a directional button, but then “slides off” that button without releasing from the screen, something doesn’t “reset” in your game, correct?
Test out the demo… notice how it handles when you slide off (say) the “up” direction onto nothing (not another button, off the controller).
I am aware, but this does not occur with mine. I will keep digging through this demo and see what I can find.
Yes, I understand, but you should probably re-build your controller around this model.
Note that the visual “D pad” is just an overlay over actual sensory objects. Comment out these two lines and you can see them. Those could be made into your arrow graphics or whatever.
-
–> btn.isVisible = false
-
–> btn.isHitTestable = true
Brent
Ah, this demo moves the character manually, I move the character with setLinearVelocity. No wonder. Well, I will look into replicating this for my project.
Could you possibly wait a day or so on this while I finish up the tutorial? I think it will exhibit a more simple way for you to build your directional controls…
Brent
Of course. I need a bit of a break.
As promised, here it is! I think this should help solve your virtual controller issues:
https://docs.coronalabs.com/tutorial/events/continuousActions/index.html
Brent