I tried making coin patterns using lua tables and a general method, then added all of them in a group. They seem to be working fine but I’m facing difficulty in spawning them. These are the two ways I tried …
(This one is not actually my code … )
local coinPatterns={ line={{x=0,y=0},{x=25,y=0},{x=50,y=0}} } -- Create Individual Coin local function createCoin(x,y) local coin=display.newImageRect("images/coin.png",20,20) coin.anchorX,coin.anchorY=0,0 coin.y=y coin.x=x coin.id='coin' physics.addBody(coin,'static',{isSensor=true,radius=10}) return coin end -- Create a coin group local function createCoinGroup() local coinGroup=display.newGroup() for key,value in pairs(coinPatterns.line) do local coin=createCoin(value.x,value.y) coinGroup:insert(coin) end coinGroup.x=screenW coinGroup.y=50 transition.to(coinGroup,{time=2000,x=0-coinGroup.width,onComplete=function() coinGroup:removeSelf() coinGroup=nil end}) foregroundGroup:insert(coinGroup) end createCoinGroup()
after this hardly worked I tried a simple approach :
local function coinLine5() local coin1=display.newImage(COINGROUP,"coin.png") coin1.x=100 coin1.y=100 physics.addBody(coin1,"static",{density = 1, bounce = 0.1, friction = 2, radius = 20}) coin1.myName="coin1" local coin2=display.newImage(COINGROUP,"coin.png") coin2.x=120 coin2.y=100 physics.addBody(coin2,"static",{density = 1, bounce = 0.1, friction = 2, radius = 20}) coin2.myName="coin2" local coin3=display.newImage(COINGROUP,"coin.png") coin3.x=140 coin3.y=100 physics.addBody(coin3,"static",{density = 1, bounce = 0.1, friction = 2, radius = 20}) coin3.myName="coin3" local coin4=display.newImage(COINGROUP,"coin.png") coin4.x=160 coin4.y=100 physics.addBody(coin4,"static",{density = 1, bounce = 0.1, friction = 2, radius = 20}) coin4.myName="coin4" local coin5=display.newImage(COINGROUP,"coin.png") coin5.x=180 coin5.y=100 physics.addBody(coin5,"static",{density = 1, bounce = 0.1, friction = 2, radius = 20}) coin5.myName="coin5" COINGROUP.x=600 end coinLine5() local function moveCoins(self,event) if self.x \< -500 then Runtime:removeEventListener("enterFrame", COINGROUP) COINGROUP:removeSelf() COINGROUP=nil else self.x = self.x - objectSpeed end end COINGROUP.enterFrame=moveCoins
Same issue in both the methods … unable to spawn the coin … plz help … !!!