detecting while transition.to() working

I’m moving obj1 with transition.to(). And I need to do something like that:

if(obj1.x == 50)then --do something end

I tried but this not working.

Firstly, because objects don’t move in whole content ‘pixels’, the likelihood of an object being at exactly x == 50 rather than say 49.912 or 50.403 is very small unless that is the final destination position. So you need to either check between a range or round obj1.x first to the nearest integer.

Secondly, where are you running that code? It would need to be in an enterFrame listener, or a repeating timer.

I know about ‘pixels’. Code is just example.

What about the second point?

Have you considered using onComplete with your transition?

local obj = display.newCircle( 0, 100, 10 ) function obj.enterFrame(self) if( math.floor(self.x) == 50 ) then -- do something end end; Runtime.addEventListener( 'enterFrame', obj ) function obj.finalize(self) Runtime.removeEventListener( 'enterFrame', self ) end; obj:addEventListener('finalize') transition.to( obj, { x = 100, time = 5000 } )

Note: There is a flaw in the code above. self.x may never be exactly 50, so you may need to round it to zero decimal places before testing the value.

Fixed.

XeduR, I’m not using onComplete()  because I need to check posistion WHILE transition working

Yeah, but since you are moving an object via transitions, I would simply create two transitions: first to move the object to the point where you want something to happen, and second to move the object to its final location. roaminggamer’s solution will most likely work out of the box though.

XeduR I thinked about that… I’m just wanted to discover something new about corona. And it can be laggy(not sure)

Discovering new stuff is fun but sometimes it is better to go with known and simple