how do i reset a display.newObject

i want the object to go back to its starting position after a collision function

my code the transition is not working

[lua] local function onLocalCollision( self, event )

physics.stop()

transition.to( crate, { x=(w-50), y=(h-50), onComplete=onLocalcollision } )

end

crate.collision = onLocalcollision

crate:addEventListener(“collision”, crate)
– all display objects must be inserted into group
sceneGroup:insert( background )
sceneGroup:insert( grass)
sceneGroup:insert( crate )
sceneGroup:insert( physicsButton )
end[/lua]

Hi @tejwinderthind,

This code seems out of order. Why are you calling the same “onLocalCollision” function as the “onComplete” of the transition inside of that same function?

Also, I suggest that you be careful when (or if) you “stop” the physics engine. Typically the only reason to do so is if you’re absolutely 100% finished with all physics processes and you want to destroy the physics world outright. If there’s any possibility you’ll return to using physics later in the game, it’s much better to pause the physics engine for scenes you’re not using physics in.

Brent

The crate still does not transition i tried it this way for some reason the crate won’t move [lua] local function onLocalCollision( self, event )

print(“gg”)

physics.pause()

transition.moveTo( crate, { x=50, y=50, onLocalcollision = “collision” } )

end

crate.collision = onLocalcollision

crate:addEventListener(“collision”, crate)
– all display objects must be inserted into group
sceneGroup:insert( background )
sceneGroup:insert( grass)
sceneGroup:insert( crate )
sceneGroup:insert( physicsButton )
end
[/lua]

Hi @tejwinderthind,

Can I see how you’re creating the crate? Is it in the proper scope so that the “onLocalCollision()” function knows what “crate” is? Also, that “onLocalCollision” parameter that you’ve put inside the transition call is incorrect and invalid. Are you attempting to do something when the transition completes?

Best regards,

Brent

[lua] local crate = display.newImageRect( “crate.png”, 90, 90 )
crate.x, crate.y = 160, 45
crate.rotation = 0

– add physics to the crate
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0. } )
[/lua]

In your “onLocalCollision()” function, add this line and tell me what it says in the console:

[lua]

print( “CRATE:”, crate )

[/lua]

Brent

CRATE: table: 0x7fad9cda4480

OK, now put the same line directly after you create the crate (local crate = ). Do the output values match exactly?