Smoke Trails

Hi, there is some way to fire a bullet with like a cool smoke trail?

What do I need to put on the code to make that?

local function go(event) display.remove(logo) display.remove(begin) local planet = display.newImage("images/earth.png") planet.x = centerX planet.y = centerY planet:scale(4, 4) transition.to( planet, { time = 200, xScale = 1, yScale = 1, onComplete = animate} ) local function firebullet(event) local bullet = display.newCircle( planet.x, planet.y, 2 ) physics.addBody( bullet, { density=3.0, friction=0.5, bounce=0.05 } ) bullet.isBullet = true local deltax = event.x - planet.x local deltay = event.y - planet.y local bulletangle = math.atan2(deltay, deltax) local xforce = (math.cos(bulletangle))\*100 local yforce = (math.sin(bulletangle))\*100 bullet:applyForce( xforce, yforce, bullet.x, bullet.y ) end bg:addEventListener ( "tap", firebullet) end

You’re interested in a particle generator/emitter. See: https://docs.coronalabs.com/api/type/EmitterObject/index.html

Rob

  1. DL my 2015 answer packs: http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015%20Answer%20Packs.zip

  2. Run April pack and start answer to question 10

  3. Look at the code in ~/answers/projectileTrails

  4. Modify code to your hearts content.

https://www.youtube.com/watch?v=JCzrjNeNovs&feature=youtu.be

Hi, I used the code but nothing diferent happens. Maybe, the cause is the first if?

local function go(event) display.remove(logo) display.remove(begin) local planet = display.newImage("images/earth.png") planet.x = centerX planet.y = centerY planet:scale(4, 4) transition.to( planet, { time = 200, xScale = 1, yScale = 1, onComplete = animate} ) startGame() timerGame() timeCount() local function firebullet(event) local bullet = display.newCircle( planet.x, planet.y, 2 ) physics.addBody( bullet, { density=3.0, friction=0.5, bounce=0.05 } ) bullet.isBullet = true local deltax = event.x - planet.x local deltay = event.y - planet.y local bulletangle = math.atan2(deltay, deltax) local xforce = (math.cos(bulletangle))\*100 local yforce = (math.sin(bulletangle))\*100 bullet:applyForce( xforce, yforce, bullet.x, bullet.y ) bullet.lastX = bullet.x bullet.lastY = bullet.y bullet.enterFrame = function( self ) if( self.removeSelf == nil or self.parent == nil) then Runtime:removeEventListener( enterFrame, self ) return end for i = 1, 3 do local tmp = display.newCircle( self.parent, self.x + math.random(-2,2), self.y + math.random(-2,2), self.contentWidth/2 ) tmp.alpha = 0.5 tmp:setFillColor(0.25,0.25,0.25) tmp:toBack() transition.to( tmp, { alpha = 0.05, xScale = 0.5, yScale = 0.5, time = 1000, onComplete = display.remove }) end end Runtime:addEventListener( "enterFrame", bullet ) end bg:addEventListener ( "tap", firebullet) end

I don’t see anything obvious …

Have you checked to see if the first ‘if-statement’ is executing by putting a print statement in it?  

Please dig deeper and debug the code till you find the issue.  Use print statement, look at the console and see what flow the code is taking.  These are the same steps I’d have to take to help you fix this.

I know the concept I coded works, you’ve just got to apply it to your own game.

Sorry this isn’t a drop in solution, but it’s pretty close and this is the nature of making games w/ an SDK.  

@alfredocosta25

I don’t know if you ever sorted this out, but the line where you remove the eventlistener should have quotes around the enterFrame section like this…

Runtime:removeEventListener( "enterFrame", self )

Hope that helps (if you didn’t already get it).

All the best

Chris

You’re interested in a particle generator/emitter. See: https://docs.coronalabs.com/api/type/EmitterObject/index.html

Rob

  1. DL my 2015 answer packs: http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015%20Answer%20Packs.zip

  2. Run April pack and start answer to question 10

  3. Look at the code in ~/answers/projectileTrails

  4. Modify code to your hearts content.

https://www.youtube.com/watch?v=JCzrjNeNovs&feature=youtu.be

Hi, I used the code but nothing diferent happens. Maybe, the cause is the first if?

local function go(event) display.remove(logo) display.remove(begin) local planet = display.newImage("images/earth.png") planet.x = centerX planet.y = centerY planet:scale(4, 4) transition.to( planet, { time = 200, xScale = 1, yScale = 1, onComplete = animate} ) startGame() timerGame() timeCount() local function firebullet(event) local bullet = display.newCircle( planet.x, planet.y, 2 ) physics.addBody( bullet, { density=3.0, friction=0.5, bounce=0.05 } ) bullet.isBullet = true local deltax = event.x - planet.x local deltay = event.y - planet.y local bulletangle = math.atan2(deltay, deltax) local xforce = (math.cos(bulletangle))\*100 local yforce = (math.sin(bulletangle))\*100 bullet:applyForce( xforce, yforce, bullet.x, bullet.y ) bullet.lastX = bullet.x bullet.lastY = bullet.y bullet.enterFrame = function( self ) if( self.removeSelf == nil or self.parent == nil) then Runtime:removeEventListener( enterFrame, self ) return end for i = 1, 3 do local tmp = display.newCircle( self.parent, self.x + math.random(-2,2), self.y + math.random(-2,2), self.contentWidth/2 ) tmp.alpha = 0.5 tmp:setFillColor(0.25,0.25,0.25) tmp:toBack() transition.to( tmp, { alpha = 0.05, xScale = 0.5, yScale = 0.5, time = 1000, onComplete = display.remove }) end end Runtime:addEventListener( "enterFrame", bullet ) end bg:addEventListener ( "tap", firebullet) end

I don’t see anything obvious …

Have you checked to see if the first ‘if-statement’ is executing by putting a print statement in it?  

Please dig deeper and debug the code till you find the issue.  Use print statement, look at the console and see what flow the code is taking.  These are the same steps I’d have to take to help you fix this.

I know the concept I coded works, you’ve just got to apply it to your own game.

Sorry this isn’t a drop in solution, but it’s pretty close and this is the nature of making games w/ an SDK.  

@alfredocosta25

I don’t know if you ever sorted this out, but the line where you remove the eventlistener should have quotes around the enterFrame section like this…

Runtime:removeEventListener( "enterFrame", self )

Hope that helps (if you didn’t already get it).

All the best

Chris