Hello, I am developing a game which is like classical race games. I have a character on screen and the way is sliding down infinitely.
http://img195.imageshack.us/img195/7789/way.png
I sliced the way above into 2 from mid and also copied them so I have 4 parts. I put them into an array like that;
Road.lua
roadGroup.wayList = {};
roadGroup.images = {};
roadGroup.images[1] = "images/cutWay1.jpg";
roadGroup.images[2] = "images/cutWay2.jpg";
roadGroup.images[3] = "images/cutWay3.jpg";
roadGroup.images[4] = "images/cutWay4.jpg";
local function loadWay ()
for i=1,4 do
roadGroup.wayList[i] = display.newImageRect(roadGroup.images[i], \_W, 240);
roadGroup.wayList[i]:setReferencePoint(display.CenterReferencePoint);
roadGroup.wayList[i].x = \_W/2;
roadGroup.wayList[i].y = 360 - (240\*(i-1));
roadGroup:insert(roadGroup.wayList[i]);
end
end
loadWay();
So the pieces are on screen like this;
http://img803.imageshack.us/img803/3269/ways.png
In game.lua, I use “EnterFrame” for main loop function and in this function I am calling a method of Road.lua which slides these pieces. Also it puts back a piece if its out of screen so it can loop infinitely.
function roadGroup:loop(dt)
local constVal = (speed+minSpeed)\*0.0035\*dt;
print("constVal "..tostring(constVal));
roadGroup.wayList[1].y = roadGroup.wayList[1].y + constVal;
roadGroup.wayList[2].y = roadGroup.wayList[2].y + constVal ;
roadGroup.wayList[3].y = roadGroup.wayList[3].y + constVal;
roadGroup.wayList[4].y = roadGroup.wayList[4].y + constVal;
if (roadGroup.wayList[1].y \>= 600) then
roadGroup.wayList[1].y = roadGroup.wayList[1].y -960;
elseif (roadGroup.wayList[2].y \>= 600) then
roadGroup.wayList[2].y = roadGroup.wayList[2].y -960;
elseif (roadGroup.wayList[3].y \>= 600) then
roadGroup.wayList[3].y = roadGroup.wayList[3].y -960;
elseif (roadGroup.wayList[4].y \>= 600) then
roadGroup.wayList[4].y = roadGroup.wayList[4].y -960;
end
end
And finally my problem is this code and approach doesn’t help me slide the way smoothly even I have 60 fps and using deltaTime which makes it time based. It shatters regularly, where am I doing wrong?
I have tried working it on 30fps, using with larger image pieces, using timer instead EnterFrame, set antialias = true and many more but can’t solve it, any ideas? Thanks in advance… [import]uid: 80068 topic_id: 18801 reply_id: 318801[/import]