I’m having a weird glitch whenever I try to rotate my background. When I press either of my rotation buttons, it takes a second for the background to actually start rotating, but when it does, it rotates incredibly fast, and after a while of rotating, it disappears. Here’s the main code, minus what I’m using to rotate the background:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
display.setStatusBar(display.HiddenStatusBar)
local airSpeedPlayer = 5 – This determines the speed at which the background moves.
local leftTouched = false
local rightTouched = false – These are booleans used to determine whether a function should do something in particular.
local bkgFilter = { categoryBits = 1, maskBits = 0 }
local playerFilter = { categoryBits = 2, maskBits = 0 } – These collision filters prevent the Background from physically pushing or contacting the plane.
local bkg = display.newImage(“bkg.png”, true)
bkg.x = display.contentWidth / 2
bkg.y = display.contentHeight - (625 / 2)
bkg.alpha = 0.5 – Not strictly necessary.
physics.addBody ( bkg, { filter = bkgFilter } ) – This simplifies the matter of moving the background downwards to give the illusion that the plane is moving.
local plane = display.newImage(“plane.png”)
plane.x, plane.y = display.contentWidth / 2, display.contentHeight / 2
physics.addBody ( plane, { filter = playerFilter } )
local rightArrow = display.newImage(“rightArrow.png”) – This arrow is used to turn the background left, giving the impression of the plane turning right.
rightArrow.x = display.contentWidth - 38.5 – You can modify this depending on the graphic you use for the button.
rightArrow.y = display.contentHeight - 38 – You can modify this depending on the graphic you use for the button.
local leftArrow = display.newImage(“leftArrow.png”) – This arrow is used to turn the background right, giving the impression of the plane turning left.
leftArrow.x = 38.5 – You can modify this depending on the graphic you use for the button.
leftArrow.y = rightArrow.y
bkg:setLinearVelocity( 0, airSpeedPlayer ) – This gets the background moving downwards, giving the impression that the plane is moving.[/code]
Here’s the rotation code which comes after the rest:
[code]
local function leftRotate()
if leftTouched == true then
bkg:rotate( bkg.rotation + 0.000001 )
elseif leftTouched == false then return false
end
end
local function leftTouch(event)
if event.phase == “began” then
leftTouched = true
print ( leftTouched )
elseif event.phase == “ended” then
leftTouched = false
end
end
Runtime:addEventListener ( “enterFrame”, leftRotate )
leftArrow:addEventListener ( “touch”, leftTouch )
local function rightRotate()
if rightTouched == true then
bkg:rotate( bkg.rotation - 0.000001 )
elseif rightTouched == false then return false
end
end
local function rightTouch(event)
if event.phase == “began” then
rightTouched = true
elseif event.phase == “ended” then
rightTouched = false
end
end
Runtime:addEventListener ( “enterFrame”, rightRotate )
rightArrow:addEventListener ( “touch”, rightTouch )[/code]
Is there some other way of rotating the object, or better yet, can I modify the current rotation code to stop the glitch? [import]uid: 82408 topic_id: 27709 reply_id: 327709[/import]
[import]uid: 52491 topic_id: 27709 reply_id: 112503[/import]