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]
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.
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
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()
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]
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]