A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Creating a explosion
Started by decaobr Aug 19 2013 02:56 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

decaobr

[GLOBAL: userInfoPane.html]
decaobr
  • Starter
  • PipPipPip
  • 31 posts
  • Advanced Member

So guys i'm trying to create a explosion in my game, a found a tutorial and come up with this:

 

 

local function exploLission ( self, event) 
        print(event.other.type)
        print(self.type)
        if(event.phase == "began") then
          local forcex = event.other.x-self.x  
          local forcey = event.other.y-self.y-20  
           if(forcex < 0) then  
            forcex = 0-(60 + forcex)-12  
           else  
            forcex = 60 - forcex+12  
        end  
        event.other:applyForce( forcex, forcey, self.x, self.y )  
       end  
      end  

      local circle = display.newCircle( -100, -100, 60 )
      physics.addBody(circle, "static", {isSensor = true, filter = filtroExplosoes})
      circle.type = "circle"
      group:insert(circle)
      circle.collision = exploLission
      circle:addEventListener("collision", circle)
     
       local function criarExplosao(cirx, ciry)
         circle.x = cirx
         circle.y = ciry
       end
        criarExplosao(100, 100)

In my collision detector ( exploLission ), i manage to print out, the type of my circle, and the type of the other object, so the collision is being detected, but for some reason the event.other:applyforce, is being complete ignored.

 

event.other is a object in transition.to() does this matter?



[TOPIC: post.html]
#2

aukStudios

[GLOBAL: userInfoPane.html]
aukStudios
  • Pro
  • PipPipPipPipPipPip
  • 995 posts
  • Jedi

Yes, it does matter if the transition is affecting the object's position. You shouldn't apply transitions to the positions of physics object, because the physics engine needs to 'own' the object. If the transition is affecting some other property of the object, like alpha, then it won't matter. You might also try applying a larger force. Maybe it appears nothing is happening simply because the force is too small. - Andrew

[TOPIC: post.html]
#3

Alex@PaNc

[GLOBAL: userInfoPane.html]
Alex@PaNc
  • Pro
  • PipPipPipPipPipPip
  • 911 posts
  • Jedi

Here's some sample code for explosions that might be a bit cleaner:

 

		local function createStar()
			local starSpeed = 10
			local starTime = 1200
			local powerUpRandom = math.random
				timer.performWithDelay(10, function()
				local starDown = display.newRect(0,0,10,10)
				starDown:setFillColor(255,235,0)
				physics.addBody( starDown, "dynamic",{ density = 3.0, isSensor=true } )
				starDown:applyForce(2*(powerUpRandom(starSpeed*-1,starSpeed)),2*(powerUpRandom(starSpeed*-1,starSpeed)), starDown.x*(powerUpRandom(1,10)), starDown.y*(powerUpRandom(1,10)))
				starDown:applyTorque(3*powerUpRandom(25,35))
				starDown.x = 100
				starDown.y = 100
				game7:insert(starDown)
				transition.to(starDown, {time=starTime, alpha=.1})
				return starDown
			end, 15)
		end

That's kind of an easy standalone snippet that generates an explosion type animation. Hope it helps!




[topic_controls]
[/topic_controls]