I have a section of code in Golem Particle that is supposed to make a random x and y within a radius, and it works. It’s used to set the beginning particle’s x and y. I am trying to add a new vent style where you can specify the ending point too, though. So I thought, “If you can make a random x and y within a radius to appear within, why can’t you create a random x and y within a radius to transition.to?” So I made the exact same function with an endRadius instead of just a radius. Here comes my problem. Every time I use the function, the corona simulator crashes and I get the spinning beach ball. The appear within radius function works fine. Just the transition radius doesn’t. Here’s my code for the random position:
[lua]local function newCircleEmit()
local function burst()
if (random) then
r1, r2, g1, g2, b1, b2, a1, a2=math.random(255), math.random(255), math.random(255), math.random(255), math.random(255), math.random(255), math.random(255), math.random(255)
end
local color=newFillColor({r1, r2}, {g1, g2}, {b1, b2}, {a1, a2})
local r=color[1]
local g=color[2]
local b=color[3]
local a=color[4]
local X1 = math.random(-startRadius, startRadius)
local Y1 = math.random(-startRadius, startRadius)
local X2 = math.random(-endRadius, endRadius)
local Y2 = math.random(-endRadius, endRadius)
while math.sqrt( (X1 - ventPoint.x)*(X1 - ventPoint.x) + (Y1 - ventPoint.y)*(Y1 - ventPoint.y)) > startRadius do
X1 = math.random(-startRadius, startRadius)
Y1 = math.random(-startRadius, startRadius)
end
while math.sqrt( (X2 - endPoint.x)*(X2 - endPoint.x) + (Y2 - endPoint.y)*(Y2 - endPoint.y)) > endRadius do
X2 = math.random(-endRadius, endRadius)
Y2 = math.random(-endRadius, endRadius)
end
local particleRadius=math.random(pRadius1, pRadius2)
particle=display.newCircle(0, 0, particleRadius)
vent:insert(particle)
particle:setFillColor(r, g, b, a)
particle.x, particle.y=X1, Y1
local function killParticle(self)
self:removeSelf()
self=nil
end
transition.to(particle, {alpha=endAlpha, time=life, onComplete=killParticle})
transition.to(particle, {y=Y2, x=X2, time=particleSpeed})
end
timer.performWithDelay(0, burst, numParticles)
end[/lua]
What I do earlier is make an endPoint for the radius to be drawn around (you can specify the size) and set it’s x and y to the ending x and y you specify. If you need any more code just let me know. Any help would be appreciated very much.
binc [import]uid: 147322 topic_id: 28585 reply_id: 328585[/import]
[import]uid: 160496 topic_id: 28585 reply_id: 117246[/import]