How do I display constant x and y coordinates of an object

I am having difficulty being able to access the constant x and (especially) y coordinates of the jet image I created. I added a force to this image that makes the jet go higher anytime i touch the screen. I want to know the immediate y values at any time so i can make another object follow it constantly but any time i try to set the new object to the jet coordinate variables, I only get the original x and y value (80,100). For example if i say

newYValue = jet.y, all i get is the original Y value no matter where the jet is in reality. PLEASE help me with this, Ive been working on it for hours upon hours. Here’s my code, thanks a lot.

local physics = require "physics" physics.start() physics.setGravity(0,8) jet= display.newImage ("redJet.png")     jet.x = 80     jet.y =100     physics.addBody (jet, "dynamic", {density = .1, bounce=.1, friction=.2,radius=10})      function activateJets (self, event) self:applyForce (0, -1.5, self.x, self.y)      end function touchScreen (event)     if event.phase == "began" then                  jet.enterFrame = activateJets         Runtime:addEventListener("enterFrame", jet)              end          if event.phase == "ended" then          Runtime:removeEventListener("enterFrame", jet)     end end Runtime:addEventListener("touch", touchScreen)

Take a look through this code and see if it helps.

[lua]

local physics = require “physics”
physics.start()
physics.setGravity(0,8)

local jet= display.newImage (“redJet.png”)
jet.x = 80
jet.y =100
physics.addBody (jet, “dynamic”, {density = .1, bounce=.1, friction=.2,radius=10})

–rectangle that will follow plane
local follower = display.newRect( 0, 0, 40, 40 )

local jetsActive = false

local function onEnterFrame( event )
 if jetsActive then
  jet:applyForce (0, -1.5, jet.x, jet.y)
 end

 follower.x = jet.x
 follower.y = jet.y
end

function touchScreen (event)
 if event.phase == “began” then
  jetsActive = true
 elseif event.phase == “ended” or event.phase == “cancelled” then
  jetsActive = false
 end
end

Runtime:addEventListener(“enterFrame”, onEnterFrame)
Runtime:addEventListener(“touch”, touchScreen)
[/lua]

Best of luck.

Hi @benyemi.  You have a duplicate post in another forum.  I wanted to let you know, per forum rules, we request that you don’t post the same question in multiple places or repeatedly.  Since you are getting responses here, I’ve deleted the other one.

Rob

thanks a lot. I’ll definitely try it out, it looks like it’ll work. thanks again

Take a look through this code and see if it helps.

[lua]

local physics = require “physics”
physics.start()
physics.setGravity(0,8)

local jet= display.newImage (“redJet.png”)
jet.x = 80
jet.y =100
physics.addBody (jet, “dynamic”, {density = .1, bounce=.1, friction=.2,radius=10})

–rectangle that will follow plane
local follower = display.newRect( 0, 0, 40, 40 )

local jetsActive = false

local function onEnterFrame( event )
 if jetsActive then
  jet:applyForce (0, -1.5, jet.x, jet.y)
 end

 follower.x = jet.x
 follower.y = jet.y
end

function touchScreen (event)
 if event.phase == “began” then
  jetsActive = true
 elseif event.phase == “ended” or event.phase == “cancelled” then
  jetsActive = false
 end
end

Runtime:addEventListener(“enterFrame”, onEnterFrame)
Runtime:addEventListener(“touch”, touchScreen)
[/lua]

Best of luck.

Hi @benyemi.  You have a duplicate post in another forum.  I wanted to let you know, per forum rules, we request that you don’t post the same question in multiple places or repeatedly.  Since you are getting responses here, I’ve deleted the other one.

Rob

thanks a lot. I’ll definitely try it out, it looks like it’ll work. thanks again