Drag image over another

(If I say this weird, it is because of my stroke, but I am a nerd so yeah… :slight_smile: )

I am not able to figure out, what seems silly but cant seem to this one.

I need to drag an image, and as I drag an image over another, if should let me know that there should till me it is over another. (so show a red image over another)
But I want to be able to leave it on top of them.

Please let me know if there is something silly,

ToughTwoImage

I’m not exactly sure of what you wish to accomplish.

If you wish to have the object that you are currently dragging always on top, then you can place all draggable display objects in the same display group. Then, when you touch any display object, you use the toFront() method.

If you want them to “stick together”, then you can move the display group where the objects are directly instead of moving the individual objects.

But, like I said, I’m not clear on what you are looking for exactly.

basically I want to only allow the drop one only something as rock under
in this image, I should not let it drop something unless there is a rock under my dig
so inside the rock has number of how much rock runs out, but if there is no rock under

(sorry my stroke SUCKS :slight_smile: )
XeduR: I will look more of the ones you sent me and check it now

So not really from the newGroup.
what I need is just as I drag an image over another image under it,
what would work if I had an image with a physics and another under an image with physics also, but I need it not to bounce off of the other, I just need it to tell me who is under another, but no bounce away.

so if there are images with physics, is there a way to not bounce but just tell me there is A and B

OK!!!
maybe silly but it is hard to read after my stroke but my nerd of my brain said that nerds are the best :slight_smile:

So the part I needed works now!!! just silly but I needed so bouncing from physics
I knew I had one of my old game test a long time ago. Anyway thank you!!

Now back to Factory :slight_smile:

local function onLocalCollision(event)
print(“Yeah it is dragging over the rock!!!”)
end

Build1 = display.newImage(onTop35, “builderA.png”, 100,100
Build1.collision = onLocalCollision
physics.addBody( Build1, “static”, {friction=2,density=1})
Build1:addEventListener( “collision”, Build1)
Build1.isFixedRotation = true

Rocks1.objtype = “lava”
Rocks1.collision = onLocalCollision
physics.addBody(Rocks1, “static”, {friction=0,density=0})
Rocks1.isSensor = true
Rocks1:toBack()

Yeah it is dragging over the rock!!!
Yeah it is dragging over the rock!!!
Yeah it is dragging over the rock!!!
Yeah it is dragging over the rock!!!
Yeah it is dragging over the rock!!!
Yeah it is dragging over the rock!!!

Tim,

You can check if one image overlaps the bounds of another image, but this overlap test is limited to the rectangular bounds.

Add this code to your game:

function display.overlaps( a, b )
	a, b = a.contentBounds, b.contentBounds
  return (a.xMin <= b.xMax) and (a.xMax >= b.xMin) and (a.yMin <= b.yMax) and (a.yMax >= b.yMin)
end

Now, you can check if display object ‘A’ overlaps ‘B’ like this:

local objA = <code to create object>
local objB = <code to create object>

...

if( display.overlaps( objA, objB ) ) then
    print("Object A is overlaping Object B")
end

The code above is a lot cheaper (computationally) than physics.

WARNING This is not about visual overlap. It is about the corners of the images’ rectangles, regardless of whether they are filled in with a visible image or not.

Also, in case you need a similar function for point here is code for point-in-rect testing too.

function display.pointInRect( point, obj )

	if(not obj) then return false end

	local bounds = obj.contentBounds
	if( point.x > bounds.xMax ) then return false end
	if( point.x < bounds.xMin ) then return false end
	if( point.y > bounds.yMax ) then return false end
	if( point.y < bounds.yMin ) then return false end
	return true
end

Thank you roaminggamer
I’ll be looking at this more, some of my test are a little works
so I am going to take this out more !

I did not real that allot of the issue was just from .isSensor = true/.isSensor = false
to help around image but link items.

(I will let you all that I cannot read text at ALL after me stroke, no book, nothing, but I learned to write from my brain but I cannot even read what I right, STRAING!! Capture2Text is the greatest of my life. I haven a nerd for my whole life, I learned making games 42 years ago, so I was 7 (49) when I started making games, I missed Corona, got now happy again… Weirdly I can read the Lua, more than anything else. so yeah, YOU ALL RULE!!!) :slight_smile:

Thank you!

1 Like