Hi,
I’m using the tutorial from here http://mobile.tutsplus.com/tutorials/corona/build-an-endless-runner-game-from-scratch-using-sprites/
I added the sprite code on top of the background motion code and the backgrond moves and everything but the sprite is nowhere to be seen. Also I changed the original running monster in the tutorial to my own .png. Any suggestions?
--takes away the display bar at the top of the screen display.setStatusBar(display.HiddenStatusBar) --adds an image to our game centered at x and y coordinates local backbackground = display.newImage("images/background.png") backbackground.x = 240 backbackground.y = 160 local backgroundfar = display.newImage("images/bgfar1.png") backgroundfar.x = 480 backgroundfar.y = 160 local backgroundnear1 = display.newImage("images/bgnear2.png") backgroundnear1.x = 240 backgroundnear1.y = 160 local backgroundnear2 = display.newImage("images/bgnear2.png") backgroundnear2.x = 760 backgroundnear2.y = 160 --create a new group to hold all of our blocks local blocks = display.newGroup() --setup some variables that we will use to position the ground local groundMin = 420 local groundMax = 340 local groundLevel = groundMin local speed = 5; --this for loop will generate all of your ground pieces, we are going to --make 8 in all. for a = 1, 8, 1 do isDone = false --get a random number between 1 and 2, this is what we will use to decide which --texture to use for our ground sprites. Doing this will give us random ground --pieces so it seems like the ground goes on forever. You can have as many different --textures as you want. The more you have the more random it will be, just remember to --up the number in math.random(x) to however many textures you have. numGen = math.random(2) local newBlock print (numGen) if(numGen == 1 and isDone == false) then newBlock = display.newImage("images/ground1.png") isDone = true end if(numGen == 2 and isDone == false) then newBlock = display.newImage("images/ground2.png") isDone = true end --now that we have the right image for the block we are going --to give it some member variables that will help us keep track --of each block as well as position them where we want them. newBlock.name = ("block" .. a) newBlock.id = a --because a is a variable that is being changed each run we can assign --values to the block based on a. In this case we want the x position to --be positioned the width of a block apart. newBlock.x = (a \* 79) - 79 newBlock.y = groundLevel blocks:insert(newBlock) end --the update function will control most everything that happens in our game --this will be called every frame(30 frames per second in our case, which is the Corona SDK default) local function update( event ) --updateBackgrounds will call a function made specifically to handle the background movement updateBackgrounds() updateBlocks() speed = speed + .05 end function updateBlocks() for a = 1, blocks.numChildren, 1 do if(a \> 1) then newX = (blocks[a - 1]).x + 79 else newX = (blocks[8]).x + 79 - speed end if((blocks[a]).x \< -40) then (blocks[a]).x, (blocks[a]).y = newX, (blocks[a]).y else (blocks[a]):translate(speed \* -1, 0) end end end function updateBackgrounds() --far background movement backgroundfar.x = backgroundfar.x - (speed/55) --near background movement backgroundnear1.x = backgroundnear1.x - (speed/5) if(backgroundnear1.x \< -239) then backgroundnear1.x = 760 end backgroundnear2.x = backgroundnear2.x - (speed/5) if(backgroundnear2.x \< -239) then backgroundnear2.x = 760 end end --this is how we call the update function, make sure that this line comes after the --actual function or it will no t be able to find it --timer.performWithDelay(how often it will run in milliseconds, function to call, --how many times to call(-1 means forever)) timer.performWithDelay(1, update, -1) --This should look familiar, hides the status bar from view display.setStatusBar(display.HiddenStatusBar) --'sprite' is what we will be using to create our spritesheets --'require' lets Corona know that we are making calls out to already --established functions in another file. "sprite" is already built into --Corona so we don't have to do any more work on that end --We will use sprite as a 'sprite handler' to create spritesheets local sprite = require("sprite") --creating a new spritesheet will break the image you put into even blocks that are 100 --by 100, change those parameters to whatever size your images are. Note that this method --of sprite creation only works for sprites that are the same size. There are other methods --to handle sprites of different sizes, but that is beyond the scope of this tutorial. local spriteSheet = sprite.newSpriteSheet("images/rider1.png", 100, 100) --from our spritesheet we create a spriteSet, this is how we how we can group different sprites --together for organizational purposes. Say for example we had 2 different monsters, we could put --them in the same spritesheet and create 2 different sprite sets each holding the information for --their respective frames. This sprite set holds all seven frames in our image,defined by 1 and 7. local monsterSet = sprite.newSpriteSet(spriteSheet, 1, 7) --next we make animations from our sprite sets. To do this simply tell the --function which sprite set to us, next name the animation, give the starting --frame and the number of frames in the animation, the number of milliseconds --we want 1 animation to take, and finally the number of times we want the --animation to run for. 0 will make it run until we tell the animtion to stop sprite.add(monsterSet, "running", 1, 6, 600, 0) sprite.add(monsterSet, "jumping", 7, 7, 1, 1) --the last step is to make a sprite out of our sprite set that holds all of the animtions local hero = sprite.newSprite(monsterSet) --finds the center of the screen x = display.contentWidth/2 y = display.contentHeight/2 --a boolean variable that shows which direction we are moving right = true hero.x = x hero.y = y --use prepare to let the sprite know which animation it is going to use hero:prepare("running") --calling play will start the loaded animation hero:play() function update() --if we are running right then keep moving right if(right) then hero.x = hero.x + 3 --if we are not moving right keep moving left else hero.x = hero.x - 3 end --if our monster has run off the screen have him turn --and run in the opposite direction. hero.xScale = -1 --will flip our sprite horizontally if(hero.x \> 380) then right = falsea hero.xScale = -1 end if(hero.x \< -60) then right = true hero.xScale = 1 end end --call the update function timer.performWithDelay(1, update, -1)