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.
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.
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.
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
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.
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
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.
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)
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.
Comments
edit: When MovieClip is eligible to GC then sprite1, sprite2 and sprite3 will be too.
If this is your case, then you should use GTween. Add the sprite to the stage and animate it by using GTween.
And since the MovieClip is a native implemetation, it's performance may be better.
https://sites.google.com/site/xraystudiogame
That's true
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
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
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)
https://sites.google.com/site/xraystudiogame
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.
https://sites.google.com/site/xraystudiogame
But your solution also works:
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
https://sites.google.com/site/xraystudiogame
I mean the best way is adding only the MovieClip and not the sprite. Like:
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.
https://sites.google.com/site/xraystudiogame
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.
But it may not meet the origal objective of the MovieClip.
https://sites.google.com/site/xraystudiogame
finally, I got your online again.
Can you take an look at my confusion for MovieClip and GTween agian, thanks.
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
But not this one (this is the correct usage):
I think there is a bug with GTween. I'll look at it.
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
toBeginning
toEnd
I have tried all before change to MovieClip
https://sites.google.com/site/xraystudiogame
Make my way to use movieclip become legal ;;)
https://sites.google.com/site/xraystudiogame