Move image on screen based on position of device

Hello,

I’m not sure if this is possible to do exactly so I’m posting it here and will pay someone to write if it can be done.

What I want to do is place an image in the app such as a ball. Then when you move the device around I want the ball to move as if it went off the screen but appear back when you point the device back to the same position. For example, say you are standing north exactly and holding the device vertical. An image of a ball could be in the top right of the screen kind of like the sun. Now if you turn your self to the left and point west then the app will move off the screen to the right. If I turn to the right again, the image will appear back on the screen in the same position when I am facing north again.

So I want an image to show up on the screen and move off based on my position. It would be nice if I could have the image move up and down if I lean forward or backward. You should get the idea now. I’ve tried all different ways and I can’t get it. But someone else might can in 15 minutes. Who knows.

So let me know if you can do this. You can reply here but a private message would work best. I really need it for iOS.

Thanks,

Warren

Can anyone do this? Is it possible?

As far as the having the ball always onscreen when facing North, and sliding it off to the left/right as you turn — yep, entirely possible and easy – start out with the compass sample app – it basically does just that.

Runtime:addEventListener( “heading”, updateCompass

It gets a bit trickier if you want to overlay/show game objects overlayed on a camera view at real world locations (augmented reality –  like objects read from a db, to be overlayed at a real gps location on a cameraview, for instance).

Thanks for the reply. Actually at this point I’m just looking for a way to get a value for the direction the device is facing such as from the compass. But I did not know if the compass would work for this because I am holding the device vertical rather than flat. I tried the app on my phone and actually the degrees did change as I turned with holding the phone vertical. I’ll play with that and see how it goes.

Do you know what I would use to determine the tilting forward and backward to get that value? I greatly appreciate your help!

Warren

Haven’t used it, but it looks like it’s the Runtime:addEventListener( “accelerometer”, onAccelerate )

https://docs.coronalabs.com/api/event/accelerometer/index.html

Looks like maybe the yGravity param is the one that changes as you tilt front/back… Best of luck!

Can anyone do this? Is it possible?

As far as the having the ball always onscreen when facing North, and sliding it off to the left/right as you turn — yep, entirely possible and easy – start out with the compass sample app – it basically does just that.

Runtime:addEventListener( “heading”, updateCompass

It gets a bit trickier if you want to overlay/show game objects overlayed on a camera view at real world locations (augmented reality –  like objects read from a db, to be overlayed at a real gps location on a cameraview, for instance).

Thanks for the reply. Actually at this point I’m just looking for a way to get a value for the direction the device is facing such as from the compass. But I did not know if the compass would work for this because I am holding the device vertical rather than flat. I tried the app on my phone and actually the degrees did change as I turned with holding the phone vertical. I’ll play with that and see how it goes.

Do you know what I would use to determine the tilting forward and backward to get that value? I greatly appreciate your help!

Warren

Haven’t used it, but it looks like it’s the Runtime:addEventListener( “accelerometer”, onAccelerate )

https://docs.coronalabs.com/api/event/accelerometer/index.html

Looks like maybe the yGravity param is the one that changes as you tilt front/back… Best of luck!