At the top of your file, write,
local xWidth = display.actualContentWidth local yHeight = display.actualContentHeight
At the top of your file, write,
local xWidth = display.actualContentWidth local yHeight = display.actualContentHeight
I’m still getting the same error .
top of the file :
local bg1 local bg2 local xWidth = display.actualContentWidth local yHeight = display.actualContentHeight
rest of the code :
bg1 = display.newImageRect("background2.jpg", xWidth, yHeight) bg1.x = 1000 bg1.y = yHeight bg2 = display.newImageRect("background32.jpg", xWidth, yHeight) bg2.x = xmid bg2.y = ymid - display.actualContentHeight scroll = 2 local function bgScroll (event) bg1.y = bg1.y + scroll bg2.y = bg2.y + scroll if bg1.y == display.actualContentHeight \* 1.5 then bg1.y = display.actualContentHeight \* -.5 end if bg2.y == display.actualContentHeight \* 1.5 then bg2.y = display.actualContentHeight \* -.5 end end
Try putting 1000, and 300, or other numbers, where it says xWidth and yHeight, on line 85.
That didn’t change anything
There appears to be some scope issues here. Shouldn’t you be creating your background and so forth in the proper Composer scene blocks, not outside of them?
Brent
I have this code :
function scene:create(event) local screenGroup = self.view brick = display.newImage("graphics/stones.png") brick.x = 260 brick.y = 210 brick:scale( 0.4, 0.5 ) screenGroup:insert(brick) bg1 = display.newImageRect("graphics/background2.jpg", xWidth, yHeight) bg1.x = 1 bg1.y = 3 screenGroup:insert(bg1) bg2 = display.newImageRect("graphics/background32.jpg", xWidth, yHeight) bg2.x = xmid bg2.y = ymid - display.actualContentHeight screenGroup:insert(bg2) display.setDefault("fillColor", 0, 1, 1) CreateWalls(1) end scroll = 2 local function bgScroll (event) bg1.y = bg1.y + scroll bg2.y = bg2.y + scroll if bg1.y == display.actualContentHeight \* 1.5 then bg1.y = display.actualContentHeight \* -.5 end if bg2.y == display.actualContentHeight \* 1.5 then bg2.y = display.actualContentHeight \* -.5 end end
And now I’m getting this error :
attempt to perform arithmetic on global 'ymid' (a nil value)
When the scene starts , I could see the background but half of it is on the screen and the other half is off .
Again, ymid does not exist. you have to define it.
I did this and the same error is occurring :
-- requires local composer = require( "composer" ) local scene = composer.newScene() local physics = require("physics") physics.start() physics.setGravity(0,9.8) local bg1 local bg2 local xWidth = display.actualContentWidth local yHeight = display.actualContentHeight -- background function scene:create(event) local screenGroup = self.view brick = display.newImage("graphics/stones.png") brick.x = 260 brick.y = 210 brick:scale( 0.4, 0.5 ) screenGroup:insert(brick) bg1 = display.newImageRect("graphics/background2.jpg", xWidth, yHeight) bg1.x = 1 bg1.y = 3 screenGroup:insert(bg1) bg2 = display.newImageRect("graphics/background32.jpg", xWidth, yHeight) bg2.x = xmid bg2.y = ymid - display.actualContentHeight screenGroup:insert(bg2) display.setDefault("fillColor", 0, 1, 1) CreateWalls(1) end
Did you define the variable ymid? Also, please tell us on what line the error is pointing to.
Seems to be a lot of code written or pasted from elsewhere, but not tested.
Start from scratch, think about the small steps you need to go through to reach the bigger goal. At the moment you’re just running around chasing your tail, trying to catch a lucky break - it might fix it, but you might not understand why.
Write a line towards each small step, test, write another line, test. If you don’t understand the flow and dependencies of your own program, it’s difficult to make sure the computer does.
Yeah, what @nick_sherman said. It seems to me that you need to go right back to basics. Follow the getting started tutorials. Read them. If you don’t understand a bit then re-read it. Try the code it tells you and make sure that you understand what it is doing before moving on to the next bit. If you get an error then read what it says and look at the line of code mentioned. A lot of errors are down to scope (if you don’t understand scope or know what it is then there’s a very good post by Rob Miracle about it which I would advise reading and bookmarking). If you really can’t figure out what the cause is then by all means post here, but don’t just tell us there’s an error and expect us to fix it for you as you’ll never learn anything that way. Tell us the error, what you’ve tried doing to fix it, and what happened when you did.
When you do get bits working then try changing something to see what difference it makes and think about why it made that difference.
Looking back at your posting history it appears (to me at least) that you’re just blindly copying code from somewhere and expecting it to work and then immediately posting here when it doesn’t. Don’t forget that most of the people here also have jobs and our time is valuable.