Sprite not working on device but is on the simulator

My game works perfectly fine in the Corona simulator.  However, I uploaded my app to my iPhone.  Everything works great, EXCEPT my sprite doesn’t play!! I need help guys! I have tried going to the console for my device and receive NO ERRORS! Any help or further instruction is appreciated! thanks! Code file that contains the sprite is below…

[lua] --game.lua

–remove status bar

display.setStatusBar(display.HiddenStatusBar)

–declare modules

local storyboard = require “storyboard”

local scene = storyboard.newScene()

local physics = require “physics”

physics.start()

physics.setGravity( 0, 100)

local stage = display.currentStage

local levelSpeed = 5

local gameIsActive = false

local saveValue = function( strFilename, strValue)

–specified value to specified file

local theFile = strFilename

local theValue = strValue

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “w+” )

if file then

–write game distance to the text file

file:write( theValue )

io.close( file )

end

end

local loadValue = function( strFilename )

–will load specified file, or create a new file if it doesn’t exist

local theFile = strFilename

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “r” )

if file then

–read ALL contents of file into a string 

local contents = file:read( “*a” )

io.close( file )

return contents

else

–create file because it doesn’t exist yet

file = io.open( path, “w” )

file:write( “0” )

io.close( file )

return “0”

end

end

–create scene

function scene:createScene( event )

local group = self.view

local highDistanceFilename = “highDistance.text”

local loadedHighDistance = 

loadValue( highDistanceFilename )

local highScore = tonumber( loadedHighDistance )

local celebrityChoiceFilename = “celebrityChoice.text”

local loadedCelebrityChoice = 

loadValue( celebrityChoiceFilename )

local celebrityChoice = tostring( loadedCelebrityChoice ) 

–sprite information

local sheetData = {

width = 65,

height = 70,

numFrames = 4,

sheetContentWidth = 260,

sheetContentHeight = 70,

}

local celebrity = graphics.newImageSheet( “”…tostring(celebrityChoice), sheetData )

local sequenceData = {

{ name = “celebrityRun”,

frames = { 1,2,3,4},

time = 400,

loopCount = 1000000000000000000000000000000000000000000000000

}

}

–make sky background

local bg = display.newRect( 250, 100, 1220, 840)

bg:setFillColor(0,0,255)

group:insert(bg)

–makes celebrity run animation

local celebrityRun = display.newSprite( celebrity, sequenceData )

celebrityRun.x = -10

celebrityRun.y = 270

physics.addBody(celebrityRun, “dynamic”, {friction = 0,bounce = 0})

celebrityRun:play()

celebrityRun.isFixedRotation = true --To stop it rotating when jumping etc

celebrityRun.isSleepingAllowed = false --To force it to update and fall off playforms correctly

–celebrity jump

local function celebrityJump( event )

if (event.numTaps == 1) then

celebrityRun.y = celebrityRun.y - 150

elseif(event.numTaps > 1) then

celebrityRun.y = celebrityRun.y - 200

return(true)

end

end

Runtime:addEventListener(“tap”, celebrityJump)

–first level

local firstLevel = display.newRect(165, 315, 1220, 10)

firstLevel:setFillColor(255, 0, 0)

physics.addBody( firstLevel, “static”, {friction = 0, density = 1, bounce = 0})

group:insert(firstLevel)

–levels

local secondLevel1 = display.newRect(220, 190, 100, 10)

secondLevel1:setFillColor(255, 0, 0)

local secondLevel2 = display.newRect(450, 190, 100, 10)

secondLevel2:setFillColor(255, 0, 0)

physics.addBody(secondLevel1, “static”, {friction = 0, density = 1, bounce = 0})

physics.addBody(secondLevel2, “static”, {friction = 0, density = 1, bounce = 0})

local thirdLevel1 = display.newRect(260, 100, 80, 10)

thirdLevel1:setFillColor(255, 0, 0)

local thirdLevel2 = display.newRect(490, 100, 80, 10)

thirdLevel2:setFillColor(255, 0, 0)

physics.addBody(thirdLevel1, “static”, {friction = 0, density = 1, bounce = 0})

