简体   繁体   中英

Inserting display objects into a group or table

I want to add these emitter objects into a group without having to do it manually. I was going to do Emitter..i but it's not a string

local function createEmitter(X,Y)
local emitter = display.newEmitter( emitterParams ) 
  emitter:scale(1.5,1.3)
  emitter.isVisible = false         
  emitter.x =X
  emitter.y =Y
  return emitter
end 

emitter_1 = createEmitter()
emitter_2 = createEmitter()
emitter_3 = createEmitter()
for i=1,3 do        
  EmitGroup:insert(emitter_1)
end

Instead of adding it in to group using for loop you can insert them inside the function itself.

local function createEmitter(X,Y)
  local emitter = display.newEmitter( emitterParams ) 
  emitter:scale(1.5,1.3)
  emitter.isVisible = false         
  emitter.x =X
  emitter.y =Y
  EmitGroup:insert(emitter) -- Added line
 return emitter
end 

emitter_1 = createEmitter()
emitter_2 = createEmitter()
emitter_3 = createEmitter()

-- for i=1,3 do
-- EmitGroup:insert(emitter_1) --end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM