# magicskillz's questions

First question: How do you make your charactar jump?

How do you make you charectar jump when you touch the screen?
Some easy example code that you can use as a layout:

`function setup() end -- This function gets called once every frame function draw () -- This sets a dark background color background(40, 40, 50) fill(255, 2, 0, 255) --make your charactar ellipse(WIDTH/4,HEIGHT/4.2,100) --make the ground fill(70, 255, 0, 255) rect(WIDTH/4, HEIGHT/50,550, 170) rectMode(RADIUS) end `

First, you should add the function touched(t). When the screen is touched, and the touch state is equal to BEGAN, then you add an amount to the y value of the character. After it jumps to whatever height you want, you subtract an amount until the character is back to the original position.

Here is a simple example.

``````function setup()
v=0
x=300
y=300
end

function draw()
background(40, 40, 50)
stroke(255)
strokeWidth(3)
line(0,250,WIDTH,250)
sprite("Platformer Art:Guy Standing",x,y)
y=y+v
if y>400 then
v=-2
elseif y<=300 then
v=0
end
end

function touched(t)
if t.state==BEGAN then
v=2
end
end
``````

Thanks

Also how do you make it so when you tilt your device your charectar moves

Try using Gravity.x or Gravity.y .

Add this line to the end of the draw function in my code above.

``````    x=x+Gravity.x*10
``````

@dave1707
Thanks a lot for helping me in my learning so far

How do you make the camera follow the charactar in your game?

translate(char.x,char.y)

I’d like to suggest you do some reading about these things, because while we are happy to solve problems and provide general guidance, we don’t have the time to provide personal tuition on every aspect of Codea.

So if you are trying to make a game, and planning to ask us how to do each and every step in it, because you know very little about Codea, I’d like you to stop right now - and first learn as much as you can about Codea (and Lua, the language behind it).

There is lots of helpful stuff on the wiki link above, and I have also written a lot of stuff on Codea, which you can find here:

The next step, if you have a question, is to google the forum to see if there is an answer (search box at upper right). It’s very important that you figure out how to solve as many problems as possible, by yourself. That’s an important part of being a programmer.

Only then, if you are still stuck, should you ask us a question. That way, you don’t waste our time.

And that’s important to you, too, because if people keep asking us unnecessary questions, we stop answering them.

@Ignatz
sigh. You have a point. I won’t ask questions on Codea

@dave1707, isn’t gravity a tag for the iPad’s Gravity position?

You CAN ask questions, but do your homework first. The forum should be last on your list of places to look for solutions, not the first.

@Ignatz
I DID do my research and I cant find a answer maybe I’m not typing in the right words to the search box. But how do allow your character to move in the air while jumping. My guess is that you have to add the x to the y but how?

If the Sprite is moving in the x direction when the character jumps, it will still be moving in the x direction. Or do you mean that the character is stationary and when the character jumps, it moves in the x direction. If that’s the case, then just add 1 or subtract 1 from the x value until the character stops the jump.

@magicskillz - you won’t find a specific answer to that question on the forum. But that’s not where you should be looking.

To answer your question, you need to understand how to move stuff around on the screen, rather than how to move the character while jumping - because moving while jumping is simply moving around on the screen!

Moving stuff on the screen is covered in many tutorials, including my ebooks, and in lots of sample code. That’s where you’ll find the answer to questions like this. And if you don’t know how to change the x and y values, you need to do some more reading about Codea before trying to program it.

Thx and by the way I do know how to change the x and y values but it didn’t work

@magicskillz I strongly suggest that you read the ebook by Ignatz before asking these questions. The things you’re asking concern rather basic things, and you won’t make much progress if you never take time to study the matter a little bit.

It can be found here: https://www.dropbox.com/sh/mr2yzp07vffskxt/AABlplSGGFBTu8FzQy94lteua/Lua%20for%20beginners.pdf?dl=0
It helped me a lot when I started using Codea!

Been looking at Ignatz’s books and made this code but it’s not working I also FIXED the code because of @dave1707’s comment

``````supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
gameState=0
x=100
y=300
cam = vec2(0,0)
done=true
cb={x=60,y=300}
val=2
end
function draw()
if GameState==0 --mainscreen
then
font("Copperplate-Bold")
fontSize(75)
--title
fill(0, 255, 8, 255)
fontSize(25)
--Name
fill(235, 5, 10, 255)
textAlign(CORNER)
text("By Magic Skillz", WIDTH/6, HEIGHT/30)
if gameState==2 then
cam.x = cam.x - DeltaTime*119.3
background(40, 40, 50)
fill(255)
translate(cam.x,cam.y)
x=x+3
cb.x=cb.x+val -- move sprite
sprite("Planet Cute:Character Boy",cb.x,cb.y)
end
function jumpTween()
t1=tween(.5,cb,{y=400},tween.easing.cubicOut)
t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
tween.sequence(t1,t2)
end

function duckTween()
t1=tween(.5,cb,{y=200},tween.easing.cubicOut)
t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
tween.sequence(t1,t2)
end

function draw()
-- draw sprite
end

function tweenDone()
done=true   -- tween is done, allow next jump
end

function touched(t)
if t.state==MOVING and done then
done=false
if t.deltaY<0 then
duckTween()
end
end
if t.deltaY>0 then  -- flick up
jumpTween()
end
end
end
end
``````