Objects Moving Too Fast For LiveCode?

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
7Leven
Posts: 18
Joined: Sat Oct 11, 2014 2:06 am

Objects Moving Too Fast For LiveCode?

Post by 7Leven » Tue Feb 24, 2015 6:15 am

Alright so basically I'm developing a game that has many objects moving around the screen at once, randomly, at various speeds.

As some of you may have known, LiveCode does not handle fast movement of objects well. When you do it, for example, if you move a button across your screen in .25 seconds, the animation is very fidgety and it is almost as if it cuts in and out, but only part of the button's animation does.

I tried to record a .gif of it but that didn't go over well and you can hardly see what I'm talking about. Plus the forums wont let me post the gif so darn.

Basically, I'm wondering if there's anything I can do to fix what I'm talking about. If you don't know what I'm talking about. Create a button, make it a rounded button, give it a color, and then move it across your entire monitor in .20 seconds and you'll see my issue. (Do that exactly)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Objects Moving Too Fast For LiveCode?

Post by Simon » Tue Feb 24, 2015 7:06 am

Hi 7Leven,
Have you tried the

Code: Select all

wait 0 millisecs with messages
trick?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Objects Moving Too Fast For LiveCode?

Post by Simon » Tue Feb 24, 2015 7:23 am

ooops, sorry.
You used the "move" command, I was thinking more of a game loop type structure.
Do you know how to build one of those?

I had a liveCode demo somewhere of 100 balls bouncing off the walls with no delay.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Objects Moving Too Fast For LiveCode?

Post by Dixie » Tue Feb 24, 2015 9:11 am

Even as it stands today, liveCode is not too shabby at moving things... Have a look at this offering by John Craig
https://www.youtube.com/watch?v=a_716ei8WOo
Things might get a whole lot better if liveCode gets the physics engine from the kickstarter campaign..

7Leven
Posts: 18
Joined: Sat Oct 11, 2014 2:06 am

Re: Objects Moving Too Fast For LiveCode?

Post by 7Leven » Tue Feb 24, 2015 4:01 pm

Simon wrote:ooops, sorry.
You used the "move" command, I was thinking more of a game loop type structure.
Do you know how to build one of those?

I had a liveCode demo somewhere of 100 balls bouncing off the walls with no delay.

Simon
I actually want to use a game-loop type structure but I am unsure how to do this.
My next problem, which I was going to post on the forums, is finding out how to move all my objects at once. I know I could just do a bunch of if statements and move commands. But I figured there was a more efficient way to do so.
One thing that makes my problem of moving them all is that when I move them, I generate a button on the screen with code. It is not placed there manually. As a result, I give the buttons a number. But when they're clicked on, they are deleted, but it is now difficult for me to detect which buttons are deleted which means using a bunch of if statements is also difficult.

Anyway, this loop type structure of a game sounds promising as if it will fix all my problems, may I see your demo?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Objects Moving Too Fast For LiveCode?

Post by Simon » Tue Feb 24, 2015 8:13 pm

Hi 7Leven,
Here is the basics of a loop
New card 2 buttons this code in the second btn;

Code: Select all

local goNow
on mouseUp
   if goNow = true then
      put false into goNow
   else put true into goNow
   moveButton
end mouseUp

on moveButton
   if goNow = true then
      if the right of btn 1 <= the width of this card then
         set the left of btn 1 to the left of btn 1+5 ---this replaces the move command
      else 
         set the left of btn 1 to 0
      end if
      send moveButton to me in 30 millisecs
   end if
end moveButton
You should play with that 30 and 5 to get the motion you want. Don't think just dropping the 30 is the best way to get it to speed up because that just uses more processing time.
Oh yeah, see that "send", that is why it's call a game loop.

I can't find the other stack, it wasn't mine, just a demo someone did.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Objects Moving Too Fast For LiveCode?

Post by Newbie4 » Wed Feb 25, 2015 3:36 am

If you download LiveCode v7.0.1 and start it up, there is a demo of bouncing balls right there on the Start Center.

If you want some simple examples of game loops at https://sites.google.com/a/pgcps.org/li ... rogramming.

If you want to see fully implemented game loops, download the livecode sources from some of the games at http://erhs.shaosean.tk/

Hope these help
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/

7Leven
Posts: 18
Joined: Sat Oct 11, 2014 2:06 am

Re: Objects Moving Too Fast For LiveCode?

Post by 7Leven » Fri Feb 27, 2015 7:15 pm

Oh okay. I was misunderstood as to what you meant by Game loops. I do know how to use those, in fact, as my stack currently is, I use game loops to keep the random movement of my objects continuous. I was used to referring to game loops as something called "Recursion".

Update:
I have scoured the LiveCode dictionary and I have been able to improve my game. But one issue still stands, there has got to be a way for me to use the move command and have my controls not freak out and twitch when they are moving a certain speed.

The reason using the move command is imperative is because the move command allows for more versatile random movements. It's easier for me to create random destinations on the card with the move command, as opposed to using incremental movement with the method suggested by Simon (although I do understand why that works).

Can anyone help me out on this?

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

Re: Objects Moving Too Fast For LiveCode?

Post by Newbie4 » Sat Feb 28, 2015 12:18 am

We have always found the move command to be too slow to use in games. The set loc works very well.

Many of my students have used it in games that had many objects moving at random speeds and directions. I do not understand your objection with that.

Did you look at that bouncing balls demo? It is impressive and is along the lines of your game. I had over 99 balls moving at one time and they moved without hesitation. Check it out. The balls follow trajectories, bounce off walls and are influenced by gravity. Yet there is smooth motion. They eventually come to a rest. Random movements could be added if desired.

If you can, give us more information or a better description of what you want to do. Maybe even some of the code that you are having trouble with and someone on this forum may be able to come up with a solution.
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/

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Objects Moving Too Fast For LiveCode?

Post by Simon » Wed Mar 25, 2015 2:28 am

This has come up a couple more times in recent posts and an idea hit me.

New stack two buttons and a squiggly line graphic (freehand tool).
open the inspector for the graphic and copy all the points (win ctrl+ a)
open the card inspector and create a new Custom Property call it cPath and paste all the points in
Now put this into the second button;

Code: Select all

local goNow,x=0,tPath,tLength
on mouseUp
   if goNow = true then
      put false into goNow
   else put true into goNow
   put the cPath of this card into tPath
   put the number of lines of tPath into tLength
   moveButton
end mouseUp

on moveButton
   if goNow = true then
      add 1 to x
      if x <= tLength then
         set the loc of btn 1 to line x of tPath ---this replaces the move command
      else 
         put 0 into x
      end if
      send moveButton to me in 30 millisecs
   end if
end moveButton
weeeeee! What fun. :)

Ok so there is a drawback in that it actually moves at the (relative) speed you drew the graphic.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply

Return to “Games”