Touch Function Problem

YES!!! WORK’S!!!

Thank you !!!

Great news!

Hello again …
I wanted to help me if possible to limit the screen so that the images do not they left the same

If you’re using Physics, then you create invisible walls with display.newRect() just off screen along the edges you want to block, make them static physics bodies and it will keep things on screen.

If you’re not using physics, in whatever code you use to move an object, check the .x value of the object and if it’s off screen stop the movement.

elseif event.phase == "moved" then if touchedObject.previousX == nil then touchedObject.previousX = 0 end if touchedObject.previousY == nil then touchedObject.previousY = 0 end touchedObject.x = (event.x - event.xStart) + touchedObject.previousX touchedObject.y = (event.y - event.yStart) + touchedObject.previousY if touchedObject.x \< (touchedObject.width \* 0.5) then touchedObject.x = touchedObject.width \* 0.5 end if touchedObject.x \> ( display.actualContentWidth - touchedObject.width \* 0.5 ) then touchedObject.x = display.actualContentWidth - touchedObject.width \* 0.5 end if touchedObject.y \< (touchedObject.height \* 0.5) then touchedObject.y = touchedObject.heigth \* 0.5 end if touchedObject.y \> (display.actualContentHeight - touchedObject.heigth \* 0.5) then touchedObject.y = display.actualContentHeight - touchedObject.heigth \* 0.5 end

or something like that.

Rob

I have this for background

local background = display.newImageRect( "Campo1F.tif", 512,300 ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2

Work’s like newrect () ?

I don’t think we support .tif files, but yes, it’s similar to newRect, except that you don’t give it a x and y as a parameter. It works like you have it.

All my images are in .tif and work xD
I have this code and they you continue to exit the screen

Help pls
I now after moving the images you intended to make a line that begins at the initial position where the user moved …

Hello David,

unfortunetly I am not sure what you want to achieve.

Do you want to move an image according to yor touch position, or do you want it to move on it’s own after a touch?

Additional information would be necessary to understand the questian and suggest a solution.

Perhaps try this:

-- create object local camisola1 = display.newImage("Camisola-F1.tif",45,60) -- create object local camisola2 = display.newImage("Camisola-F2.tif",45,110) -- create object local camisola3 = display.newImage("Camisola-F3.tif",45,160) -- create object local camisola4 = display.newImage("Camisola-F4.tif",45,210) -- create object local camisola5 = display.newImage("Camisola-F5.tif",45,260) local function camisolaTouch(event) local touchedObject = event.target if event.phase == "began" then display.getCurrentStage():setFocus( touchedObject ) touchedObject.previousX = touchedObject.x touchedObject.previousY = touchedObject.y elseif event.phase == "moved" then touchedObject.x = (event.x - event.xStart) + touchedObject.previousX touchedObject.y = (event.y - event.yStart) + touchedObject.previousY elseif event.phase == "cancelled" then display.getCurrentStage():setFocus( nil ) end return true end camisola3:addEventListener( "touch" , camisolaTouch) camisola4:addEventListener( "touch" , camisolaTouch) camisola5:addEventListener( "touch" , camisolaTouch) camisola2:addEventListener( "touch" , camisolaTouch) camisola1:addEventListener( "touch" , camisolaTouch)

I want to move the images on top of each other , but this function is not working. My project is a tactical framework for coaches, with so he could move the images , which are the players , where desired .

This is my app : ExBkK7.png

JonPM with this function can only drag one image at a time I wish I could drag more

We support multi-touch. However devices may limit how many touches can be active at once. We support a maximum of 10 touches. The Kindle Fire for instance will only let you have two touches at once.

Rob

You need to be able to move more than 1 image at the exact same time?  Or can the user just move each player one by one

One by one, the coach moves one image at a time

So what is the problem with my code exactly?  You said it moves one image at a time

yes but when the images touch they flee each other and sometimes gives error RoVYQi.png

Help Pls :c

Can you post your current code?

Rob

local composer = require( “composer” )
local scene = composer.newScene()
local function buttonHit(event)
    composer.gotoScene( event.target.destination )
    return true
end

– include Corona’s “physics” library
local physics = require “physics”
physics.start(); physics.pause()


– forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5

function scene:create( event )

    local sceneGroup = self.view

    – create a grey rectangle as the backdrop
    local background = display.newImage( “Campo1F.tif”, true )
 background.x = display.contentWidth / 2
 background.y = display.contentHeight / 2

    
    
    – all display objects must be inserted into group
    sceneGroup:insert( background )

end

function scene:show( event )
    local sceneGroup = self.view
    local phase = event.phase
    
    
    if phase == “will” then
    
–Voltar
    local backBtn = display.newImageRect(“botaoV.tif”,50,25)
    backBtn.x= 500
    backBtn.y= 296
    backBtn.destination = “menu”
    backBtn:addEventListener(“tap”, buttonHit)
    composer.removeScene(true)
    sceneGroup:insert(backBtn)
    
    
 – Inserir a Camisola
local camisola1 = display.newImageRect(“Camisola-F1.tif”,35,60)
camisola1.x = 45
camisola1.y = 50
sceneGroup:insert(camisola1)
    
 – Inserir a Camisola
local camisola2 = display.newImageRect(“Camisola-F2.tif”,35,60)
camisola2.x=45
camisola2.y=110
sceneGroup:insert(camisola2)
    
 – Inserir a Camisola
local camisola3 = display.newImageRect(“Camisola-F3.tif”,35,60)
camisola3.x=45
camisola3.y=160
sceneGroup:insert(camisola3)
    
 – Inserir a Camisola
local camisola4 = display.newImageRect(“Camisola-F4.tif”,35,60)
camisola4.x=45
camisola4.y=210
sceneGroup:insert(camisola4)
    
 – Inserir a Camisola
local camisola5 = display.newImageRect(“Camisola-F5.tif”,35,60)
camisola5.x=45
camisola5.y=260
sceneGroup:insert(camisola5)

local function camisolaTouch(event)
    local touchedObject = event.target
    
        if event.phase == “began” then
            touchedObject.previousX = touchedObject.x
            touchedObject.previousY = touchedObject.y
            
        elseif event.phase == “moved” then
            touchedObject.x = (event.x - event.xStart) + touchedObject.previousX
            touchedObject.y = (event.y - event.yStart) + touchedObject.previousY
        end

        return true
end

–Botao back Android - Runtime:addEventListener( “key”, onKeyEvent )
camisola3:addEventListener( “touch” , camisolaTouch)
camisola4:addEventListener( “touch” , camisolaTouch)
camisola5:addEventListener( “touch” , camisolaTouch)
camisola2:addEventListener( “touch” , camisolaTouch)
camisola1:addEventListener( “touch” , camisolaTouch)
    

    elseif phase == “did” then
    
        physics.start()
    end
end

function scene:hide( event )
    local sceneGroup = self.view
    
    local phase = event.phase
    
    if event.phase == “will” then
    
        physics.stop()
    elseif phase == “did” then
    
    end    
    
end

function scene:destroy( event )
    local sceneGroup = self.view
    
end


scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )