A problem with zooming and actor position

Hi, I need to zoom in and out and the video posted by GSHelper at was perfect and works brilliantly - thank you!

However there is a problem: When I click on an actor (before zooming in/out) the 'pressed' trigger works, no problems. But when I zoom out and click on the (now smaller) actor the trigger doesn't get activated. If I click where the actor used to be (before the zoom) the trigger gets activated!

I'm using display size 480x320. When I zoom out the camera is increased to 960x640.

The actor starts at position x=122 and maintains this x value when zoomed out (because the actor hasn't actually moved, the camera has just got bigger) which is fine. But the game.mouse.position.x is still working on the premise that the screen is 480x320. The 'actor clicked' trigger appears to use the mouse.position.x value to determine if its been clicked and this is causing the bug.

How can I easily code round this given that my game will have lots of clickable actors?

Any help will be really appreciated!

Comments

  • philmphilm Member Posts: 8
    Hi guys, any ideas about this, still stuck with it!
  • philmphilm Member Posts: 8
    I've been looking in to this a bit more, I think this must be a bug in GameSalad. It appears that the 'Touch' functionality fails when the camera is zoomed out. Can any of the regulars here confirm this or know if this is a known issue?
  • slowcutslowcut Member, PRO Posts: 164
    I have never used some zoom tricks, but I can imaging, that the x and y position of your touches change with the zooming camera, put a Display Text behavior somewhere and let it show the x and y of your touch and your actors, I bet they are different then when zoomed in. Create some math to adjust the values to zoom in and zoom out
  • philmphilm Member Posts: 8
    Hi Slowcut, thanks for reply. That's pretty much what I did. The mouse coords are always in the range of the screen size (480x320), the fact that it's zoomed out isn't taken in to account. Unfortunately the actors 'Touch' functionality still uses these coords and therefore doesn't work correctly.

    This appears to be a major flaw in GameSalad.
  • 3itg3itg Member, PRO Posts: 382
    edited January 2014
    When Zoomed, Try diving the mouse coords by 2. fine tune from there.
    Or if I misunderstood, double the actors location values.

    If its a little more cryptic than that... Try changing display size values to the scene.camera size values instead.
    Hopefully that at least gets you closer to identifying the cause of the problem.

    It sounds as though one is getting calculated in local space (The Touch, in relation to the camera.), where the actors locations reside in global coordinates.
  • philmphilm Member Posts: 8
    Thanks for the suggestions 3itg. Doubling the actors location values would move the actor though wouldn't it. All my actors are static, they dont move at all.
    I think you're spot on with your last comment, the Touch is calculated in local space and completely ignores the fact that the actor resides in the global coords.

    It seems really strange to me that the Touch functionality is triggered in this way, surely it must relate to the actors actual location and not where the actor would be if the camera size=display size!! Crazy! This is basic stuff, it's not exactly advanced functionality.

    The only way I think I can work round this is if I do not use the Touch functionality at all, record all the actors locations in a table and code my own version of Touch when the mouse is clicked - this is ridiculous though.

    Got a feeling GameSalad just can't handle zooming, which is a shame.

    If any GS mods have any input that would be great, otherwise can anyone suggest another game creator that might be able to do this?

    Many thanks for the replies :)
  • 3itg3itg Member, PRO Posts: 382
    Math is hard sometimes, especially what you are getting into... but I think you can convert from local to global if you know the values of both.
    Something like Game.DisplaySize.X-Scene.Camera.Size.X?
    Let me think about a minute and see my brain can make math.
  • 3itg3itg Member, PRO Posts: 382
    edited January 2014
    I didnt follow that tutorial, so I have no idea what it says, but I built zoom in about 15 seconds like this...
    image

    I placed the button in the center of the screen, then clicked it, the scene switched to 2048x1536 with the button in the center.
    Click it again and it zooms back out.
    Is there more to this story that is making this not work?
  • colandercolander Member Posts: 1,610
    Create a test project showing your problem and someone will be able to figure it out for you. Don't forget to zip it before attaching it.
  • vafurlogivafurlogi Member, PRO Posts: 203
    I'm having the exact same problem. It's driving me crazy!
  • TouchiMediaTouchiMedia Member Posts: 154
    Use mouse button instead of touch, that's what I use.. Works fine even when I test on my ipad
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Try setting the Preview zoom level to 50% and see if that makes a difference. I've found that 100% zoom can sometimes cause Touch rules to behave oddly.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ashtmjashtmj Member, PRO Posts: 405
    keeping button in the same place and the same sizes while zooming in/out is REAL tricky!
    I've made a nice working pinch zoom with buttons that stay locked to the HUD, I'll try to clean it up a the project a bit/add info so others can make use of it :)



  • natzuurnatzuur Member Posts: 304
    edited January 2014
    @philm A (relatively) easy way to do this would be to create an attribute called zoom%.

    This will be your master controller for every aspect of zooming including the HUD.

    Obviously on each scene you need to access the Camera width and height for zoom, so if you plan on using this on more than one scene I would suggest creating a custom behavior for ease of copying the following logic into an unlocked actor.

    Camera controller actor:
    Constrain Scene.Camera.Width to 1024*Zoom%
    Constrain Scene.Camera.Height to 768*Zoom%

    (change the above static size values according to device)

    On another actor (does not need to be unlocked)

    Write logic to control the zoom with either
    a. interpolate zoom% to desired zoom
    b. timer change zoom% (actually smoother) to desired zoom

    Now finally on your hud elements:

    Constrain Self.Width to ( desired size)*zoom%
    Constrain Self.Height to ( desiredsize)*zoom%
    Constrain Self.Position.X to (desired Pos)*zoom%
    Constrain Self.Position.Y to (desired Pos)*zoom%

    Make sure the Camera controller actor is always above the actor doing the zooming in layers but below the UI elements and this should work for you! Let me know if you have questions.


    Edit: Oh Yeah, so in case you were wondering the zoom% nees to be a real attribute so basically .99 is 99% of camera size, or 1.1 is 110% camera size.
  • Screaming Goat AppsScreaming Goat Apps Member, PRO Posts: 10

    SOLVED
    Okay, after many days/hours of working on this issue I think I have it figured out. I would like to share my efforts with the community, since this forum has been such a great source of information for me. So here is my small contribution:

    To make sure we are all on the same page, what I figured out a solution for is the following: "When zooming in and out....The mouse/touch coords are always in the range of the camera screen size (480x320), the fact that it's zoomed out or in isn't taken in to account. Unfortunately the actors 'Touch' functionality still uses these coords and therefore doesn't work correctly".

    I am creating a game with multiple levels of zooming (using a zoom in, and a zoom out buttons) and I could not get the actors I wanted the player to move around on the screen when zoomed in or out to move to the locations the player would select. The player would click on the actor to move/drag the actor, and the actor would move all the way across the screen to the camera screen size X/Y, and not stay within the desired scene size X/Y. I found that the mouse and touch live within the camera size, whereas the actors on the scene lived within the scene X/Y. Thus when you would touch an actor, that are located at lets say scene value X 900 and Y 600, the actor would pop over to the whatever the camera X/Y value was when touched and display at that camera size X/Y coord value within the scene X/Y. All of that based on where the touch/mouse was located within the camera size viewing area (so of instead of the actor being at the desired X900 and Y 600, the actor pops over to ~ X 300 and ~ Y 200). Hopefully that all makes sense and I explained the problem making using zoom difficult. It was all bad and I thought my game concept was dead in the water.

    So here is what I did to work around this issue:

    1) I created an actor named "follow mouse actor" (I made it's size small, 10 x 10 pixels)
    2) I then created two game level integer attributes, one named "touch moverX", and "touch moverY".
    3) I placed the "follow mouse actor" on the scene, and unlocked it.
    4) For the "follow mouse actor" under its instance I then:
    constrained the self.position.x to game.Touches.Touch 1.x
    constrained the self.position.y to game.Touches.Touch 1.y
    constrained the game.touch moverX to: scene.camera.orgin.x + self.position.x
    constrained the game.touch moverY to: scene.camera.orgin.x + self.position.y
    5) I then created an actor that I would like the player to move around on the scene when touched/dragged. I just named it "Actor 1", you can name it whatever you want.
    6) I created a rule for Actor 1:
    If touch is pressed then do:
    constrain self.position.x to game.touch moverX
    constrain self.position.y to game.touch moverY

    That is it, very simple, but difficult for me to get my head wrapped around at first and come up with a solution. The idea is that the origin of the camera always follows the value of the scene size. So by adding that with the actors within camera X and Y position would result in its real position/location on the screen as perceived by the game player. I set this up, and it is working great. For the "follow me actor" in step four above, I also tried using the mouse position x and y instead of touch, and it worked great as well. So if you need to use mouse position instead of touch, it also works.

    Hopefully this helps someone. If there is a better way to do this I am all ears.

    Cheers!
    David

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @dbratley66 -- Great idea! Thanks for sharing your solution with the community!

Sign In or Register to comment.