Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to use rawequal (value1, value2) to find the same coordinates and change the position of an object?
Started by srzhnv Jun 06 2018 08:30 AM

2 replies to this topic
rawequal

Best Answer StarCrunch , 06 June 2018 - 08:46 AM

Hi.

 

rawequal is meant for something else; it ignores certain metamethods and checks if the "raw" objects are the same / different. (Maybe the particular object should be skipped, say, or the metamethod has a side effect.)

 

I suspect you're dealing with coordinates that are almost, but not quite, the same. In that case, use a tolerance:

local function positionCheck ()

   if (math.abs(object1.x - object2.x) < .005 then -- close enough?

 

    transition.to (object1, {time=1500, x = object1.x - 50})

    transition.to (object2, {time=1500, x = object2.x + 50})

   end

end

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

srzhnv

[GLOBAL: userInfoPane.html]
srzhnv
  • Observer

  • 10 posts
  • Corona SDK

Something like this:

 

local object1 = display.newRect(100, 100, 50, 50)   --means object1.x = 100

local object2 = display.newRect(200, 100, 50, 50)   --means object2.x = 200

 

--During the objects dragging:

 

local function positionCheck ()

   if (rawequal (object1.x, object2.x) then

 

    transition.to (object1, {time=1500, x = object1.x - 50})

    transition.to (object2, {time=1500, x = object2.x + 50})

   end

end

 
In common, is it possible whithout "physics" library?
Thank you for some words to clarify it.
 
Yuriy


[TOPIC: post.html]
#2

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 758 posts
  • Corona SDK

  Best Answer

Hi.

 

rawequal is meant for something else; it ignores certain metamethods and checks if the "raw" objects are the same / different. (Maybe the particular object should be skipped, say, or the metamethod has a side effect.)

 

I suspect you're dealing with coordinates that are almost, but not quite, the same. In that case, use a tolerance:

local function positionCheck ()

   if (math.abs(object1.x - object2.x) < .005 then -- close enough?

 

    transition.to (object1, {time=1500, x = object1.x - 50})

    transition.to (object2, {time=1500, x = object2.x + 50})

   end

end

  • roaminggamer and srzhnv like this

[TOPIC: post.html]
#3

srzhnv

[GLOBAL: userInfoPane.html]
srzhnv
  • Observer

  • 10 posts
  • Corona SDK

Thank you, StarCrunch!


  • StarCrunch likes this


[topic_controls]
[/topic_controls]