It looks like you're new here. If you want to get involved, click one of these buttons!
cParticle = gideros.class(Sprite) local oncParticleTweenCompleteRemove = function(tween) local target = tween.target target:Remove() end function cParticle:Remove() self.tweenx:setPaused(true) local parent = self:getParent() self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) self:removeChildAt(1) parent:removeChild(self) end function cParticle:init(x, y) local bitmap = Bitmap.new(texpack:getTextureRegion("particle.png",false)) bitmap:setAnchorPoint(0.5, 0.5) self:addChild(bitmap) self:setPosition(x, y) self:setScale(0.1) self:setAlpha(0.8) grpFX:addChild(self) local tx = x + math.random(-50,50) local ty = y + math.random(-50,50) self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) --************Watch out, the second version to determine the duration for the tween --************Will cause a memory leak local t = math.random(5,15)/10 --local t = math.random(0.5,1.5) --************ self.tweenx = GTween.new(self, t, {x=tx, y= ty, alpha=0.1, scaleX= 0.8, scaleY = 0.8}, {onComplete=oncParticleTweenCompleteRemove}) end function cParticle:onEnterFrame(event) --self.angle = self.angle + self.spin end |
Comments
this one not...
--local t = math.random(0.5,1.5)
i think is because in LUA math.random(lower, upper) is designed to work with integers.
extracted from LUA docs:
"upper and lower must be integer. In other case Lua casts upper into an integer, sometimes giving math.floor(upper) and others math.ceil(upper), with unexpected results (the same for lower)."
and (i ask you because i don't know how to check memory), but
how do you determine memory leaks in Gideros? (lua)...
thanks.
www.tntengine.com
To check the memory usage, do this:
Then according to the hint from GregBug, when t = 0, onComplete function is not called. Therefore your particle is not removed from the stage.
Currently, I'm looking at original GTween. I'll post an update here.
cheers,
Edit: An easy solution is adding a very small amount (e.g. 0.00001) to the t.
Likes: atilim