How to Scroll the background with a finger on iPhone
froamer
Member Posts: 29
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.
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
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)
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.
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
So you are moving the camera not the background.
Very much appreciated. I'll give these a try and let you know how I get on.
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.
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.
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?
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.