Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Trying to understand MovieClips — Gideros Forum

Trying to understand MovieClips

WauloKWauloK Member
edited February 2013 in General questions
Here's my code. Both animations only show frame 1 for some reason I cannot fathom.
-- Set up our images into frames to animate
local frames = {}
 
frames[1] = Bitmap.new(Texture.new("images/Smile1.png"))
frames[2] = Bitmap.new(Texture.new("images/Smile2.png"))
frames[3] = Bitmap.new(Texture.new("images/Smile3.png"))
frames[4] = Bitmap.new(Texture.new("images/Smile4.png"))
 
-- Create an animation with 2 images spread over a timeline of 20 frames
-- First 10 frames are frame[1], the rest are frame[2]
local mc1 = MovieClip.new{
    {1, 10, frames[1]}, 
    {10, 20, frames[2]}, 
}
 
-- Set the location and add it to the stage
mc1:setPosition(150,150)
stage:addChild(mc1)
 
-- If animation reaches frame 2, go to frame 1
-- Set looping of mc1
mc1:setGotoAction(2, 1)
-- Start animating mc1
mc1:gotoAndPlay(1)
 
-- Create a new movie clip
-- First 5 frames are the first image. Next 5 frames are the second image, etc
local mc2 = MovieClip.new{
    {1, 5, frames[1]}, 
    {5, 10, frames[2]}, 
    {10, 15, frames[3]}, 
    {15, 20, frames[4]},
}
 
-- Set the location and add it to the stage
mc2:setPosition(250,250)
stage:addChild(mc2)
 
-- Play it through once
--mc2 plays once and stops at frame 4
mc2:setGotoAction(4,4)
-- Start animating mc2
mc2:gotoAndPlay(1)
Thanks in advance for any assistance :)

Likes: Yan

Gideros Tutorials and Mobile apps:
http://BlueBilby.com/
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • zvardinzvardin Member
    edited February 2013 Accepted Answer
    It's because of your setGotoAction calls. You're telling the MovieClip to go to frame 1 before it ever switches to the 2nd bitmap.
    -- If animation reaches frame 2, go to frame 1
    -- Set looping of mc1
    -- Your "frame 2" doesn't happen until frame 10, and I'm assuming you don't want the
    -- animation to go to "frame 1" until "frame 2" has been out for its 10 frames
    --mc1:setGotoAction(2, 1)
    mc1:setGotoAction(20,1)
     
     
    -- Play it through once
    --mc2 plays once and stops at frame 4
    -- Same thing here
    mc2:setGotoAction(20,1)
  • WauloKWauloK Member
    edited February 2013
    Ah ok I see.
    Let me try again :)
    Gideros Tutorials and Mobile apps:
    http://BlueBilby.com/
  • The problem was I originally only used a clip with 2 frames but changed it to 20 frames and didn't update the action. Cheers!
    Gideros Tutorials and Mobile apps:
    http://BlueBilby.com/
  • I added another MovieClip but somehow it's affecting mc2 ?
    local bounce = MovieClip.new{
        {1, 100, frames[4], {x = 50, y = {150, 50, "inBounce"}}}
    }
    stage:addChild(bounce)
    bounce:gotoAndPlay(1)
    Both bounce now even though inBounce is only applied to 'bounce' and not 'mc2'. mc1 is unaffected.
    Gideros Tutorials and Mobile apps:
    http://BlueBilby.com/
  • I think it's because you're referencing the same Bitmap.
  • Interesting. So the Movieclip is tied to the bitmap in it's timeline. Any new movieclips referencing the bitmap will change that bitmap as well even though it's a totally different Movieclip. Strange.
    Gideros Tutorials and Mobile apps:
    http://BlueBilby.com/
  • ...yeah, I guess it's best to think of things like MovieClip and Gtween as systems for manipulating the properties of a sprite rather than as graphic objects containing other graphic objects.

    http://appcodingeasy.com/Gideros-Mobile/Gideros-GTween-with-easing
  • Well I would say it's more that the bitmap class represents a sprite of a texture not the file. You can change your frame declarations to Textures which represent the file and then instantiate bitmap per movieclip.
  • Ok. So if you want 5 animations you need 5 tables with sprites and 5 movieclips..
    Gideros Tutorials and Mobile apps:
    http://BlueBilby.com/
  • BJGBJG Member
    edited February 2013
    (Edit...see below)

    Dislikes: Yan

    +1 -1 (+0 / -1 )Share on Facebook
  • BJGBJG Member
    edited February 2013
    Well I would say it's more that the bitmap class represents a sprite of a texture not the file. You can change your frame declarations to Textures which represent the file and then instantiate bitmap per movieclip.
    Are you suggesting a way to create a set of independent animations based on a single table of Textures...? I don't understand how the plan works...MovieClip.new needs a sprite, not a Texture...

  • Are you suggesting a way to create a set of independent animations based on a single table of Textures...? I don't understand how the plan works...MovieClip.new needs a sprite, not a Texture...
    Yeah, it's just a matter of how you setup your code. The way it's setup now is more flexible because it's relatively easy to use them in the fashion you're hoping to, but still allows them to be used in other ways as well. If you have many objects that will be the same types of animations, you can make a class like the MovieClip example does. But using the example above:
    -- Set up our images into frames to animate
     
    -- I'd change the frame declaration to be Textures, since you just want these to be
    -- references to the images themselves
    local frames = {}
     
    frames[1] = Texture.new("images/Smile1.png")
    frames[2] = Texture.new("images/Smile2.png")
    frames[3] = Texture.new("images/Smile3.png")
    frames[4] = Texture.new("images/Smile4.png")
     
    -- Create an animation with 2 images spread over a timeline of 20 frames
    -- First 10 frames are frame[1], the rest are frame[2]
     
    -- now just add bitmap.new in your movieclip declaration
    local mc1 = MovieClip.new{
        {1, 10, Bitmap.new(frames[1])}, 
        {10, 20, Bitmap.new(frames[2])}, 
    }

    Likes: BJG

    +1 -1 (+1 / -0 )Share on Facebook
  • Oh, I get it...cheers.
Sign In or Register to comment.