Scrolling a DisplayObject

I am making a very simple scrabble style game, and have a Group composed of my “tile sockets” which make up the game board. The tile sockets are 40px x 40px and the game board is made up of 15x15 of these.

I have added the event listener for touch to my Group, but I am at a loss as to how to actually scroll it when the user clicks and drags. I have found some decent threads on this, but am having trouble putting something together as it seems most of what I have found is the “incorrect” way of doing it. [import]uid: 72600 topic_id: 14031 reply_id: 314031[/import]

sorry I din’t get your requirement excatly. do you just want to drag a display group ? [import]uid: 71210 topic_id: 14031 reply_id: 51682[/import]

Yeah, that is really all I need to do. I just need to make sure that they can’t scroll out of the range of it, so once the side of the screen hits the edge of the group, it should stop scrolling on that axis.

Thanks! [import]uid: 72600 topic_id: 14031 reply_id: 51687[/import]

hope this is what you want…
[lua]local cameraGroup = display.newGroup()

local vertex = {}
local count = 1
for i = 1, 4 do
for j = 1, 5 do

vertex[count] = display.newCircle( 0, 0, 10)
vertex[count]:setReferencePoint(display.TopLeftReferencePoint)
vertex[count].x = (j*30)
vertex[count].y = (i*30)
vertex[count].type = “boardVertex”
cameraGroup:insert(vertex[count])
count = count + 1

end
end

local function dragCamera(event)
local phase = event.phase
if “began” == phase then
cameraGroup:setReferencePoint(display.CenterReferencePoint)
display.getCurrentStage():setFocus( cameraGroup )
cameraGroup.isFocus = true
cameraGroup.x0 = event.x - cameraGroup.x
cameraGroup.y0 = event.y - cameraGroup.y
elseif “moved” == phase then
if cameraGroup.isFocus then
if “moved” == phase then
cameraGroup.x = math.min(320 - (cameraGroup.contentWidth/2) ,math.max(0 + (cameraGroup.contentWidth/2) ,event.x - cameraGroup.x0))
cameraGroup.y = math.min(480 - (cameraGroup.contentHeight/2),math.max(0+ (cameraGroup.contentHeight/2),event.y - cameraGroup.y0))
end
end
elseif “ended” == phase then
display.getCurrentStage():setFocus( nil )
end
end

cameraGroup:addEventListener(“touch”, dragCamera) [/lua] [import]uid: 71210 topic_id: 14031 reply_id: 51692[/import]

Thank you very much, although this doesn’t seem to be working. Here is my code with your implementation in it.

[code]
local function ScrollBoard(event)

local phase = event.phase

if(event.phase==“began”) then
board:setReferencePoint(display.CenterReferencePoint)
display.getCurrentStage():setFocus( board )
board.isFocus = true
board.x0 = event.x - board.x
board.y0 = event.y - board.y
elseif(event.phase==“moved”) then
if board.isFocus then
if “moved” == phase then
board.x = math.min(320 - (board.contentWidth/2), math.max(0 + (board.contentWidth/2), event.x - board.x0))
board.y = math.min(480 - (board.contentHeight/2), math.max(0+ (board.contentHeight/2), event.y - board.y0))
end
end
elseif “ended” == phase then
display.getCurrentStage():setFocus( nil )
end
end
local function makeBoard()

board=display.newGroup()
local counter=0

for y=1, ROWS, 1 do
for x=1, COLS, 1 do

counter = counter + 1

local slot = makeTileSocket()
slot.x = (x) * SLOT_SIZE
slot.y = (y) * SLOT_SIZE
slot.id = counter
board:insert(slot)

end
end

board.x = SLOT_SIZE/2
board.y = SLOT_SIZE/2

– Center the View on the Center of the Board
board.x = board.contentCenterX
board.y = board.contentCenterY

board:addEventListener(“touch”, ScrollBoard);

end
[/code] [import]uid: 72600 topic_id: 14031 reply_id: 51711[/import]

It worked fine for me don’t know what happened when you ran it.
any way did you get your problem solved ? [import]uid: 71210 topic_id: 14031 reply_id: 51737[/import]

I haven’t figured out the issue yet. In the console window I am getting…

WARNING: Attempting to set property(x) with nil
WARNING: Attempting to set property(y) with nil

Is that normal? [import]uid: 72600 topic_id: 14031 reply_id: 51742[/import]

is this shown on your code or the code i posted ? I can’t try running your code as it is not complete.
The code I posted works fine for me with out any warning. [import]uid: 71210 topic_id: 14031 reply_id: 51748[/import]