physics.addBody(thirdLevel2, “static”, {friction = 0, density = 1, bounce = 0})

group:insert(secondLevel1)

group:insert(secondLevel2)

group:insert(thirdLevel1)

group:insert(thirdLevel2)

–paparazzi1

local paparazzi1 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi1.x = 800

paparazzi1.y = 283

physics.addBody(paparazzi1, “static”, {friction = 0, density = 0, bounce = 0})

group:insert(paparazzi1)

–paparazzi2

local paparazzi2 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi2.x = math.random(350, display.contentWidth)

paparazzi2.y = 160

physics.addBody(paparazzi2, “static”, {friction = 0, density = 0, bounce = 0})

group:insert(paparazzi2)

–paparazzi3

local paparazzi3 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi3.x = math.random(450, display.contentWidth)

paparazzi3.y = 70

physics.addBody(paparazzi3, “static”, {friction = 0, density = 0, bounce = 0})

group:insert(paparazzi3)

–wall to prevent character from being pushed off screen (left)

local wall = display.newRect(-45, 100, 5, 500)

physics.addBody(wall, “static”, {friction = 0, density = 1})

wall.alpha = 0

group:insert(wall)

–current distance

local currentDistance = 0

–distance score

local distanceText = display.newText("Distance: ", 245, 20, “Arial”, 30) 

group:insert(distanceText)

local objectGroup = display.newGroup()

–Main gameLoop function

function gameLoop( event )

if (gameIsActive == true) then

currentDistance = currentDistance + 1

distanceText.text = "Distance: "…currentDistance

–Move the other items and platforms. 

–If they are far left of the screen we remove them.

local i

for i = objectGroup.numChildren,1,-1 do

local object = objectGroup[i]

if object ~= nil and object.y ~= nil then

object:translate( -levelSpeed, 0)

if object.x < -175 then 

display.remove(object); object = nil;

end

end

end

–Move the background, ground, and levels

–We then check to see if they need to be replaced.

bg:translate(-(levelSpeed)*0.6,0)

secondLevel1:translate(-levelSpeed,0)

secondLevel2:translate(-levelSpeed,0)

thirdLevel1:translate(-levelSpeed,0)

thirdLevel2:translate(-levelSpeed,0)

paparazzi1:translate(-levelSpeed, 0)

paparazzi2:translate(-levelSpeed, 0)

paparazzi3:translate(-levelSpeed, 0)

if secondLevel1.x <= -100 then

secondLevel1.x = secondLevel1.x + 600 

end

if secondLevel2.x <= -100 then

secondLevel2.x = secondLevel2.x + 600 

end

if thirdLevel1.x <= -100 then

thirdLevel1.x = thirdLevel1.x + 600 

end

if thirdLevel2.x <= -100 then

thirdLevel2.x = thirdLevel2.x + 600 

end

if paparazzi1.x <= -75 then

paparazzi1.x = math.random(600,1000) 

end

if paparazzi2.x <= -75 then

paparazzi2.x = math.random(900,2000) 

end

if paparazzi3.x <= -75 then

paparazzi3.x = math.random(1000,1500) 

end

if bg.x <= -50 then bg.x = bg.x + 400 

end

end

end

gameIsActive = true

Runtime:addEventListener(“enterFrame”,gameLoop)

–make speed of game faster

function speedBoost( event )

if (currentDistance  >= 200) then

levelSpeed = 6

end

if (currentDistance  >= 450) then

levelSpeed = 8

end

if (currentDistance  >= 700) then

levelSpeed = 10

end

if (currentDistance  >= 1100) then

levelSpeed = 12

end

end

Runtime:addEventListener(“enterFrame”, speedBoost)

–collided

function gameOver()

storyboard.gotoScene(“gameover”, “fade”, 200)–go to game over scene

print(“go to scene gameover completed!”)

end

–paparazzi collision

local function onCollision(event)

if (event.phase == “began”) then

print(“collision began”)

levelSpeed = 0

celebrityRun.alpha = 0

paparazzi1:removeEventListener(“collision”, onCollision)

paparazzi2:removeEventListener(“collision”, onCollision)

paparazzi3:removeEventListener(“collision”, onCollision)

