Stop Moving

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
chelling
Posts: 100
Joined: Tue Mar 06, 2007 3:14 am

Stop Moving

Post by chelling » Mon May 27, 2013 4:13 pm

Any recommendations for stopping an image from moving along the points of a polygon graphic when the sound is done?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Stop Moving

Post by sturgis » Mon May 27, 2013 5:07 pm

To stop the move try:

Code: Select all

stop moving image "theNameOfYourImage"

As far as coordinating it with sound, I've not messed with sound on IOS much yet, but you might look at the "soundfinishedonchannel" message in the dictionary. If you're using channels, then you might end up with something like:

on soundFinishedOnChannel pChannel, pSound
stop moving image "yourImage" -- if you're playing multiple channels at once, with multiple things moving you might need to see which channel it is so you can stop the correct object.
end soundFinishedOnChannel


It might be easier to code a simple loop and move your object to each point of the grc with code and some type of check each time before the move to decide if you should make the next change or not.

chelling
Posts: 100
Joined: Tue Mar 06, 2007 3:14 am

Re: Stop Moving

Post by chelling » Mon May 27, 2013 6:16 pm

Thanks stugis. I am not using channels - just an mp3 file.

I am using a repeat loop. I am collecting the points in variables like this. There are 10 points, so I end up with tPoint1 to tPoint10.
put item 1 to 2 of line 1 of the points of graphic "Polygon" into tPoint1

Next I play the sound file:
if the environment is "mobile" then play specialFolderPath("engine") & "/audio/musicFile2.mp3"

Then I have the repeat loop set up for each of the variable tPoint1 to tPoint10
repeat until the sound is done
move image "a_apple" to tPoint1
if the sound is done then
stop moving image "a_apple"
showNextBtns
else
move image "a_apple" to tPoint2
if the sound is done then
stop moving image "a_apple"
showNextBtns
else
This continues through each of the 10 tPointx variables. I know it is redundantly checking for the sound to be done - this is one of my attempts to get the movement in synch with the audio file. Needless to say it has not been successful.

This is showNextBtns
on showNextBtns
stop moving image "a_apple"
move image "a_apple" to the location of grc "Oval"
set the visible of card btn "Learn About It" to true
set the visible of card btn "Finished" to true
end showNextBtns

I have tried several variations with no luck. It really seems like there are messages pending to move, and those pending messages are executed even though the sound is actually done. I have tried to use the pendingMessages function and delete each line, but it didn't make a difference.

The thing is, this is a very simple movement that just needs to continue until the sound is done. It is confusing when the music file stops and the movement continues.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Stop Moving

Post by Jellicle » Tue May 28, 2013 4:48 am

Perfect use for sound channels. Is there a reason you aren't using them?

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

chelling
Posts: 100
Joined: Tue Mar 06, 2007 3:14 am

Re: Stop Moving

Post by chelling » Tue May 28, 2013 10:34 pm

I didn't think of using sound channels because I am playing one sound, but this was the answer. Thank you all very much!!

on openCard
put specialFolderPath("engine") & "/audio/musicFile3.mp3" into tSoundFile
if the environment is "mobile" then mobilePlaySoundOnChannel tSoundFile, "current", "now"

repeat until soundFinishedOnChannel
if the environment is "mobile" then move image "a_apple" to the points of graphic "Polygon"
end repeat

if the environment is "mobile" then iphoneClearTouches
end openCard


on soundFinishedOnChannel
stop moving image "a_apple"
end soundFinishedOnChannel

One more question, should I delete the channel once the file has played? Should each card have its own channel?

Post Reply