I currently am a Newbie and started a week ago. I’m just messing around and trying to learn new stuff and what I’m currently learning is dragging objects. here’s my code:
display.setStatusBar(display.HiddenStatusBar)
local physics = require “physics”
physics.start()
physics.setGravity(0, 0)
local bg = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
bg:setFillColor(0, 450, 220)
local big = display.newImage(“big.png”)
big.x = 100
big.y = 0
physics.addBody(big, “dynamic”, {density = 0.4, friction = 0.2, bounce = 0.3})
local small = display.newImage(“Icon.png”)
small.x = 280
small.y = 0
physics.addBody(small, “dynamic”, {density = 0.4, friction = 0.2, bounce = 0.3})
local floor = display.newRect(160, 700, display.contentWidth, display.contentHeight)
physics.addBody(floor, “static”, {density = 0.4, friction = 0.2, bounce = 0.3})
function small:touch(event)
if event.phase == “began” then
self.markX = self.x
self.markY = self.y
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y
end
return true
end
small:addEventListener(“touch”, small)
My question is: am I able to create a group where I can place all the objects into and then create a function with the name of the group to make ALL of the objects draggable or do I have to create a function for each object? Hope this isn’t confusing to understand…?