Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help changing animations!

edited February 2012 in General Posts: 5

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.

Comments

  • Posts: 447

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

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

  • edited February 2012 Posts: 273

    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...

    http://twolivesleft.com/Codea/Reference/#detail/index/drawOverview

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

  • Posts: 273

    The drawing never ceases. :)

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

    One of these for example:
    http://lua-users.org/wiki/ControlStructureTutorial

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

  • Posts: 447

    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.

  • Posts: 2,820

    That's a good idea for a library. I'll make it :-)

  • 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 self.active that defaults to true for button:init() and have an "if self.active then" in you button:draw() and button:touched() functions. button1.action would have to set button1.active to false to stop drawing.

  • @Zoyt!
    Wait can you post your coding here after?

  • Posts: 1,255
    draw()
       If eggSwap then
          sprite(egg, 100, 100)
       else
          sprite(eggC, 100, 100)
       end
       eggSwap = not eggSwap
    end
    
Sign In or Register to comment.