Home / Topic / triger action after layers dragged to defined area

triger action after layers dragged to defined area

Home Kwiksher Forums Help me! triger action after layers dragged to defined area

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Fionnuala
    Participant
    #85425

    Hi

    I would like to release an action (triggering sprites) after a certain number of layers have been dragged to a defined area (but not locked to that area). Is it possible to do this?

    Many thanks for any help.

    Kind regards

    Fionnuala

    Yamamoto
    Keymaster
    #85428

    please use trigger action on release and an external code to check the defined area.

    http://kwiksher.com/doc/kwik/toolset/interactions/drag.html

    Collision detection without physics.

    
    local function testCollisions()
        for i=1, #objects do
            if hasCollided(objects[i], player) then
            -- do what you need to do if they hit each other
            end
        end
    end
    
    Runtime:addEventListener("enterFrame", testCollisions)
    
    -- rectangle based
    local function hasCollided(obj1, obj2)
        if obj1 == nil then return false end
        if obj2 == nil then return false end
        local left = obj1.contentBounds.xMin <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= obj2.contentBounds.xMin
        local right = obj1.contentBounds.xMin >= obj2.contentBounds.xMin and obj1.contentBounds.xMin <= obj2.contentBounds.xMax 
        local up = obj1.contentBounds.yMin <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= obj2.contentBounds.yMin
        local down = obj1.contentBounds.yMin >= obj2.contentBounds.yMin and obj1.contentBounds.yMin <= obj2.contentBounds.yMax 
    
        return (left or right) and (up or down) 
    end 
    
    -- circle based 
    local function hasCollidedCircle(obj1, obj2)
        if obj1 == nil then return false end 
        if obj2 == nil then return false end
         local sqrt = math.sqrt 
         local dx = obj1.x - obj2.x
         local dy = obj1.y - obj2.y 
         local distance = sqrt(dx*dx + dy*dy)
         local objectSize = (obj2.contentWidth/2) + (obj1.contentWidth/2) 
         if distance < objectSize then 
            return true 
        end 
        return false 
    end
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.