Page 1 of 2
Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Jul 30, 2014 9:00 am
by maxs
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Jul 30, 2014 10:24 am
by jmburnod
Hi Max,
I never use Updatescreen
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Jul 30, 2014 10:32 am
by maxs
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.
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Jul 30, 2014 10:46 am
by jmburnod
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Jul 30, 2014 8:57 pm
by maxs
Thank you for the PendingMesseges tip.
Max
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Wed Dec 17, 2014 11:23 pm
by sturgis
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.
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Thu Dec 18, 2014 12:09 am
by sturgis
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Sat Dec 20, 2014 10:57 pm
by maxs
Thank you. All three for your files are terrific. Max
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Sun Dec 21, 2014 12:43 am
by Newbie4
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Sun Dec 21, 2014 1:42 am
by sturgis
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.
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Sun Dec 21, 2014 9:25 am
by maxs
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Mon Dec 22, 2014 3:52 am
by Newbie4
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Mon Dec 22, 2014 6:51 am
by maxs
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.
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Mon Dec 22, 2014 3:36 pm
by Newbie4
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
Re: Using Updatescreen in Game Loops (Game Academy)
Posted: Mon Dec 22, 2014 4:51 pm
by sturgis
Great stuff, thanks for sharing. More stuff for me to read yay!