I understand I recently made a post similar to this, wherein I was trying to rotate the background instead of the plane. However, I changed my code drastically because I realized I was making the code really awkward by rotating/moving the background instead of doing the same thing to the plane and having the screen follow it.
What I want is to be able to rotate the plane using my left and right buttons and have the screen kinda rotate with it. I have the screen following the plane in x and y coordinates, but I need it to rotate with it as well. Here’s my main code:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
display.setStatusBar(display.HiddenStatusBar)
local physicsData = (require “shapedefs”).physicsData(1.0) – Enables special physics shapes for objects.
system.activate( “multitouch” )
local airSpeedPlayer = 5 – This determines the speed at which the player moves.
local turnSpeedPlayer = 0.001 – This determines the speed at which the player turns.
local game = display.newGroup( ) – This group is used to ‘scroll’ the screen.
game.x, game.y = 0, 0
local leftTouched = true – These are booleans used to determine whether
local rightTouched = false – one of the buttons is being touched or not.
local playerIsAlive = true – This determines if the player is ‘alive’ or not.
local bkg = display.newImage(“bkg.png”, true)
bkg.x = display.contentWidth / 2
bkg.y = display.contentHeight - (625 / 2) – The exact numbers here are optional; they ensure that the background is positioned so that the bottom of the image is touching the bottom of the screen.
bkg.alpha = 0.5 – Not strictly necessary.
game:insert( bkg )
local plane = display.newImage(“plane.png”)
plane.x, plane.y = display.contentWidth / 2, display.contentHeight / 2
physics.addBody ( plane, physicsData:get(“plane”) )
plane.isSleepingAllowed = false – Keeps the plane from falling asleep.
game:insert( plane )
plane:setLinearVelocity( 0, -airSpeedPlayer ) – Gets the plane moving.
local rightArrow = display.newImage(“rightArrow.png”) – This arrow is used to turn the player left.
rightArrow.x = display.contentWidth - 38.5
rightArrow.y = display.contentHeight - 38
local leftArrow = display.newImage(“leftArrow.png”) – This arrow is used to turn the player right.
leftArrow.x = 38.5
leftArrow.y = rightArrow.y
local function moveCamera() – This function is used to ‘scroll’ the screen.
if playerIsAlive == true then – By determining if the player is ‘alive’ or not, a fatal error can be prevented when/if the player’s plane is removed.
game.x = -(plane.x - 160)
game.y = -(plane.y - 240)
end
end
Runtime:addEventListener ( “enterFrame”, moveCamera )
physics.setDrawMode( “normal” )[/code]
Thank you in advance. [import]uid: 82408 topic_id: 27992 reply_id: 327992[/import]