moving objects

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

moving objects

Post by ferhan24badshah » Thu Apr 24, 2014 11:36 pm

I have 3 blocks evenly spaced out on the card. I animated each of the blocks to move from right to left at the same speed, and if the right side of a block moves past the left side of the card, the left side of the block is placed past the right side of the card and it continues its motion towards the left again. The animation looks fine on LiveCode but when I package it into my phone, the animation appears very laggy and slows down frequently. I also set the acceleratedrendering to true in preopencard.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: moving objects

Post by jacque » Sat Apr 26, 2014 6:08 am

This came up in another thread too. Besides setting acceleratedRendering, you also need to set the layerMode of each block to "dynamic".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: moving objects

Post by ferhan24badshah » Sat Apr 26, 2014 9:20 pm

jacque wrote:This came up in another thread too. Besides setting acceleratedRendering, you also need to set the layerMode of each block to "dynamic".
Thanks for the response. I already had the layerMode of each block set to "dynamic".

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: moving objects

Post by jacque » Sat Apr 26, 2014 10:45 pm

It may be in your script then. Does the handler include any "wait" instructions?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: moving objects

Post by ferhan24badshah » Sun Apr 27, 2014 6:40 am

jacque wrote:It may be in your script then. Does the handler include any "wait" instructions?

Here is my code....It's really laggy and the bottom obstacles aren't moving at the same pace as the top obstacles.
Attachments
gammeeee111.zip
(2.09 KiB) Downloaded 334 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: moving objects

Post by jacque » Mon Apr 28, 2014 6:56 pm

Could you post just the relevant part of your script please? I rarely download whole stacks, they are too time-consuming to read and debug. Short handler excerpts are much better for me.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: moving objects

Post by magice » Mon Apr 28, 2014 8:30 pm

Actually this runs fine in windows, however it does not completely shut down. You need to add a script on closeStack that deletes all pending messages. I have no idea if that could be causing your problem since I have no experience with phone apps, (maybe multiple instances running on the phone?) but it still should be taken care of.

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: moving objects

Post by ferhan24badshah » Tue Apr 29, 2014 1:25 am

jacque wrote:Could you post just the relevant part of your script please? I rarely download whole stacks, they are too time-consuming to read and debug. Short handler excerpts are much better for me.
Here is the relevant part of the code

command moveObj
....if the hilite of button "check" is true then
.........set the left of the image "brick1" to the left of image "brick1" - 10
.........set the left of the image "brick2" to the left of image "brick2" - 10
.........if the right of the image "brick1" < 0 then
..............set the left of the image "brick1" to the right of this card
.........end if
.........if the right of the image "brick2" <0 then
.............set the left of the image "brick2" to the right of this card
.........end if
.........send "moveObj" to me in 20 milliseconds
end moveObj




I tried using images instead of buttons but that didn't make a difference. It seems to run fine on Windows but on my android phone, the animation is really jerky.

I attached a more simple version of my project. The coding is in the card script.
Attachments
Untitled 1.zip
(212.35 KiB) Downloaded 274 times

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

Re: moving objects

Post by Simon » Tue Apr 29, 2014 5:30 am

Hi Ferhan,
Once on a real device "set the left..." or "set the loc..." of multiple objects gets very slow. I believe you are going to have to think up another way to do this.

In your demo for the motion you show, it could be just group the objects and "move" the group.

I just tried your last stack on my Kindle Fire and it's very smooth. You might try locking the screen:

Code: Select all

command moveObj
   if the hilite of button "check" is true then
      lock screen
      set the left of the image "brick1" to the left of image "brick1" - speed
      set the left of the image "brick2" to the left of image "brick2" - speed
      if the right of the image "brick1" < 0 then
         set the left of the image "brick1" to the right of this card
      end if
      if the right of the image "brick2" < 0 then
         set the left of the image"brick2" to the right of this card"
      end if
      send "moveObj" to me in 20 milliseconds
      unlock screen
   end if
end moveObj
Not sure if that will help on your device, the motion was smooth either way on my Android.

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

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: moving objects

Post by ferhan24badshah » Tue Apr 29, 2014 7:41 am

Simon wrote:Hi Ferhan,
Once on a real device "set the left..." or "set the loc..." of multiple objects gets very slow. I believe you are going to have to think up another way to do this.

In your demo for the motion you show, it could be just group the objects and "move" the group.

I just tried your last stack on my Kindle Fire and it's very smooth. You might try locking the screen:

Code: Select all

command moveObj
   if the hilite of button "check" is true then
      lock screen
      set the left of the image "brick1" to the left of image "brick1" - speed
      set the left of the image "brick2" to the left of image "brick2" - speed
      if the right of the image "brick1" < 0 then
         set the left of the image "brick1" to the right of this card
      end if
      if the right of the image "brick2" < 0 then
         set the left of the image"brick2" to the right of this card"
      end if
      send "moveObj" to me in 20 milliseconds
      unlock screen
   end if
end moveObj
Not sure if that will help on your device, the motion was smooth either way on my Android.

Simon
thanks simon. i added the lock screen to my code and the animation appears to be more smooth now. I tried grouping and using the move command too. but the movement still seems to be jerky when the objects move out of the screen if my eyes aren't fooling me. Did you notice that ?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: moving objects

Post by jacque » Tue Apr 29, 2014 4:36 pm

Thanks for posting the script, it's easier for us that way and you'll get more replies too.

The grouping idea is a good one. You should change the layermode of the blocks back to static and set the layermode of the group to dynamic now. You want only the highest layer to be buffered. Having each object inside the group individually buffered can actually slow things down.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: moving objects

Post by ferhan24badshah » Fri May 02, 2014 11:12 pm

jacque wrote:Thanks for posting the script, it's easier for us that way and you'll get more replies too.

The grouping idea is a good one. You should change the layermode of the blocks back to static and set the layermode of the group to dynamic now. You want only the highest layer to be buffered. Having each object inside the group individually buffered can actually slow things down.
I've tried all of those ideas but it still causes the animation to be jerky especially when it goes into the left side of the screen on my phone :/

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

Re: moving objects

Post by Simon » Fri May 02, 2014 11:18 pm

ferhan24badshah wrote: I've tried all of those ideas but it still causes the animation to be jerky especially when it goes into the left side of the screen on my phone :/
I'm still thinking you'll have to use the "move" command, it's very smooth.

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

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: moving objects

Post by sefrojones » Sat May 03, 2014 2:24 am

Check out this little sample stack to show you how much more smooth it will be using the "move"command.
This stack basically moves 3 images down the card along a graphic line as a path. The lines are hidden. when the image goes off the edge of the card it is hidden, the path is randomly placed in a new spot and the image is moved again. I just created/ tested this stack on an ancient droid and it runs very smooth compared to doing the same thing with the "set" command.

Good Luck!

--Sefro
Attachments
MovingonAndroid.zip
(2.68 KiB) Downloaded 278 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: moving objects

Post by jacque » Sat May 03, 2014 6:22 am

If you want to use the original script, try reducing the 20 milliseconds to 1, then tinker with the time delay to see what works.

But I agree "move" is better. You'll get a consistent animation no matter what the speed of the CPU. When you use "set" the time delay isn't calculated until after the blocks have finished moving, and that can take different amounts of time on different devices.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply