How to rotate an object 360 degree?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to rotate an object 360 degree?

Post by Klaus » Wed Aug 28, 2013 6:10 pm

Hi Tom,
tomBTG wrote:Hi Klaus.
Would you entertain a few follow-up questions about your stack?
No :D
tomBTG wrote:1) Being a newbie, I would have written a similar stack using handlers. You used "command". What's the difference? (The LC dictionary doesn't help much on this point.)
A couple of years ago RunRev advised to use COMMAND for custom handlers
and leave the ON for build-in handlers like "mouseup" etc.

If I remember correctly, the reason was that the engine might distinguish this some time in the future.
No idea why, but this has not happened yet, and I got used to it :-)
tomBTG wrote:2) What is the result you are getting back from the "send" message in lin 19 and 20?
I tried to view it as a variable and did not see it. You stored it in tAnimationMessage and used it to cancel
the operation. Is it a message ID?
Yes! When you do a "send", "THE RESULT will return the ID for this message.
You can use that to cancel the next delivery of that message.
Check "send" and "pendingmessages" in the dictionary.
tomBTG wrote:3) You end the animation_stop with "enable btn "animate" of cd 1".
What is the reason for that? (Did the animation process disable the button?)
The button "animate" is rather erm... self-disabling :D
See line 2 of its script.


Best

Klaus

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm

Re: How to rotate an object 360 degree?

Post by tomBTG » Wed Aug 28, 2013 6:34 pm

Thanks for the insights! Very helpful. :D
-- Tom

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: How to rotate an object 360 degree?

Post by istech » Sun Dec 01, 2013 12:18 pm

Hi all,

Hope you can provide some insight to a newbie.

I have been playing with this script for a while as I have been experimenting with manipulating animations.

What I am playing with at the moment is creating a custom repeat and the best way to approach this with this script.

I would love to see some possible scenarios and your thought processes behind them with comments. Thanks

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to rotate an object 360 degree?

Post by Klaus » Sun Dec 01, 2013 1:22 pm

Hi istech,

what exactly is your question? 8)


Best

Klaus

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: How to rotate an object 360 degree?

Post by istech » Sun Dec 01, 2013 4:29 pm

Hi Klaus,

Thanks for replying. For example if I wanted to add, repeat 2 times then send cancel Animation message.

Or repeat 6 times then send cancel animation. etc. What is the best solution to add this code? Where is the best place to start.

Kindest Regards,

Tone

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to rotate an object 360 degree?

Post by Klaus » Sun Dec 01, 2013 5:11 pm

Hi Tone,

sorry, forgot my original script, too long ago.
Could you please post my code (again)? :D

But basically you need to manage a COUNTER and check that everytime.


Best

Klaus

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: How to rotate an object 360 degree?

Post by istech » Sun Dec 01, 2013 7:36 pm

No worry s it's the one on the first page. I love messing with it. Just learning and tinkering. :?

half work and half don't but fun learning.
Attachments
wheel_animation1.rev.zip
(95.92 KiB) Downloaded 265 times

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to rotate an object 360 degree?

Post by Klaus » Sun Dec 01, 2013 10:15 pm

Hi Tone,

AHA!
Yes, I remember faintly :D

OK, I modified the script to accept one parameter = any integer > 0

Code: Select all

local tAnimationMessage

command mk_animate howoften
  put the icon of btn "wheel" into tCurrentIcon
  
  ## Next icon?
  if tCurrentIcon < 1006 then
    add 1 to tCurrentIcon
    
    ## We already reached the last "FRAME" so we start anew:
  else
    put 1003 into tCurrentIcon
  end if
  
  ## Now set the new icon
  set the icon of btn "wheel" to tCurrentIcon
  
  ## We simply count down to 0 everytime
  ## if howoften = 0, we do NOT send the message again
  ## Otherwise we subtact 1 from howoften and send the message again
  if howoften > 1 then
    subtract 1 from howoften
    send "mk_animate howoften" to me in 100 millisecs
    put the result into tAnimationMessage
  end if
end mk_animate

## This will KILL the appropriate "pending message" and thus stop the animation
command mk_animate_stop
  
  ## Preven setting next icon = stop the animation:
  cancel tAnimationMessage
  enable btn "animate" of cd 1
end mk_animate_stop
In the "animate" button you can now add a parameter = the number of repeats
until the animation automatically stops:

Code: Select all

on mouseUp

  ## Will change the wheel 6 tiems and then stops!
  mk_animate 6
end mouseUp
You get the picture :)


Best

Klaus

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: How to rotate an object 360 degree?

Post by istech » Mon Dec 02, 2013 12:41 am

Thanks Klaus

Given me some more to tinker with thanks. :D

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to rotate an object 360 degree?

Post by Klaus » Mon Dec 02, 2013 12:58 am

OK, please take a look at my solution to this problem:
http://forums.runrev.com/phpBB2/viewtop ... 69&t=17552
It's the last posting. 8)

Post Reply