@jayantv
Here’s my latest code. Tested this on my old ipod 3G and it works like a charm. But I’d like to know why this would perform in a buggy way before I use it on my game? I searched the forum as you mentioned but would like to hear your thoughts. Many thanks for the help!
[lua]-- Hide status bar
display.setStatusBar(display.HiddenStatusBar);
– Set up variables
local screenWidth = display.contentWidth;
local screenHeight = display.contentHeight;
local start_x;
local x_move;
local xOffset;
local scrollVelocity = 0;
local totalScrollMove;
local backgroundWidth = 2500;
– create new display group to hold the scrolling
– scrollB = scrolling background
local scrollB = display.newGroup();
– Image to use as background
local background = display.newImage(“back3.png”);
scrollB:insert(background);
scrollB.width=2500;
scrollB.height = 320;
– Scrolling function
local function makeScroll(event)
if(event.phase==“began”) then
– stop any scrolling
scrollVelocity = 0;
– record offset
xOffset = event.x - scrollB.x;
x_move = 0;
start_x = event.x;
end
– move background group
scrollB.x = event.x - xOffset;
–scroll B was dragged to the right, past boundaries
if(scrollB.x > 50) then
transition.to(scrollB, {x=0, time=500});
end
print(scrollB.x);
if(scrollB.x < (screenWidth - backgroundWidth)) then
scrollB.x = (screenWidth - backgroundWidth);
end
– record total x move, used for flick scroll
if(event.phase == “moved”) then
if(event.x > start_x) then
x_move = event.x - start_x;
start_x = event.x;
direction = “right”;
else
x_move = start_x - event.x;
start_x = event.x;
direction = “left”;
end
end
– when phase ended, apply any velocity
if(event.phase == “ended”) then
scrollVelocity = x_move;
end
end
local function extraScrollMove()
if(direction==“right”) then
scrollB.x = scrollB.x + scrollVelocity;
scrollVelocity = scrollVelocity -2;
if(scrollVelocity < 0) then
scrollVelocity = 0;
end
if(scrollB.x > 0) then
scrollB.x = 0;
scrollVelocity=0;
end
end
if(direction==“left”) then
scrollB.x = scrollB.x - scrollVelocity;
scrollVelocity = scrollVelocity -2;
if(scrollVelocity < 0) then
scrollVelocity = 0;
end
if(scrollB.x < (screenWidth - backgroundWidth)) then
scrollB.x = (screenWidth - backgroundWidth);
scrollVelocity=0;
end
end
end
Runtime:addEventListener(“touch”, makeScroll);
Runtime:addEventListener(“enterFrame”, extraScrollMove);[/lua] [import]uid: 55068 topic_id: 10748 reply_id: 39132[/import]