Rotate an Image

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
basheps
Posts: 11
Joined: Tue May 31, 2011 11:53 am

Rotate an Image

Post by basheps » Tue Jun 14, 2011 10:34 pm

Hi all, I'm new to LiveCode and Animation Engine although I do have programming experience in other languages. This may seem simple but I'm trying create an effect on a graphic that shows it spinning and fading in, and enlarging in place simultaneously as the page opens. So far I've tried the code below which works for the most part but I don't know how to 1) Do this with Animation Engine and 2) Create the effects simultaneously. I see a function in AE called spiral and I'm assuming that it may do the rotation but there is no sample and I've been unable to get it to work. Any help is appreciated.

repeat with BlendOut = 100 to 0 step -1
set the blendLevel of image splash.png to BlendOut
wait 10 milliseconds with messages
end repeat

repeat with imageAngle = 360 to 0 step -10
set the angle of image "splash.png" to imageAngle
wait 10 milliseconds with messages
end repeat

repeat with imagePercent = 100 to 1 step -3
set the width of image "splash.png" to (tWidth/imagePercent)
set the height of image "splash.png" to (tHeight/imagePercent)
wait 35 milliseconds with messages
end repeat

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Rotate an Image

Post by malte » Wed Jun 15, 2011 10:02 am

Hi basheps,

welcome to liveCode and AE!

what you will want to read up on is the usage of send in time. Using repeat is not your friend in this context.

In an animationEngine context, many handlers exist to help you doing fades and stuff like that.

look at aeFadeIn / aeFadeOut in the animationEngine docs. It is a simple command with a few parameters that let you specify, how you would want your object to fade in (amount of time the fade should take, etc). Now, aeFadeIn sends a callback message to the target object. You can trap that and do the rotation in the callback handler.

Please let me know if you need a specific code example and I will be whipping something up.

All the best,

Malte

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4000
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Rotate an Image

Post by bn » Wed Jun 15, 2011 2:00 pm

Hi basheps,

it turns out that it is not easy to set the angle of an image and change its size at the same time. If you set the angle of an image Livecode always uses the original image to calculate the angle, this overrides the setting of width and height.

With a bit of image vodoo you can arrive at an image that you set the angle and the size at the same time.

Here is a stack that lets you make a png image from a text field. You then have three buttons that either change the angle, grow the image or both.

It uses the send in time structure Malte recommended. It does not use animation engine. (actually I doubt that animation engine provides a means to rotate and grow an image at the same time, it is such an ugly hack :) )

Have a look at the scripts.
spinAnimateBasheps.livecode.zip
(4.42 KiB) Downloaded 801 times
Kind regards

Bernd

basheps
Posts: 11
Joined: Tue May 31, 2011 11:53 am

Re: Rotate an Image

Post by basheps » Wed Jun 15, 2011 3:08 pm

This is perfect. Exactly what I was looking for! Thank you so much for the sample and for the tips.

basheps
Posts: 11
Joined: Tue May 31, 2011 11:53 am

Re: Rotate an Image

Post by basheps » Wed Jun 15, 2011 11:04 pm

Just curious on how to implement this sample on multiple images simultaneously. I've tried:

Code: Select all

on openCard   
   -- start rotation/animation
   initVars "splash1.png"
   initVars "splash2.png"
end openCard

on initVars pSplashImage
   put pSplashImage into sSplashImage
   put the width of image sSplashImage into sWidth
   put the height of image sSplashImage into sHeight
   put the loc of image sSplashImage into sLoc
   put 100 into sCounter   
   send AnimateSplash to me in 0 milliseconds
end initVars
but it only does the rotation on the last image and not the first.
What is the correct way to do this? Thanks in advance.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4000
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Rotate an Image

Post by bn » Wed Jun 15, 2011 11:42 pm

Hi basheps,
Just curious on how to implement this sample on multiple images simultaneously
try this:
spinAnimateBasheps_0.0.2.livecode.zip
(6.33 KiB) Downloaded 677 times
Kind regards

Bernd

basheps
Posts: 11
Joined: Tue May 31, 2011 11:53 am

Re: Rotate an Image

Post by basheps » Thu Jun 16, 2011 6:18 pm

Once again thank you for the sample bn. I am going to try to work on this some more in order to make it a reusable function that I can pass in an array of images or all images in a group and have it rotate each one together.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4000
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Rotate an Image

Post by bn » Sun Jun 19, 2011 8:23 pm

Hi basheps,

here is a version that uses an array and works with as many images as you want, just pass the names of the images.

But if you overdo it Livecode will be slow to rotate too many images at the same time, I tried it with 6 images and it is noticeably slower. If you change the stepsize of sCounter you can compensate for that to some degree.
It also depends on the size of the images you want to rotate.
Bildschirmfoto 2011-06-19 um 21.19.06.png
Bildschirmfoto 2011-06-19 um 21.19.06.png (14.99 KiB) Viewed 15508 times
spinAnimateBasheps_0.0.3.livecode.zip
(15 KiB) Downloaded 648 times

I thought I let you try it first but in case it did not work out with the array here is one way to do it.

Kind regards

Bernd

basheps
Posts: 11
Joined: Tue May 31, 2011 11:53 am

Re: Rotate an Image

Post by basheps » Mon Jun 20, 2011 12:08 am

Once again it worked perfectly! Thanks again Bernd.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Rotate an Image

Post by Mark » Mon Sep 19, 2011 3:49 pm

MODERATORS why hasn't the previous post been removed yet?

[Moderator edit]

The post this refers to has now been removed

[/moderator edit]
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9833
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Rotate an Image

Post by FourthWorld » Mon Sep 19, 2011 5:13 pm

Mark wrote:MODERATORS why hasn't the previous post been removed yet?
I would like to remove it, but there's something odd about this thread which prevents me from doing so. We'll have to wait for another admin with higher privileges to take care of it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Rotate an Image

Post by Mark » Mon Sep 19, 2011 5:54 pm

OK, thanks for letting me/us know.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Rotate an Image

Post by malte » Mon Sep 19, 2011 6:45 pm

Done. :-)

Thanks for reporting.

Malte

Post Reply

Return to “Animation Engine”