Simple question in physics body - why it's not working? :(

Hi guys, 

I am just learning the tap event and physics. I have an object on the screen in static mode. I want to tap on it and it falls down (that is the bodyType should become dynamic ). why my code is not working?

local physics = require('physics') physics.start() center\_x = display.contentCenterX center\_y = display.contentCenterY bird = display.newImageRect('bird.png', 101, 171) bird.x = center\_x bird.y = center\_y physics.addBody(bird, "static") function screen\_touched(event) bird.BodyType = "dynamic" end bird:addEventListener('tap', screen\_touched) 

Thank you so much

Andy

Hi, there is a small typo in your code:

 bird.BodyType = "dynamic" 

BodyType should not be written with a capital B

The correct line is:’

  bird.bodyType = "dynamic" 

LUA is very funny that way… If the variable does not exist it just creates it - no warnings or anything. It’s very unfamiliar if you’re used to writing in c/c++ as me…

I also did not get any response on listening to ‘tap’. I used ‘touch’ myself to test the code. The whole shebang is here:

local physics = require('physics') physics.start() center\_x = display.contentCenterX center\_y = display.contentCenterY bird  = display.newImageRect('bird.png', 101, 171) bird.x = center\_x bird.y = center\_y physics.addBody(bird, "static") function screen\_touched(event) print("tapped")   bird.bodyType = "dynamic"     end bird:addEventListener('touch', screen\_touched)

-Rune

Hi Rune,

It’s working now, as you said the B in bodyType should not be capital.
The tap event is now working.

Thank you so much
Andy

Hi, there is a small typo in your code:

 bird.BodyType = "dynamic" 

BodyType should not be written with a capital B

The correct line is:’

  bird.bodyType = "dynamic" 

LUA is very funny that way… If the variable does not exist it just creates it - no warnings or anything. It’s very unfamiliar if you’re used to writing in c/c++ as me…

I also did not get any response on listening to ‘tap’. I used ‘touch’ myself to test the code. The whole shebang is here:

local physics = require('physics') physics.start() center\_x = display.contentCenterX center\_y = display.contentCenterY bird  = display.newImageRect('bird.png', 101, 171) bird.x = center\_x bird.y = center\_y physics.addBody(bird, "static") function screen\_touched(event) print("tapped")   bird.bodyType = "dynamic"     end bird:addEventListener('touch', screen\_touched)

-Rune

Hi Rune,

It’s working now, as you said the B in bodyType should not be capital.
The tap event is now working.

Thank you so much
Andy