Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

attempt to call method 'setLinearVelocity' (a nil value) Error
Started by JoeMakesGames Feb 23 2019 04:41 PM

4 replies to this topic

Best Answer horacebury , 23 February 2019 - 10:24 PM

I recommend (strongly) that you start the physics engine at the very beginning of your app and only either pause/resume it or simply don't apply it to objects.

 

Just trust me on this.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

JoeMakesGames

[GLOBAL: userInfoPane.html]
JoeMakesGames
  • Observer

  • 7 posts
  • Corona SDK

I'm trying to spawn in a simple rectangle object and just get it to move to the left but I can't get Corona to recognize setLinearVelocity.  It keeps saying that it's a nil value. I don't known why that is.

local function createBarrier()
    local barrier = display.newRect(mainGroup, 0, 0, 20, 100)
    physics.addBody(barrier, "kinematic")
    barrier.myName = "barrier"
    barrier:setFillColor(0, 1, 0)
    barrier.x = display.contentWidth
    barrier.y = display.contentHeight - 270
    barrier:setLinearVelocity( 50, 0)
    table.insert( barriers, barrier)
end


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

was physics started by then?



[TOPIC: post.html]
#3

JoeMakesGames

[GLOBAL: userInfoPane.html]
JoeMakesGames
  • Observer

  • 7 posts
  • Corona SDK

I checked and realized my problem. I was calling this function right from the start via a timer.performWithDelay game loop, but I have it set to only start physics by tapping a 'start' button. I think I need to toggle the game loop timer on only after the start button is pressed.  Is there a way to toggle timers and listeners on and off?

 

Thanks



[TOPIC: post.html]
#4

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,059 posts
  • Corona SDK

  Best Answer

I recommend (strongly) that you start the physics engine at the very beginning of your app and only either pause/resume it or simply don't apply it to objects.

 

Just trust me on this.


  • roaminggamer likes this

[TOPIC: post.html]
#5

JoeMakesGames

[GLOBAL: userInfoPane.html]
JoeMakesGames
  • Observer

  • 7 posts
  • Corona SDK

I did not realize that you could initialize the physics engine and then pause it.  After playing around with that, everything works (so far).  That was much easier than playing around with listeners.  Thanks!

 

I'll mark this as solved.




[topic_controls]
[/topic_controls]