Hi guys!
In my app I use the function “newTrail”. It works well but in some cases it creates a bit of lag.
For example if I’m uploading advertising or doing other runtime checks.
I know that I should load the advertisement in scenes not animated but in this case I am forced.
I am attaching the code and what I get in the two cases:
code:
local myImage = display.newImageRect( "myImage.png", 30, 30 ) myImage:translate( 160, 20 ) transition.to( myImage, {time=5000, y=460, iterations=-1, transition=easing.continuousLoop}) local function lenSqr( dx, dy, dz ) return ( dx \* dx + dy \* dy + dz \* dz ) end local function newTrail( object, options ) if not object.contentBounds then print( "WARNING: Object not found" ) return false end options = options or {} local image = options.image or "myImage.png" local dw, dh = object.width, object.height local size = options.size or ( dw \> dh ) and ( dw \* 0.9 ) or ( dh \* 0.9 ) local w, h = size, size local ox, oy = options.offsetX or 0, options.offsetY or 0 local trans = options.transition or { time = 250, alpha = 0, delay = 50, xScale = 0.01, yScale = 0.01 } local delay = options.delay or 0 local color = options.color or { 1.0 } local alpha = options.alpha or 0.5 local blendMode = options.blendMode or "add" local frameSkip = options.frameSkip or 1 local frame = 1 local trail = display.newGroup() --se vi è un diverso punto di ancoraggio eseguo dei controlli per esso if((object.anchorX ~= .5) or (object.anchorY ~= .5))then --creo un immagine solo per il giusto posizonamento del ancoraggio trail.tmp = display.newRect(trail, 0, 0, object.width, object.height) trail.tmp.isVisible = false trail.anchorChildren = true trail.anchorX = object.anchorX trail.anchorY = object.anchorY end if options.parent then options.parent:insert( trail ) else if object.parent then object.parent:insert( trail ) end end trail.ox, trail.oy, trail.oz, trail.oa = object.x, object.y, ( object.z or 0 ), object.rotation trail.alpha = alpha local function enterFrame() frame = frame + 1 -- Object destroyed if not object.contentBounds then trail:finalize() return false end -- Haven't moved if lenSqr( object.x - trail.ox, object.y - trail.oy, ( object.z or 0 ) - trail.oz ) \< 1 \* 1 then return false end trail.ox, trail.oy, trail.oz = object.x, object.y, (object.z or 0) if frame \> frameSkip then frame = 1 else return false end -- Create trail local particle = display.newImageRect( trail, image, w, h ) transition.from( particle, { alpha = 0, time = delay } ) -- Color particle:setFillColor( unpack(color) ) particle.blendMode = blendMode -- Place particle.x, particle.y = object.x + ox, object.y + oy - ( object.z or 0 ) particle.rotation = object.rotation -- Finalization trans.onComplete = function() display.remove( particle ) particle = nil end -- Transition transition.to( particle, trans ) end Runtime:addEventListener("enterFrame", enterFrame) function trail:finalize() Runtime:removeEventListener( "enterFrame", enterFrame ) local function onComplete() display.remove( self ) trail = nil end transition.to( trail, {alpha = 0, onComplete = onComplete } ) end trail:addEventListener( "finalize" ) return trail end newTrail( myImage, { frameSkip = 5, transition = { time = 1000, alpha = 0, delay = 50, xScale = 0.01, yScale = 0.01 } } )
image:
My question is there a way to avoid this?
for example, I would prefer that the main ball momentarily block rather than ruining the trail.
Or anything else
Thanks in advance…