Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
My feature suggestion for gideros - Page 2 — Gideros Forum

My feature suggestion for gideros

2

Comments

  • atilimatilim Maintainer
    edited August 2012

    Then after Event.COMPLETE, sprite1 sprite2 sprite3 will be remove from stage?
    not very exactly. In fact they are not on the stage or they are not children of MovieClip. They are just internally referenced and used by MovieClip to draw them to the screen.
    edit: When MovieClip is eligible to GC then sprite1, sprite2 and sprite3 will be too.


    My common situation, the sprite is always on the stage, and I need to make different animation to the sprite.
    If this is your case, then you should use GTween. Add the sprite to the stage and animate it by using GTween.
  • alexzhengalexzheng Guru
    edited August 2012
    At first,I always use GTween, but I found some very strange result if I play my game very fast, I guess it maybe because the local gtween is collected before the animation completed. So I begin to make a reference myself carefully.
    And since the MovieClip is a native implemetation, it's performance may be better.
  • atilimatilim Maintainer
    edited August 2012
    At first,I always use GTween, but I found some very strange result if I play my game very fast, I guess it maybe because the local gtween is collected before the animation completed.
    This shouldn't be. GTween object is not collected if it's running. I'll test it.

    And since the MovieClip is a native implemetation, it's performance may be better.
    That's true :)
  • not very exactly. In fact they are not on the stage or they are not children of MovieClip. They are just internally referenced and used by MovieClip to draw them to the screen.

    Then these sprites will disappear from the stage?

    And the GTween is not suit for a character with some frames for walking,some for jump,and so on
  • atilimatilim Maintainer
    edited August 2012

    Then these sprites will disappear from the stage?
    Yes, if you remove the MovieClip from the stage (and if these sprites are not added to the stage somewhere else).
  • I think I have understood the MovieClip much better, thanks @atilim

  • is there any side effect if I use movieClip instead of GTween in this way:
    mcs = {}
    local sprite1 = Sprite.new(...)
    stage:addChild(sprite1 )
     
    local mc = MovieClip.new(... sprite1 ....)
    mc:addEventListener(Event.COMPLETE, function(mc) mcs[mc] = nil end, mc)
    mcs[mc] = true
  • atilimatilim Maintainer
    hmm.. I think there isn't any side effects (but isn't adding mc to the stage easier)?
  • add both sprite and movieclip to the stage?
    like that:

    local sprite1 = Sprite.new(...)
    stage:addChild(sprite1 )

    local mc = MovieClip.new(... sprite1 ....)
    mc:addEventListener(Event.COMPLETE, function(mc)mc:removeFromParent() end, mc)
    stage:addChild(mc)
  • atilimatilim Maintainer
    If you add both, the sprite will be drawn twice :)
  • alexzhengalexzheng Guru
    edited August 2012
    So that's not a good way to achieve that.
    Unfortunately all of my games have used MovieClip this way. :-(
    So what's the best way to use MovieClip just instead of Gtween?
    in other words, Keeping the sprite on the stage and release the MovieClip after complete.
  • atilimatilim Maintainer
    edited August 2012
    The best way is adding only the MovieClip to the stage. hehe :)

    But your solution also works:
    mcs = {}
    local sprite1 = Sprite.new(...)
    stage:addChild(sprite1 )
     
    local mc = MovieClip.new(... sprite1 ....)
    mc:addEventListener(Event.COMPLETE, function(mc) mcs[mc] = nil end, mc)
    mcs[mc] = true
  • alexzhengalexzheng Guru
    edited August 2012
    The best way is adding only the MovieClip to the stage.

    But the sprite will aslo be disppared from the stage if not add to the stage after release the movieclip.

    and will this code also draw twice ?
    mcs = {}
    local sprite1 = Sprite.new(...)
    stage:addChild(sprite1 )

    local mc = MovieClip.new(... sprite1 ....)
    mc:addEventListener(Event.COMPLETE, function(mc) mcs[mc] = nil end, mc)
    mcs[mc] = true
  • atilimatilim Maintainer
    edited August 2012
    Your code is not drawing twice because you're not adding the MovieClip to the stage.

    I mean the best way is adding only the MovieClip and not the sprite. Like:
    local sprite1 = Sprite.new(...)
     
    local mc = MovieClip.new(... sprite1 ....)
    stage:addChild(mc)
    -- if you want you can use Event.COMPLETE to remove the MovieClip from stage when it's finished
  • atilimatilim Maintainer
    edited August 2012
    But in this case, I also guess that you need to change your current code a lot.
  • Can I understand MovieClip as a special sprites container with the ability to draw different sprites and run actions sush as moveto, scaleto on them?

    So, as I understand
    If you want to show a sequence of bitmaps,either once (show a firework and remove it when completed) or looping (an endless walking man), the MovieClip is the best choice, and you can simply add the MovieClip to the stage and remove it when it's not needed.

    However, in another situation, When you want to run an action on a sprite that is already on the stage, and after the action is completed, the action object is collected and the sprite is still on the stage,maybe the best choice is GTween.
  • alexzhengalexzheng Guru
    edited August 2012
    Here is my story why I prefer MovieClip to GTween when I just need to run an action on a sprite.

    I will illustrate my situation with a simple demo

    At first, I use GTween, and I want the sprite always move to the last point I tapped,
    But It failed on very fast taps.
    local sprite = Bitmap.new(Texture.new("box.png"))
    stage:addChild(sprite)
     
    --GTween.new(sprite, 2, {x = 240}, {delay = 0.2, ease = easing.outBounce, repeatCount = 1, reflect = true})
     
     
    local gtween
    stage:addEventListener(Event.MOUSE_DOWN, function(event)
    		if gtween then
    			gtween:toEnd()  ---stop the previous action
    		end
    		gtween = GTween.new(sprite, math.random(4), {x = event.x, y = event.y}, {delay = 0.2, ease = easing.outBounce, repeatCount = 1, reflect = true})
    	end)
    So I try MovieClip in this way, and it works as I expected.
    But it may not meet the origal objective of the MovieClip.
    local mc
    stage:addEventListener(Event.MOUSE_DOWN, function(event)
    		if mc then
    			mc:gotoAndStop(200)
    		end
    		mc = MovieClip.new{
    		{1, 200, sprite, {x = {sprite:getX(), event.x}, y= {sprite:getY(), event.y}}}
    		}
    	end)
  • hi @atilim

    finally, I got your online again.
    Can you take an look at my confusion for MovieClip and GTween agian, thanks.
  • atilimatilim Maintainer
    Can I understand MovieClip as a special sprites container with the ability to draw different sprites and run actions sush as moveto, scaleto on them?

    So, as I understand
    If you want to show a sequence of bitmaps,either once (show a firework and remove it when completed) or looping (an endless walking man), the MovieClip is the best choice, and you can simply add the MovieClip to the stage and remove it when it's not needed.

    However, in another situation, When you want to run an action on a sprite that is already on the stage, and after the action is completed, the action object is collected and the sprite is still on the stage,maybe the best choice is GTween.
    exactly!

  • Then is there any bugs in the above code to use GTween?
  • atilimatilim Maintainer
    edited August 2012
    Interestingly, this code is working as expected:
    local gtween
    stage:addEventListener(Event.MOUSE_DOWN, function(event)
    	GTween.stopAll()
    	gtween = GTween.new(sprite, 1, {x = event.x, y = event.y}, {ease = easing.outBounce})
    end)

    But not this one (this is the correct usage):
    local gtween
    stage:addEventListener(Event.MOUSE_DOWN, function(event)
    	gtween:setPaused(true)
    	gtween = GTween.new(sprite, 1, {x = event.x, y = event.y}, {ease = easing.outBounce})
    end)

    I think there is a bug with GTween. I'll look at it.
  • GTween.stopAll() will stop all action run on all sprite, that's not as expected.
  • atilimatilim Maintainer
    Although it's the incorrect usage, I just put it to show the desired behavior :)

  • Interestingly, this code is working as expected:
    I think there is a bug with GTween. I'll look at it.
    Then, finally, I know why I changed all the gtween to movieclip
  • So currently, I must use movieclip in that abnormal way to achieve what I expected.
  • gtween:setPaused(true)
    toBeginning
    toEnd

    I have tried all before change to MovieClip
  • atilimatilim Maintainer
    gtween:setPaused(true)
    toBeginning
    toEnd

    I have tried all before change to MovieClip
    :-\"
  • alexzhengalexzheng Guru
    edited August 2012
    Maybe you can add an feature to MovieClip to make it a repalcement for gtween totally.

    Make my way to use movieclip become legal ;;)
  • atilimatilim Maintainer
    edited August 2012
    If you mean prevent garbage collection of running MovieClips, it causes much more trouble. And fixing GTween is easier :)
Sign In or Register to comment.