Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Pass variable into vent group build function
Started by s0527705277 Jul 10 2013 01:05 AM

2 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

s0527705277

[GLOBAL: userInfoPane.html]
s0527705277
  • Enthusiast

  • 47 posts
  • Corona SDK

I'm a little stuck in trying to pass variable into vent group build function.

 

for example:

in vent group i've this function

 

            build=function(size)
                local size=math.random(size, size)
 

How can i pass the "size" variable?


what i've tried

 

function fireBall(x,y,size)
    local group = burn:get("burn")
    group.x, group.y = x, y
    group.size = size
    burn:start("burn")
end
fireBall(20,220, 15)
    

 

burn=CBE.VentGroup{
        {
            preset="burn",
            color={{255, 111, 0}, {255, 70, 0}}, -- Reddish-orange colors
            build=function(size)
                local size=math.random(size, size)
                return display.newImageRect("media/generic_particle.png", size, size)
            end,
            onCreation=function()end, -- See the note for the ice comet
            x=20,
            y=20,
            perEmit=2,
            positionType="inRadius",
            posRadius=20,
            emitDelay=50,
            fadeInTime=500,
            lifeSpan=500, -- Particles are removed sooner than the ice comet
            lifeStart=500,
            endAlpha=0,
            physics={
                relativeToSize=false,
                sizeX=-0.01,
                sizeY=-0.01,
                autoAngle=false,
                angles={135},
                relativeToSize=false,
                velocity=3,
                xDamping=1,
                gravityY=-0.01,
                gravityX=0.01
            }
        },
        {
            preset="burn", -- Not the smoke preset because it's just about the same as the burn effect, just with a few changes
            title="smoke", -- The smoke vent
            color={{100}},
            build=function()
                local size=math.random(120, 140)
                return display.newImageRect("media/smoke.png", size, size)
            end,
            propertyTable={blendMode="screen"}, -- Lighten the comet slightly
            onCreation=function()end,
            perEmit=1,
            y=384,
            x=512,
            positionType="inRadius",
            posRadius=20,
            emitDelay=50,
            fadeInTime=500,
            lifeSpan=500,
            lifeStart=500,
            alpha=0.5,
            endAlpha=0,
            physics={
                relativeToSize=false,
                sizeX=-0.01,
                sizeY=-0.01,
                autoAngle=false,
                angles={90},
                relativeToSize=false,
                velocity=3,
                xDamping=1,
                gravityY=-0.01,
                gravityX=0.01
            }
        }
    }
 

 

 

 



[TOPIC: post.html]
#2

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Variables can't be passed into the build function itself unless you edit the library. However, you can use a property belonging to the vent to do it, using just a few changes to your functions:

function fireBall(x,y,size)    local group = burn:get("burn")    group.x, group.y = x, y
    group.size = size
    burn:start("burn")endfireBall(20,220, 15)

 

And then for the build function (the only argument passed to the build function - at least with the most recent version - is the vent itself):

build=function(vent)    -- local size=math.random(vent.size, vent.size) -- Not sure why you're using math.random - you could just as easily do this, and it would take less time:
   local size=vent.size
 
   (build particle)
end



[TOPIC: post.html]
#3

s0527705277

[GLOBAL: userInfoPane.html]
s0527705277
  • Enthusiast

  • 47 posts
  • Corona SDK

Worked like a charm, thanks!




[topic_controls]
[/topic_controls]