Spawn actor on touch issue. Please help!

I'm making a simple block stacking game that spawns a new block when and where you touch the screen. I have a tall scene with a touch area actor that is stretched from the bottom to the top. Everything works great until the blocks reach the top of the initial screen and my camera control actor moves to its second position. Here is where the problem is occurring. After the camera moves to its second position when I touch the screen the block actor no longer spawns where I touched. Instead it spawns way below where I touched.
please, any help is appreciated. Thanks!

Comments

  • SummationSummation Member, PRO Posts: 476

    @8bitninja said:
    I'm making a simple block stacking game that spawns a new block when and where you touch the screen. I have a tall scene with a touch area actor that is stretched from the bottom to the top. Everything works great until the blocks reach the top of the initial screen and my camera control actor moves to its second position. Here is where the problem is occurring. After the camera moves to its second position when I touch the screen the block actor no longer spawns where I touched. Instead it spawns way below where I touched.
    please, any help is appreciated. Thanks!

    You can divide your viewable camera locations into regions so that when the camera goes into the second one, you can let the game know (maybe set an attribute like game.whichcamera to 2) to adjust your spawns.

  • ArmellineArmelline Member, PRO Posts: 5,415

    Touch will always be calculated by the position on the screen of your device.

    Spawns will happen relative to the scene as a whole.

    If you move your camera, these two things go out of sync.

    To avoid this problem, calculate how much the camera has moved by and add (or subtract) that from the touch location.

    E.g. Camera has moved up 200px, spawn at touch.y+200

  • LovejoyLovejoy Member Posts: 2,078

    You need to take into account the camera's origin. So do

    game.Touches.Touch 1.Y + scene.Camera.Origin.Y

  • 8bitninja8bitninja Member Posts: 367
    edited May 2015

    @Summation @Armelline thanks guys, that totally makes sense.

  • 8bitninja8bitninja Member Posts: 367

    Awesome, @Lovejoy that sounds somewhat easier, I'll give it a try. Thanks you guys!

  • 8bitninja8bitninja Member Posts: 367

    @Lovejoy Thanks again, it worked perfectly!

  • LovejoyLovejoy Member Posts: 2,078

    @8bitninja said:
    Lovejoy Thanks again, it worked perfectly!

    Np

Sign In or Register to comment.