I read your original question and I’m having trouble understanding what you want. So, I made a little demo. Is what I did (see video) similar to what you want? If not, how is it different?
Warning: Uses SSK2:
https://roaminggamer.github.io/RGDocs/pages/SSK2/
Code: https://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2020/06/airplane_movement.zip
Video:
io.output():setvbuf("no")
display.setStatusBar(display.HiddenStatusBar)
-- =====================================================
require "ssk2.loadSSK"
_G.ssk.init( { measure = false } )
-- =====================================================
local mRand = math.random
local physics = require "physics"
physics.start()
physics.setGravity(0,0)
-- physics.setDrawMode("hybrid")
-- Create a set of display groups to contain the different display objects in the 'game'
local layers = ssk.display.quickLayers( group, "underlay", "world", "gems", "content", "interfaces" )
-- Create a background image
local back = ssk.display.newImageRect( layers.underlay, centerX, centerY, "images/protoBackX.png",
{ w = 720, h = 1386, rotation = fullw>fullh and 90 })
-- My 'airplane' prototype, will move 'forward' continously and wrap to the opposite side of the screen when it gets there.
local player = ssk.display.newImageRect( layers.player, centerX, centerY, "images/arrow.png",
{ w = 40, h = 40, faceAngle = 0 }, { radius = 18 } )
local wrapProxy = ssk.display.newImageRect( layers.content, centerX, centerY, "images/fillT.png",
{ w = fullw + 80, h = fullh + 80 } )
function player.enterFrame( self )
ssk.actions.face( self, { angle = self.faceAngle, rate = 180 } )
ssk.actions.move.forward( self, { rate = 150 } )
ssk.actions.scene.rectWrap( self, wrapProxy )
end; listen( 'enterFrame', player )
-- Add touch listener to background that let's us 're-aim' player.
function back.touch( self, event )
--if( event.phase ~= 'began' ) then return false end
local vec = ssk.math2d.diff( player, event )
player.faceAngle = ssk.math2d.vector2Angle( vec )
return false
end; back:addEventListener( 'touch' )
-- Add score label
local scoreLabel = display.newText( layers.interfaces, "0", right - 150, top + 50, "Roboto-Light.ttf", 50 )
local score = 0
-- Add a spawner to create some 'gems'
local allGems = {}
local function spawnGem()
local gems = { 'blue.png', 'green.png', 'orange.png', 'pink.png', 'red.png', 'white.png', 'yellow.png' }
while( table.count(allGems) < 15 ) do
local function collision( self, event )
if( event.phase == "began" ) then
if( not event.other.isGem ) then
score = score + 1
scoreLabel.text = score
end
allGems[self] = nil
display.remove(self)
end
return false
end
local gem = ssk.display.newImageRect( layers.gems, mRand(left + 40, right - 40), mRand( top + 40, bottom - 40), "images/" .. gems[mRand(1,7)],
{ size = 40, collision = collision, isGem = true },
{ isSensor = true } )
allGems[gem] = gem
end
end
timer.performWithDelay( 30, spawnGem, -1 )