How to Scroll the background with a finger on iPhone

froamerfroamer Member Posts: 29
edited November -1 in Working with GS (Mac)
Hi, just joined gamesalad and very impressed with the software, the community and games people are producing! So I'm inspired to create my first iphone game but I am falling down at the first hurdle.

I want to scroll the background by dragging my finger (like Google Maps). When I release the background would stay where it was dragged. Dragging again would move it from that point.

I've gone through the drag and drop tutorials, and looked at some examples, but I need the background to move in the opposite direction and cover a large map (bigger than the initial screen).

If any could help a newbie I would very much appreciate it.

Comments

  • RHRH Member Posts: 1,079
    I'm sure that he will probably post this later but FireMapleGames made this demo

    http://gamesalad.com/game/play/37404

    and i'm sure that you can probably use something similar to create what you are looking for

    (I haven't actually looked at that as a project in GS so i'm just guessing)
  • froamerfroamer Member Posts: 29
    Thanks @roryyror,

    However that is not really what I want. I want multi-directional dragging of the background, like Google Maps. Also I need to click the background itself, not have a scrollbar.

    I appreciate the post though, but I am still struggling.
  • RHRH Member Posts: 1,079
    ye, i know i didn't have much time to think about it so i figured that was better than nothing. Thinking about it, a very simple way of doing it is:

    Create an actor and set the image (your map) as the image for the actor.

    Create a rule for the actor that is:

    When actor receives event that is touch is pressed

    constrain attribute: self.Position.X to game.Touches.Touch 1.X

    and

    constrain attribute: self.Position.Y to game.Touches.Touch 1.Y

    That simply allows you to move the image around with your fingers touch I think

    I'm not exactly an expert when it comes to GS so you may want to wait for a better/different answer.

    EDIT: on third thoughts check this out as well http://gamesalad.com/forums/topic.php?id=5013
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    have an actor that is invisible and put the control camera behavior in it. Then have a rule that says when touch is pressed constrain self.positionX to touch1X and constrain self.positionY to touch1y

    So you are moving the camera not the background.
  • froamerfroamer Member Posts: 29
    Many thanks @roryyror and @scitunes!!!

    Very much appreciated. I'll give these a try and let you know how I get on.
  • froamerfroamer Member Posts: 29
    OK this turned out to be quite complicated, so I have shared a working example. You can find it on my profile. However I achieved it without the need for a camera controlling actor and the result should work with any size map.

    Basically I had to create a Dragging flag on the map which I turn on when the mouse its down. I also store the DragStart X and Y coordinates and the DragOrigin X and Y coordinates at the start of the drag.

    While the Dragging flag is set, I constrain the Camera X and Y origin like this:

    scene.Camera.Origin.X = min( self.MapWidth ,max(0,( self.DragStartX - game.Mouse.Position.X )+ self.DragOriginX ))

    scene.Camera.Origin.Y = min(self.MapHeight,max(0,( self.DragStartY - game.Mouse.Position.Y )+ self.DragOriginY ))

    I do all this in the Map INSTANCE so I have access to the current scene and therefore the camera.

    It is probably easier to see in action:
    http://gamesalad.com/game/play/50917

    I hope it helps others.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Nice! Great solution! Thanks for sharing!
  • carlos.varela.comcarlos.varela.com Member Posts: 99
    froamer:

    I am with scitunes and firemaplegames, maybe moving the camera its a better strategy, because you are not limited to one background or one object I think.
  • carlos.varela.comcarlos.varela.com Member Posts: 99
    Froamer,

    I did put your project at my porfolio:
    http://gamesalad.com/game/play/51398

    I did reduce the size of the image from 5mb to 1mb and do some changes in order to see the entire map. GS say that the limitation for iphone images is 1024x1024, your image is about 2400x1200 and I can play with it in my iphone 3g os version 3.1.2, just for your info.

    Maybe the image limitations are bigger right now with the current iphone os.

    Anyone know about the current limitations for images on the iphone?
  • froamerfroamer Member Posts: 29
    HI Carlos,

    I'm glad you found it useful. yes the image was a bit big but it was only really an example. In the game I am developing I will probably use tiles to make up the background.

    Thanks for the tweaks, I have updated my original game example which seems to make more sense than you posting your own, otherwise we will have two examples of the same thing, which is just going to confuse people looking to solve the same problem.
  • ImsdleImsdle Member Posts: 8
    Hey Carlos. I'm trying to do a simple game and your post is exactly what I need. Can you post a screen shot somewhere or let us know where we can download the code?
Sign In or Register to comment.