Using Updatescreen in Game Loops (Game Academy)

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Wed Jul 30, 2014 9:00 am

Hi

In the first video from the Game Academy, Hanson mentions that in order to make game loops that an "UpdateScreen" message is needed. He goes on to say that it is currently not implemented in Livecode, but will be implemented in the coming weeks. That I don't need to worry about it.

Well, it's been 2 years since the video, and I cannot find "Updatescreen" message in the livecode dictionary. SO what do I do in order to make a simple game loop? Has "UpdateScreen" been implemented in Livecode? Do I use an "On idle" handler? Does anyone know the game loop code for starting and stopping objects?

The academy is great, but I still do not know how to make game loops.

Max

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by jmburnod » Wed Jul 30, 2014 10:24 am

Hi Max,

I never use Updatescreen :oops:
What do you use for your loop ?
• "repeat" or "send in time"
I often heard that using idle seems not a good way and "send in time" is better than repeat
I use "send in time" without Updatescreen and it works fine for me

Best regards
Jean-Marc
https://alternatic.ch

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Wed Jul 30, 2014 10:32 am

Do you mean like:

local sTime
on mouseUp
put 0 into sTime
send "timerIncrement" to me in 1 seconds
end mouseUp

on timerIncrement
add 1 to sTime
put sTime
send "timerIncrement" to me in 1 seconds
end timerIncrement

SO I guess this may be better than updatescreen. I can't find it in the dictionary anyway. Thanks.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by jmburnod » Wed Jul 30, 2014 10:46 am

Yes.
Don't forget delete pending message to avoïd unnecessary pendingmessages

Code: Select all

--••stop one pending pMessage
on doStopPending pMessage
   repeat for each line aLine in the pendingmessages
      if pMessage is in item 1 of aLine then
         cancel item 1 of aLine
      end if
   end repeat
end doStopPending
https://alternatic.ch

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Wed Jul 30, 2014 8:57 pm

Thank you for the PendingMesseges tip.

Max

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Using Updatescreen in Game Loops (Game Academy)

Post by sturgis » Wed Dec 17, 2014 11:23 pm

updatescreen is code provided during the academy to generate the loop. it actually works pretty well, the result being an updatecreen message that is dispatched every 50 milliseconds. (20fps) (if I recall correctly).

Updatescreen was never implemented in the engine, but the stackscript that was provided does a good job. At that point, its a simple matter to utilize.

on updatescreen
if not sGameRunning then exit updatescreen
checkthisstuff
checkthatstuff
lookforcollisoins
dowhateverelse
end updatescreen

The biggest issue, whether writing your own loop, or using the code provided by David Williams, is if you're stacking too much to be accomplished in 50ms. For things like movement, its important to track time and use the difference between then and now as part of your movement scaling.

I haven't needed to worry about the scaling with the things I've done so far, so wouldn't be much help with that. If you want to see some simple examples using the gameloop, I can post a very very basic breakeout start, as well as a rocket you can fly around the screen (it shoots too!) Also, if I can locate it, I have an example of rolling a ball around screen using accelerometers. On desktop, a yellow controlbox appears that you cna click and hold, them move the mouse to simulate accelerometer movement. My wall detection in that one needs a major revamp though, so i'm waiting for box2d.

EDIT to add zip of stack files.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Using Updatescreen in Game Loops (Game Academy)

Post by sturgis » Thu Dec 18, 2014 12:09 am

File was too big, so heres a dropbox link to it. https://dl.dropboxusercontent.com/u/119 ... estuff.zip

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Sat Dec 20, 2014 10:57 pm

Thank you. All three for your files are terrific. Max

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by Newbie4 » Sun Dec 21, 2014 12:43 am

There are a few tutorials and examples here:
https://sites.google.com/a/pgcps.org/li ... rogramming
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Using Updatescreen in Game Loops (Game Academy)

Post by sturgis » Sun Dec 21, 2014 1:42 am

maxs wrote:Thank you. All three for your files are terrific. Max
Feel free to use them for whatever. Be aware though, the images in the asteroid framework, I've no clue where I got them, so you'd want to make sure to replace them with something else for legality sake.

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Sun Dec 21, 2014 9:25 am

These are terrific resources I never knew about. Thanks. Who made these?

Max


There are a few tutorials and examples here:
https://sites.google.com/a/pgcps.org/li ... rogramming

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer

Posts: 137
Joined: Sun Apr 15, 2012 12:17 am
Location: USA

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by Newbie4 » Mon Dec 22, 2014 3:52 am

I am a teacher and I they came about as a result of my classes. I wrote them to help my students learn game programming using LiveCode. They have fun creating their very own games while learning about programming and computer science. It has been effective in attracting more girls and minorities to further studies in computers.

They learn how to break big problems into solvable pieces, about logic, problem solving, creativity, patience, debugging many other life skills taught only in computer science.

They also produce some amazing games that are challenging yet fun to play.

Thanks for the complement and I hope they help you. I look forward to seeing some of your games.

Thanks,
Newbie4
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by maxs » Mon Dec 22, 2014 6:51 am

I want to share my apps with you, and I would love to see what your students came up with. Max7@aol.com

Max
Great sentence:
They learn how to break big problems into solvable pieces, about logic, problem solving, creativity, patience, debugging many other life skills taught only in computer science.

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Using Updatescreen in Game Loops (Game Academy)

Post by Newbie4 » Mon Dec 22, 2014 3:36 pm

You can download and try some of them here http://erhs.shaosean.tk. I will be putting up more next week that are even better. I am always finding more effective ways of presenting the material and teaching the concepts, so the games keep getting better. I try to keep the website updated but get behind uploading their work.

I am also working on teaching them to do mobile apps and doing standard computer programs ( calculating, working with text, files, functions, etc). Those can be accessed from here https://sites.google.com/a/pgcps.org/livecode/home

I welcome any suggestions, samples of code, ideas...

Thank you
Cyril Pruszko
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Using Updatescreen in Game Loops (Game Academy)

Post by sturgis » Mon Dec 22, 2014 4:51 pm

Great stuff, thanks for sharing. More stuff for me to read yay!

Post Reply

Return to “Games”