Do you guys know how to make a start and a pause button? I want to publish my game but I need a start and pause button.
function setup() playing = 0 paused = 1 state = paused end function draw() if state==paused then -- draw the pause menu text("play",WIDTH/2,HEIGHT/2) else -- draw the playing screen end function touched(t) if state==paused and t.state==ENDED then state=playing elseif state==playing and t.tapCount==5 then state=paused end
Something like this (untested, sent from an iphone)
The user and all related content has been deleted.
@Parker Here’s an example.
function setup() button="PAUSE" rectMode(CENTER) w=WIDTH/2 h=HEIGHT/2 end function draw() background(40,40,50) fill(255) rect(w,h,100,50) fill(255,0,0) if b=="PAUSE" then text(button,w,h) else text(button,w,h) end end function touched(t) if t.state==BEGAN then if t.x>w-50 and t.x<w+50 and t.y>h-25 and t.y<h+25 then if button=="PAUSE" then button="START" else button="PAUSE" end end end end
@NatTheCoder Did you even try to run the code Doge posted before you commented on it, because if you tried, you’d see that it doesn’t run. @Doge Did you try your code before you posted it, because it’s missing 2 “end” statements and doesn’t work.
@dave1707 I was on my phone and didn’t have my iPad with me, so I just tried to roughly demonstrate how to use states pause and playing, I didn’t really try to make a program that he could directly copy and use.
@Doge That explains it. Normally when someone post code on their phone, they say that, and also that the code may not work. I think that the majority of people who ask questions would like a working example so they can see how it is done. I usually look at how many posts they have and that gives me a good idea of how I respond to their question.
@dave1707 He did say that it made on an iPhone and that it might not work… But either way, I thought it was intended to be pseudo-code.
@SkyTheCoder I don’t think that was originally there, but added after I mentioned it. That doesn’t look like pseudo-code because once you add the 2 missing “end” statements, it runs kind of. Pseudo-code doesn’t run.
@Doge, were would I put that code? I would I put it in the main class that Is always in a codea project? Or do I create a new class then paste it?
@Parker - main isn’t a class, nor would you paste that code into a class. I suggest reading up on how Codea code works, otherwise it is going to be very confusing for you.
The wiki link above has useful info, I also have a Codea ebook that may help explain the basics for you
Ok, I don’t know why I sent that message I sent a few minutes ago. But whenever I play the game, it says play. You can’t click it or do anything. It just says play.
That’s because it’s an empty program, it doesn’t do anything. It isn’t supposed to. It’s just an example to show what was needed.
I don’t mean to be unkind, but if that isn’t clear to you, then I think you need to read up on Lua and Codea.
I need to finish the app on the 23rd of this month
and the bad thing is that I am a beginner. I have been working on this app for 2 to 3 years.
I need a working start and pause button script fast.
@Doge, can you send a working start button script when you have your iPad with you?
@Ignatz, I don’t have Dropbox and I am using a iPad right now.
Hi @parker, I believe the above samples describe pretty well how you should approach the start/pause thing. There’s no standard pause script afterall, what you need to do is to prevent moving/drawing of a certain set of objects when the pause state ( likely a simple variable ) is set. Hope this helps
@parker, you don’t need Dropbox to download a Dropbox file, just click and it will open in Safari