Hello, I was wondering. Does anyone happen to have some code that might help me? I’m working on a sidescroller that moves only to the right. And the players’ sprite itself has three actions:
- Jump, so to get over passing obstacles.
- Duck under obstacles.
- Shoot a bullet when the screen is double tapped
I would like to use functions to be carried out through the swipe of a finger.
Any help is much appreciated. Such as links to perhaps video tutorials.
I made a library a while ago called Flickable that has easy access to swiping & tapping, you could try that. (But you could code one yourself, if you want to.)
Thank you guys. I would much rather get these helpful links than be spoon fed code. But if I need help with altering code, expect a post here. Thanks again
I had trouble finding my way through the coolcodea.wordpress, but I got it.
@Ignatz, I was wondering if you have any coding tutorials on a sidescroller that automatically moves to the right with the player’s sprite in a running animation (but remaining stationary on the screen), until a the screen is tapped, or swiped to make the sprite duck, or jump. Along with that, is there a way to program the game to randomly spawn things, such as enemies, bonuses, coins, and even a slight gap and height between “platforms” that the player’s sprite runs on? Basically, The game runs until the player dies.
My side scroller moves to the right, keeping the player in the middle (unless the player is at the far left or right of the map)
Use math.random to include randomness
Any tutorials you could send my way?
“My side scroller moves to the right, keeping the player in the middle (unless the player is at the far left or right of the map)”
I see that you can control wether you want the player’s sprite to move right OR left with controls. I want the sprite to always be moving to the right, with no ability for the player to control the direction, just the “jump” movement, via the screen is double tapped
why don’t you try writing some simple code yourself?
if that’s too hard, then you may not be ready for this project
Look at angry birds for instance, the bird never moves from its position, but the side scroller does not stop, until a collision is detected
Just in case anyone wants a simple version of swiping and double tap, here’s one. Just double tap or swipe up, down, left, or right.
-- detects double tap, swipe up, down, left, or right.
if t.state==BEGAN then
if t.tapCount==2 then doubleTap() else tx=t.x ty=t.y end
if t.state==ENDED then
local dx=t.x-tx local dy=t.y-ty
local dxa=math.abs(dx) local dya=math.abs(dy)
if dxa>30 or dya>30 then
if dxa>dya then
if dx>0 then swipeRight() else swipeLeft() end
elseif dy>0 then swipeUp() else swipeDown() end
Thanks for the code @dave1707
@SkyTheCoder When I started coding, I wanted the smallest code that did the job. It was easier to understand. A lot of new coders make the mistake of using someone else’s “class” that has several hundred lines of code when they only need 20 to do what they need. That’s why I always post something small. Depending on what they need, they can use the small code or the “class”.
@dave1707 But it’s not a class, it’s a dependency you can add that works kind of like Codea as in it calls functions automatically and supplies them with parameters. Mine also does a lot of extra things to make sure it’s accurate. With your code, what if someone dragged their finger right, but it was a very long swipe, and it moved just far enough up that it qualified as a right and up swipe, even if to the user it looked like it was only going right?
Besides, he said to me “I don’t want to be spoon fed code,” but he’ll accept your code and not mine that we’re “spoon feeding” to him.
@SkyTheCoder Class or dependency, it’s 454 lines long and I’m not sure what all it does. Mine is 15 lines ( touched function ) and does what he wanted. There can’t be a right and up swipe. It will be either a right swipe or an up swipe. Whichever swipe direction is the longest is the direction of the swipe. And he’s not being spoon fed code. He has the choice to take you’re code, my code, or write his own. I’m just giving an example for anyone to use.
@dave1707 OH, I messed up, I just realized, it was two different people. I thought that the waffle man asked for code, then declined my code (“rather than being spoon-fed code”), and then accepted your code. I just noticed that it was a different person that said thanks for your code. Sorry. (But if you want to know what my code does, run it and see. I also wrote a tun of documentation on it.)
It’s good to have several versions, so thanks to both of you…