how do i drag the camera around?

jmp909jmp909 Member Posts: 73
edited November -1 in Working with GS (Mac)
hi I want to have a scene that's say 1024x1024, with a camera that's phone screen size ie 480x320

how do i make it so i can drag the camera around with my finger? (the user has to find something on the larger 1024x1024 area by moving the camera around it..so eg there's one actor (32x32) sitting on the large (1024x1024) background somewhere). Obviously it'll need to respect the boundaries of the scene as well so you can't drag past the edge of the image.

note preferably i want the user to have to drag, pick their finger up and drag again, like you would with a laptop mousepad to get across a large area, rather than for example the camera scrolling if their finger is near the corner of the screen

it might be good to have some easing on the dragging though if possible

i didnt want to have to make the actors move rather than the camera, as i'd potentially have to move a lot of them all at once... that's why it is better to just move the camera and keep the actors essentially static

thanks
j

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    I would play around with something like this:

    Actor prototypes do NOT have access to the camera, but Actor Instances in the Scene DO have access to the camera.

    Make a new Actor called something like CameraController. Just a simple box will work. Don't put any code in the prototype. Drag the CameraController into the Scene and place it just outside of view.

    Double-click on it to open its properties and click on the padlock to access its behaviors. This actor now has access to the Camera data. Specifically the Camera.Origin.X and Y (which are the lower left coords of the viewing area at all times.

    You could try Constraining those coordinates to your Touch X and Y with an offset when you touch the screen.

    ---

    Another option is to use the Control Camera behavior on an Actor. When you touch the screen, spawn an actor with that behavior in it. When you release, destroy the actor.
  • jmp909jmp909 Member Posts: 73
    thanks will have a look at that, but any suggestions on what sizes to set the tracker and the camera tracking area?

    also the dragging needs to move the camera in the opposite direction doesnt it.... ie if i drag my finger from right to left, the camera needs to move right (because i'm dragging the camera, not the background actor)

    also i wont want to move the camera until the user starts dragging, not when they first touch it

    j
  • firemaplegamesfiremaplegames Member Posts: 3,211
    so you can move around those tracker "bars".

    When an object that controls the camera "pushes" one those bars, that's when the camera starts to follow them.

    Bringing those bars all the way in would mean that the Camera is always locked on the Actor. If the tracking area is bigger, the camera will only pan across the screen when you drag near the edges. I would play around with it, but I don' think you will want them all the way in, it is a little jerky.

    I BELIEVE that the size of the tracker doesn't matter, as it is just looking at the center point. I could be wrong. I would make the tracker smallish, 40x40? and invisible of course.
  • jmp909jmp909 Member Posts: 73
    i just updated my post above with some extra information. i think it's a bit more complicated than that :S
  • firemaplegamesfiremaplegames Member Posts: 3,211
    There's only two ways to control the camera, either by directly controlling the camera origin or with an actor that has a Control Camera behavior.

    Here's an example of how to move a camera around Google Maps style:
    http://gamesalad.com/game/play/51398

    EDIT: also, the camera cannot go past the boundaries of the scene. You tracker actor can, so you just need to use min and max on the constrain...
  • jmp909jmp909 Member Posts: 73
    I think that's exactly what i need, thanks!

    when i first looked at it and the comments just now I thought it was actually dragging the background around, but actually looking inside the actor it's moving the camera origin...great!

    thanks again (and to the author too)

    works nicely with interpolating with ease in/out for a nice smooth movement too

    regards
    j
  • jmp909jmp909 Member Posts: 73
    i cant wait until we can type attributes in directly :S
  • jmp909jmp909 Member Posts: 73
    i tried to move that rule into a different actor that i could possibly reuse in other projects.. stopped working altogether.. i just got a blank screen. any idea why this would happen? also you can't just copy the rule because self.something copied into another actor even if it has .something has an attribute itself, just doesn't work :S

    it seems like self.something is actually equal to eg map.something and puttting this into a new actor it doesnt see self.. it tries to see "map" which obviously it isn't

    frustrating!
  • sebababisebababi Member Posts: 51
    Hi Firemaplegames

    You said "... click on the padlock to access its behaviors. This actor now has access to the Camera data ..."

    But I don't see any camera info.

    I tried to post a printscreen, but I don't know how to.

    I just have camera TRACKING to 0,0 but until the Actor doesn't arrive to the middle of the screen the camera doesn't move. I'd like it to move before that.

    thanks
    Sebastian
Sign In or Register to comment.