Endless Runner Help

Back again with another few issues regarding my endless running/sledding game that I’m working on. Basically it revolves around a sled sliding down a hill and is more just me messing with physics and spawning terrain features, etc. but I’m having a few issues.

The first involves scrolling the screen with the player. In my enterFrame event I have the following:

local function frameEvent(event)&nbsp; &nbsp;local deltaX = (-1)\*math.abs(lastX - sled.x); &nbsp;local deltaY = (-1)\*math.abs(lastY - sled.y); &nbsp;for i = tiles.numChildren, 1, -1 do &nbsp;&nbsp;tiles[i]:translate(deltaX, deltaY); &nbsp;&nbsp; &nbsp;&nbsp;if (tiles[i].x + 128) \< display.screenOriginX then &nbsp;&nbsp;&nbsp;display.remove(tiles[i]); &nbsp;&nbsp;end &nbsp;end &nbsp; &nbsp;local speedX, speedY = sled:getLinearVelocity(); &nbsp;if speedX \> 50 then &nbsp;&nbsp;sled:setLinearVelocity(50, speedY); &nbsp;end &nbsp; &nbsp;lastX = sled.x; &nbsp;lastY = sled.y; end

Basically I spawn all of my terrain into the tiles group and want to scroll these tiles backwards as the player moves forwards. However, the following happens:

(Beginning)

MSo0qMz.png

(After ~4-5s)

kJ0Z6yy.png

Basically the scrolling is happening but not fast enough, so what’s the best way to do this? I thought basing it on the player’s x and y-cords would work.

My second problem is that the terrain eventually doesn’t spawn correctly (with respect to the y-coords). I’m using the following code right now to randomly generate slopes:

local function newTerrain() &nbsp;local width = math.random(64, 128); &nbsp;local height = math.random(16, 64); &nbsp; &nbsp;local polyVerts = {(-0.5)\*width, (-0.5)\*height, 0.5\*width, 0.5\*height, (-0.5)\*width, 0.5\*height}; &nbsp; &nbsp;local poly = display.newPolygon(tiles, spawnX + 0.5\*width, spawnY + 0.5\*height, polyVerts); &nbsp;poly:setFillColor(0.557, 1, 1); &nbsp; &nbsp;if physicsStarted then &nbsp;&nbsp;physics.addBody(poly, {density = 3, friction = 0.1, bounce = 0.2, shape = polyVerts}); &nbsp;&nbsp;poly.bodyType = "static"; &nbsp;else &nbsp;&nbsp;poly.savedVerts = polyVerts; &nbsp;end &nbsp; &nbsp;local rect = display.newRect(tiles, spawnX + 0.5\*width, spawnY + height + 400, width, 800); &nbsp;rect:setFillColor(0.557, 1, 1); &nbsp;spawnX = spawnX + width; &nbsp;spawnY = spawnY + height; &nbsp; &nbsp;return width; end &nbsp; function scene:show(event) &nbsp;local sceneGroup = self.view; &nbsp;local phase = event.phase; &nbsp;if phase == "will" then &nbsp;&nbsp;physics.start(); &nbsp;&nbsp;physics.setGravity(0, 6); &nbsp;&nbsp; &nbsp;&nbsp;physicsStarted = true; &nbsp;&nbsp;physics.addBody(sled, {density = 3, friction = 0.02, bounce = 0}); &nbsp;&nbsp; &nbsp;&nbsp;for i = tiles.numChildren, 1, -1 do &nbsp;&nbsp;&nbsp;if tiles[i].savedVerts ~= nil then &nbsp;&nbsp;&nbsp;&nbsp;physics.addBody(tiles[i], {density = 3, friction = 0.8, bounce = 0.2, shape = tiles[i].savedVerts}); &nbsp;&nbsp;&nbsp;&nbsp;tiles[i].bodyType = "static"; &nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end &nbsp; &nbsp;&nbsp;Runtime:addEventListener("enterFrame", frameEvent); &nbsp;elseif phase == "did" then &nbsp;&nbsp;timer.performWithDelay(1, newTerrain, 0); &nbsp;end end

It works for the first part however eventually (after about 20s) the following starts to occur:

YxOwnxZ.png

It just continues to slowly become more and more offset but I don’t know why.

Also just posted the whole file for reference if that helps: https://hastebin.com/jutoyomofi.lua.

Thanks

Hi @danielbeer1376,

I’m curious, have you explored our “Endless Sk8boarder” sample template? It’s a full, customizable endless runner template which looks, in many ways, like what you’re designing. It might be a perfect starting point for you to customize a new game:

https://docs.coronalabs.com/guide/programming/index.html#endless-sk8boarder

Best regards,

Brent

[quote name=“Brent Sorrentino” post=“359656” timestamp=“1497560519”]Hi @danielbeer1376, I’m curious, have you explored our “Endless Sk8boarder” sample template? It’s a full, customizable endless runner template which looks, in many ways, like what you’re designing. It might be a perfect starting point for you to customize a new game:   https://docs.coronalabs.com/guide/programming/index.html#endless-sk8boarder   Best regards, Brent[/quote] I did take a look at that but just couldn’t make sense of it. The terrain system is much more complicated than what I’m trying to do and even after dissecting it couldn’t figure out what was causing the spawning offset. Couldn’t really figure out the scrolling either based on it

@daniel if you are not understanding the template then maybe you are out of your depth and you should spend time with smaller projects learning how things work.

I am in no way “putting you down” or anything… but you WILL be a better programmer and more likely to release a successful game if you spend time perfecting the basics before ramping up the complexity.  Even if this may seem boring.

I would agree however I have worked through the tutorials and am just having trouble applying the template to what I am doing since I don’t want to copy and paste code

Hi @danielbeer1376,

I’m curious, have you explored our “Endless Sk8boarder” sample template? It’s a full, customizable endless runner template which looks, in many ways, like what you’re designing. It might be a perfect starting point for you to customize a new game:

https://docs.coronalabs.com/guide/programming/index.html#endless-sk8boarder

Best regards,

Brent

[quote name=“Brent Sorrentino” post=“359656” timestamp=“1497560519”]Hi @danielbeer1376, I’m curious, have you explored our “Endless Sk8boarder” sample template? It’s a full, customizable endless runner template which looks, in many ways, like what you’re designing. It might be a perfect starting point for you to customize a new game:   https://docs.coronalabs.com/guide/programming/index.html#endless-sk8boarder   Best regards, Brent[/quote] I did take a look at that but just couldn’t make sense of it. The terrain system is much more complicated than what I’m trying to do and even after dissecting it couldn’t figure out what was causing the spawning offset. Couldn’t really figure out the scrolling either based on it

@daniel if you are not understanding the template then maybe you are out of your depth and you should spend time with smaller projects learning how things work.

I am in no way “putting you down” or anything… but you WILL be a better programmer and more likely to release a successful game if you spend time perfecting the basics before ramping up the complexity.  Even if this may seem boring.

I would agree however I have worked through the tutorials and am just having trouble applying the template to what I am doing since I don’t want to copy and paste code