gameOver()

print(highScore)

print(currentDistance)

if currentDistance > highScore then

highScore = currentDistance

local highDistanceFilename = “highDistance.text”

saveValue( highDistanceFilename, tostring(highScore))

end

end

end 

paparazzi1:addEventListener(“collision”, onCollision)

paparazzi2:addEventListener(“collision”, onCollision)

paparazzi3:addEventListener(“collision”, onCollision)

end

–enter scene

function scene:enterScene( event )

local group = self.view

physics.start()

physics.setGravity( 0, 100)

end

–exit scene

function scene:exitScene( event )

local group = self.view

Runtime:removeEventListener(“tap”, celebrityJump)

Runtime:removeEventListener(“enterFrame”, speedBoost)

Runtime:removeEventListener(“enterFrame”,gameLoop)

end

–destroy scene

function scene:destroyScene( event )

local group = self.view

end

scene:addEventListener( “createScene”, scene)

scene:addEventListener( “enterScene”, scene)

scene:addEventListener( “exitScene”, scene)

scene:addEventListener( “destroyScene”, scene)

return scene [/lua] 

Check the case and spelling of all assets carefully.

99% of the time when it ‘works fine in the simulator’ and ‘fails on the device’, it is because you got the case wrong on a file name.

The simulators (because they run in OS X and Windows) are not case-sensitive, but the the device builds running on iOS and Android operating systems are.

@roaminggamer , I checked every single file’s spelling and caps… nothing is wrong… I checked extremely carefully. I even made another build of the app.  When I uploaded it to Test Flight, still no luck with the sprites moving :frowning:

Any other suggestions?

Two suggestions (in order)

Suggestion One

  1. Download this file: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/01/caseDetectError.zip 

  2. Copy the file caseErrorDetect.lua into your game folder (same place as main.lua)

  3. Add these lines to the VERY TOP of main.lua:

    local ced = require “caseErrorDetect” ced.promoteToError()

  4. Re-run the game in the simulator and play around for a while to ‘test’ all is good.  If any errors pop-up, correct them then re-try building.

Suggestion Two

I appreciate that you’ve posted your code and I did peruse it, but this is one of those things where one needs to see the project.  So, if you’d be willing to post a link to your project (in a ZIP file), I will take a look at it some time today.

I still think this is an issue with case, file name spelling, or assumptions about how paths work, but I can only verify my suspicions with an actual project.

-Ed

One last thing.  Why are you using ‘storyboard’?  When you get the chance, you should switch to ‘composer’.  Storyboard is end-of-life.

@roaminggamer , i followed your instructions and have implemented your file into my game folder.  I have also added the code to the top of my manilla file… I have an error but i have no idea how to solve it!  Please help! Below is the .zip file for my entire project!  Thanks!

Here is my project .zip:

Hi.  I tested this on:

  • OS X 10.10.2 Simulator (Corona 2015.2605) 
  • iOS 8.2 iPad Air  (Corona 2015.2605)
  • Windows 7  Simulator (Corona 2015.2625)
  • Android 4.4 Nexus 7 Gen 1(Corona 2015.2625)

It worked with no issues in each case.

So, you’re either using an OLD version of Corona with bugs, OR you’ve got something else going on.

Which version of Corona are you using.

Also, you said you have an error?  What was the error message.

First try using the latest Corona if you’re not.

Can you provide me a link to the latest version download?

There is a ‘daily builds’ link at the top of the page.

Just installed latest version of corona.  Trying to rebuild app now  The error is: : ***** WARNING! require( ‘CoronaLibrary’ ) - does not exit.  Check case of file.  

Please tell us this:

  1. OS X Version you’re using: OX X aa.bb.c

  2. Where are you seeing the above error?  In the simulator, or on the device?

  3. If on the device, what device, what version of iOS 

  4. Are you able to run and build any of the samples that come with Corona?

  5. Where are you storing the folder containing your project.  I suggest you NOT store it in the applications or other folder.  It should live in a project folder on your drive or on your desktop if that is easy for you.  Definitely, do not put it in the Corona app folder.

  6. Have you tried re-booting since the install?  Not really necessary, but can’t hurt.

  7. I may think of other questions later. I know this is probably frustrating, but we (I) need more details to help figure this out.  You project worked fine for me with all the above combinations of Corona and OS, so I suspect something is wrong with your system setup if you can’t run Corona.  However, I don’t have enough data to figure out what is happening now.

