Help changing animations!

I have a button that has a function for writing text but i was wondering what do i have to write so it takes the current sprite off the screen and replace it with a different sprite.
Here is the code

button1 = Button( 470, -9, 100, 60 )
button1.action = function(sender) print(“Hello From Button 1”) end
button1.color = color(0, 0, 0, 138)

now i have a sprite called Egg and a sprite called EggC if i Egg is on the screen already what do i need to write to remove Egg and place EggC onto the screen.

stop drawing Egg and start drawing EggC, or did I misunderstand?

yup except what the stop function ??
I know to start its
but i have no clue for stop.

There is no stop function other than doing exactly what @ruilov said, “stop drawing Egg”

You may want to check out the in-app documentation concerning the draw function…

@Blanchot thanks, So there is no way to stop a draw?
Or… Is there?

The drawing never ceases. :slight_smile:

I think what you are looking for is a conditional expression to change the sprite you wish to draw.

One of these for example:

@Blanchot Yeah!
I trying to change sprite so it becomes an Animation so it changes back and forth from Egg to EggC

goalrex: normally you have to keep drawing stuff if you want it to keep showing up on the screen. If at any point you stop drawing, then it will stop showing. This is accomplished by codea by having the draw() function be called 60 times per second. If in any of those times you don’t draw the sprite, then for that 1/60 second period, the image will not show. Anyway, the wiki has more detailed explanations.

That’s a good idea for a library. I’ll make it :slight_smile:

button1 = Button( 470, -9, 100, 60 ) 
button1.action = function(sender) print("Hello From Button 1") end 
button1.color = color(0, 0, 0, 138)

It’s sort of hard to tell without seeing the rest of the code.

I guess you made a button class.

Possibly you could make a that defaults to true for button:init() and have an “if then” in you button:draw() and button:touched() functions. button1.action would have to set to false to stop drawing.

Wait can you post your coding here after?

   If eggSwap then
      sprite(egg, 100, 100)
      sprite(eggC, 100, 100)
   eggSwap = not eggSwap