Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
on keyDown theKey
if theKey is space then
put -1 into birdDirection
end if
end keyDown
Hello! I have a question. What if in the code I want to put a "if key space or key up or key w" how do I do that? Sorry If I'm a newbie but please help me please. I'm making a flappy bird game following a udemy course on livecode by the way.
on keyDown KD
put empty into fld "fRESULT"
if KD is " " then
put "Space" into fld "fRESULT"
else
if KD is "w" then
put "w" into fld "fRESULT"
end if
end if
end keyDown
I don't think you can trap in the same way for 'key up' as you suggest;
local birdDirection
local birdVerticalSpeed
local gameIsRunning
local citySpeed
on preOpenCard
put 1 into birdDirection
put 4 into birdVerticalSpeed
put 3 into citySpeed
end preOpenCard
on startGame
preOpenCard
put true into gameIsRunning
flapBird
end startGame
on stopGame
put false into gameIsRunning
set the bottom of button "Bird" to 400
end stopGame
// move bird up and down
on flapBird
// move bird
put the bottom of button "Bird" into newPosition
add(birdDirection * birdVerticalSpeed) to newPosition
set the bottom of button "Bird" to newPosition
// move City_Background1
put the right of button "City_Background1" - citySpeed into newLoc
if newLoc < 0 then
set the left of button "City_Background1" to the right of button "City_Background2" - citySpeed
else
set the right of button "City_Background1" to newLoc
end if
// move City_Background2
put the right of button "City_Background2" - citySpeed into newLoc
if newLoc < 0 then
set the left of button "City_Background2" to the right of button "City_Background1"
else
set the right of button "City_Background2" to newLoc
end if
//
if gameIsRunning then
send flapBird to me in 0.02 seconds
end if
end flapBird
// control bird movements
on keyDown theKey
if theKey is space then
put -1 into birdDirection
else
if theKey is "w" then
put -1 into birdDirection
end if
end if
end keyDown
on arrowKey AK
if AK is "up" then
put - 1 into birdDirection
end if
end arrowKey
on keyUp
put 1 into birdDirection
end keyUp
So I've tried and it kinda works but not quite still. My flappy bird in the game is meant to go up once with the keep press but when I use the up arrow key it continues to go up after I pressed it.
how do i put in image please too (edit: thanks for telling me )
Last edited by Starpat on Fri Nov 29, 2019 5:22 pm, edited 3 times in total.
on rawKeyDown RAWK
put empty into fld "fKEE"
switch RAWK
case "32"
put "SPACE" into fld "fKEE"
break
case "119"
put "w" into fld "fKEE"
break
case "65362"
put "UP" into fld "fKEE"
break
default
pass rawKeyDown
end switch
end rawKeyDown
Starpat wrote: Thu Nov 28, 2019 8:20 pm
how do i put in image please too
ksnip_attachFiles.png
Once you've done the above steps, place the cursor where you want the picture to show up in the reply and click the "Place inline" button
Yes, but only after you have at least 10 postings!
So in your next (but one) posting you can add images, links etc.