Wait a second…  Did  you  mean:

  1. I’m installing the newest version of Corona now and will try it shortly.

  2. The error I mentioned before was, “***** WARNING! re…”  Is implies you’re still seeing an error.

Please clarify.  Meanwhile, I’ll assume this is resolved.

This is whats going on…

1.) My corona version is Version 2015.2625 (2015.4.23).  

2.) My game runs fine an ALL DEVICES IN THE SIMULATOR

3.) I am then building the app using my provisioning file and the build and application loader works 100% fine with NO errors

4.) when the app is tested in the test flight application, the gameplay works fine, BUT THE SPRITES DONT WORK!

I see the error in my last response using the iPhone 5 on the corona simulator.  The error is shown in terminal in the debugging log.  NO ERROR IS SHOWN ON DEVICE AT ALL!  The folder for my game is on the desktop. 

  1. Version - Good.  That should be fine.

  2. Devices - Testing on your target simulated device is enough for this.  All devices use the same simulator (+/-) a few flags.  The real benefit of the simulators is a quick test of various known resolutions.

  3. Application Loader - Are you using an old version of OS X (you didn’t say which, but had assumed Yosemite.)?  Old versions had an app called the application loader.  You don’t want to use that to upload the binary to your device.  (ONLY use xCode for this.)

  4. Here is a video of the game on my iPad.  Does this look right?  (Maybe I’ve made an assumption here that what I’m seeing is correct.  If something is missing in the video please tell me specifically what I should be seeing that is not there.) 

Click here for video if it doesn’t show.

  1. Two part answer:

Part 1

A. Un-register Corona on your computer.

B. Completely uninstall it.

C. Reboot.

D. Re-install Corona

E. Load “Horse Animation” sample that comes with Corona installation.

F. Build it and install it on your device.

G. Verify it works.  

If you get this far, then your environment, Corona install, and certificates are probably good.  If not, you’ve got some other problem. 

Part 2

When you say no errors on the device at all, did you look at the xCode console?   (See video above.  I mention this there).  (the video was made for another forums question, but is still relevant)

PS - I’m having trouble getting my posts to work due to some unknown issue so bear with me as I re-edit my posts to get them working.

You need to attach your device to your Mac and use Xcode to see messages on the device. Please read"

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

@roaminggamer the video you created is right, EXCEPT the characters SHOULD BE MOVING IN A RUNNING MOTION.  The sprites should be running, not frozen.  

@rob I connected my device to my mac as you said… I then went to the debugging console in Xcode while playing the game like you said…  I got ZERO errors! Everything in the console was normal…  I am clueless as to why my sprites aren’t working on a real device! They work perfectly fine on the simulator! HELP!

  1. You’re using GIFs.  You need to use PNG for this.  In general only use JPG or PNG files.

  2. This code is wrong:

    loopCount = 1000000000000000000000000000000000000000000000000

It does produce an warning message:

WARNING: The 'loopCount' value(-2147483648) cannot be negative.

If you want an infinite loop do this:

loopCount = 0 -- loop forever
  1. I suggest creating reasonable names for your assets.  The names you have are very hard to read and debug.  Nice short meaningful names are better.

  2. This is not running in the simulator (Windows) either.  

  3. Please limit the use of ALL CAPS in forums posts and titles.  It implies shouting or frustration.  If you’re frustrated, say so, we’ll understand.  If you want to draw the eye to something, make it bold or underline it or both.

I tested some fixes, and

  1. once you convert the sprite source images to PNG and,

  2. fix the loop count you should be in better shape.  

However, your menu images will need to be cleaned up (remove black background.)

One final note.  I pointed out some things in prior posts that would help to debug this issue, but failed to direct you here:

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

The above link will take you to a blog post where I talk about asking questions and how to provide better details to those you’re asking for help.  It may help you in the future to try to follow some of the discussed suggestions.

Good luck with your game.