Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

detecting while transition.to() working
Started by tima.xxxyyy Jan 16 2020 09:50 AM

9 replies to this topic
transition movement detect
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

tima.xxxyyy

[GLOBAL: userInfoPane.html]
tima.xxxyyy
  • Observer

  • 13 posts
  • Corona SDK

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.

 

 



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,959 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

tima.xxxyyy

[GLOBAL: userInfoPane.html]
tima.xxxyyy
  • Observer

  • 13 posts
  • Corona SDK

I know about 'pixels'. Code is just example.



[TOPIC: post.html]
#4

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,959 posts
  • Corona SDK

What about the second point?



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,169 posts
  • Corona SDK

Have you considered using onComplete with your transition?



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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.


Edited by roaminggamer, 17 January 2020 - 08:42 PM.

  • sporkfin and XeduR @Spyric like this

[TOPIC: post.html]
#7

tima.xxxyyy

[GLOBAL: userInfoPane.html]
tima.xxxyyy
  • Observer

  • 13 posts
  • Corona SDK

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



[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,169 posts
  • Corona SDK

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.



[TOPIC: post.html]
#9

tima.xxxyyy

[GLOBAL: userInfoPane.html]
tima.xxxyyy
  • Observer

  • 13 posts
  • Corona SDK

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



[TOPIC: post.html]
#10

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 154 posts
  • Corona SDK

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


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: transition, movement, detect