Animation with Icons and next card

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mission007
Posts: 2
Joined: Tue Nov 15, 2011 3:22 pm
Location: Brazil-Argentina-USA

Animation with Icons and next card

Post by Mission007 » Tue Nov 15, 2011 4:31 pm

Hi there,
I am trying to animate a button like a person blinking.
I have 2 images and from the script of animating enemy space ship, I was able to make mine work.
Problem: When I go to next/previous card ( 2, 3, etc), it shows error because the runAnim cannot find the button or image to replace (they are in card 1).
Can it be fixed, or a code to stop the runAnim3 running or a better way.
NOTE: Every card will have up to 4 of this individual animations.
Thanks
Mission007
Here is the script:
-----------------------
on preOpenStack
set icon of button ID 1175 to ID of img ID 1177
end preOpenStack

Local blinkAnim

on openCard
if blinkAnim = "" then runAnim3
end openCard

on runAnim3
if blinkAnim = 11 or blinkAnim >11 then put 1 into blinkAnim
if blinkAnim < 10 then
set icon of button ID 1175 to ID of img ID 1177
add 1 to blinkAnim
send "runAnim3" to me in random(10)*100 millisecs
else
set icon of button ID 1175 to ID of img ID 1178
add 1 to blinkAnim
send "runAnim3" to me in 250 millisecs
end if
end runAnim3
-------------------------
"So many minds, so little time"

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: Animation with Icons and next card

Post by BvG » Tue Nov 15, 2011 5:07 pm

You need to cancel the pending message.

see the pendingMessages() function, as well as the cancel command.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Animation with Icons and next card

Post by Klaus » Tue Nov 15, 2011 5:09 pm

Hi Mission007,

at first, welcome to the forum :D

Yep, Björnke is right.

However here some useful hints:
1. you should give your buttons meaningful names instead of "button id XYZ"
2. You should add a descriptor, so the objects will ALWAYS be found:
... of btn "xyz" OF CD 1
## of stack XYZ ## if neccessary
3. the ID of image ID 1077 is: TADA -> 1077 :D
So you can save some typing AND if you ONLY use the ID, LiveCode will find the image
and will NOT give you any error in this regard!

So try this:

Code: Select all

Local blinkAnim

on openCard
  if blinkAnim = "" then runAnim3
end openCard

on runAnim3

## Although this is a bit more witing, this is better readable and you see the complete "if ... end if" structure at one glance!
  if blinkAnim = 11 or blinkAnim >11 then 
     put 1 into blinkAnim
  end if
  if blinkAnim < 10 then
    set icon of btn "El Blinko" OF CD 1 to 1177
    add 1 to blinkAnim
   send "runAnim3" to me in random(10)*100 millisecs
  else
    set icon of btn "El Blinko" OF CD 1  to 1178
    add 1 to blinkAnim
    send "runAnim3" to me in 250 millisecs
  end if
end runAnim3
Best

Klaus

Mission007
Posts: 2
Joined: Tue Nov 15, 2011 3:22 pm
Location: Brazil-Argentina-USA

Re: Animation with Icons and next card

Post by Mission007 » Tue Nov 15, 2011 9:45 pm

Hi, Thanks Björnke and Klaus
Thanks for the quick response and thanks Klaus for humorously correcting me.
( I liked "El Blinko)

I made the command stop using:
-----
on mouseUp
      repeat for each line aLine in the pendingMessages
            if aLine contains "runAnim3"  then
                  cancel item 1 of aLine
            end if
      end repeat
go to next card
end mouseUp
_______
I had to copy from someone because I didn't know how to use it. (some commands are intuitive, others for professionals...)

My problem is that when I go back to that card, the animation don't work any more.
Is there a way to have simple independent animations, this way I can place several in one card, go to next card and go back to same and they still animate?
Also place other animation on different cards. (basically it is a storybook where you go from page to page read and see animations. Nothing too fancy)
(If you didn't figure out, I am a newbe...)
Ed - Mission007
"So many minds, so little time"

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Animation with Icons and next card

Post by Klaus » Wed Nov 16, 2011 11:44 am

Hi Ed,

since you completely stopped the animation, can't you just start the animation (again) when you go to a card like this:

Code: Select all

on openCard
  ## if blinkAnim = "" then runAnim3
  runAnim3
end openCard
?


Best

Klaus

Post Reply

Return to “Games”