Scroll Screen with Finger Touch/Swipe

My scene is at a larger width than the device play area. I want to be able to see the objects outside the play area by using touch to scroll to the right then scroll back left.

Any suggestions?

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    When mouse button down, store current mouse X and Y in attributes. This gives you a reference point. The difference between that reference point and the mouse position is how much you will scroll the camera.

    Also when you see the mouse button down event, store the camera origin X and Y in a different set of attributes. You'll need to unlock an actor instance to access those. (I generally don't recommend unlocking instances, but that is the only way you can get to those scene attributes, for now) In that unlocked instance, after storing all of values for reference points, you can now use constrain on the camera origin X and Y and constrain them to the camera origin stored plus the offset based on the difference between the stored mouse position and the current mouse position.

    Normally I would also wrap all the constrains in another rule that does not kick in until the distance between the stored mouse position and the current mouse position is greater than 5 so it doesn't get activated until you swipe far enough and not when you are pushing UI buttons.
  • ArmellineArmelline Member, PRO Posts: 5,366
    edited January 2014
    but that is the only way you can get to those scene attributes, for now

    only way you can get to those scene attributes, for now

    get to those scene attributes, for now

    for now
    ...oh please god yes.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    but that is the only way you can get to those scene attributes, for now

    only way you can get to those scene attributes, for now

    get to those scene attributes, for now

    for now
    ...oh please god yes.
    Genius. It would be extremely helpful!
  • 11XIndustries11XIndustries Member, PRO Posts: 28
    I am fairly new to the building platform of Gamesalad. I have the basics down, but understanding this action is difficult for me. Can anyone go into detail about it with step-by-step examples? Any help is greatly appreciated.
  • colandercolander Member Posts: 1,610
    I there is an instructional video for this which will show you how to do what CodeMonkey said. Search here and on Google for "swipe menu" or "scrollable menu", I think it was by tshirtbooth.
  • 11XIndustries11XIndustries Member, PRO Posts: 28
    Instead of mouse button, can I use touch, touch 1, X? I followed tshirtbooths tutorial, and it did not work. I used touch. This will be for the iphone. There is no keyboard. What did I do wrong?

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    use mouse button. it is always the same as touch 1, even on the iOS devices, but does not require the actor to cover the whole screen for some rule condition to catch the event for touch pressed.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    but that is the only way you can get to those scene attributes, for now

    only way you can get to those scene attributes, for now

    get to those scene attributes, for now

    for now
    ...oh please god yes.

    this would be incredible!
  • TouchiMediaTouchiMedia Member Posts: 154
    edited January 2014
    I can get the camera to move with touch by Codemonkey's method but it goes off the scenes limits, what's best method to keep the camera constrained within scene x , y? But still move around…

    Think I figured it out, basically when scene camera origin x greater then scene width , constrain scene camera to scene width. Or something ;)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    in your constrains use max(0,min(sceneWidth-cameraWidth,TheExpressionYouHaveNow))
    Similar for the height.

    This will make sure with the max(0,X) it will take the larger value of 0 or X, where X is the value for...
    min(sceneWidth-cameraWidth,Y) which takes the smaller of the 2 values.
    SceneWidth-cameraWidth will be the furthest point to the right the camera origin can go.
  • TouchiMediaTouchiMedia Member Posts: 154
    edited January 2014
    Thanks CodeMonkey, I'll do some further testing.

    Last night I thought I had it , but ended up being kind of glitchy (not moving camera but getting to scenes edge)

    I will go back and look at your suggestion and try to implement that.
  • TouchiMediaTouchiMedia Member Posts: 154
    edited January 2014
    in your constrains use max(0,min(sceneWidth-cameraWidth,TheExpressionYouHaveNow))
    Similar for the height.

    This will make sure with the max(0,X) it will take the larger value of 0 or X, where X is the value for...
    min(sceneWidth-cameraWidth,Y) which takes the smaller of the 2 values.
    SceneWidth-cameraWidth will be the furthest point to the right the camera origin can go.
    Well I tried it and isn't scrolling, here is the code for this part -- note, before this using your previous method , It scrolls but with no limit , now nothing at all-

    max(0,min( scene.Size.Width - scene.Camera.Size.Width ,self.CameraOriginX+( self.CurrentMouseX - game.Mouse.Position.X ))

    -edit- maybe missing a parenthesis.. added a third parenthesis at end still nothing - think it was formatting issue, some reason one of the variables was acting as text?

    -EDIT#2- GOT IT! wwahoooo.. Thanks a bunch, this worked for moving X and constraining to scene size, thanks Codemonkey.. below is final code for X:

    max(0,min( scene.Size.Width - scene.Camera.Size.Width , self.CameraOriginX +( self.CurrentMouseX - game.Mouse.Position.X )))

    *** my self.currentmousex should probably be renamed to self.mouseoriginalX to be more clear

    Wow awesome. Appreciate it !
  • TouchiMediaTouchiMedia Member Posts: 154
    edited January 2014

    Normally I would also wrap all the constrains in another rule that does not kick in until the distance between the stored mouse position and the current mouse position is greater than 5 so it doesn't get activated until you swipe far enough and not when you are pushing UI buttons.
    Sorry but must ask one more thing before I will finally have everything set.. Having trouble on this part, about not having camera move with subtle mouse/touch movements--for example, clicking a HUD Button.

    Right now, I am setting my original camera / x,y attributes when mouse button is down rule. Then I do the constrain camera stuff that is discussed above. It scrolls when you touch and drag until edge of scene, fine. All good.

    I been trying combinations of setting a new attribute self.swipedistance. I set the swipedistance attribute to abs(game.mouse.positionX - self.mouseoriginalX) - Then create rule (if self.swipedistance > 5) , constrain the camera(blah , blah).

    But problem is there's no delay of setting the originalX,Y vs mouseX,Y …

    And so I tried doing time delays like 55

    --Well I just tried changing time to every .01 seconds and that makes it better but feels 'choppy' cause of the update time I'm guessing

    Thanks for any help or input!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    if you are going to make an attribute I suggest it not be one you modify.

    So something like self.swipeThreshold and have it set to 5.
    Then the rule around the constrains but inside the touch/mouse pressed event condition and after the setting of the stored camera origin and mouse values:

    If self.swipeThreshold < magnitude(self.mouseStoredX-game.mouse.Position.X, self.mouseStoredY-game.mouse.Position.Y)
  • Raikiri91Raikiri91 Member Posts: 1

    I am trying to get my entire scene to scroll. I am very new to gamesalad. Is there any way someone can break this down even further because I am having difficulty comprehending it and this is the only thread I could find on the topic. Any help would be greatly appreciated.

  • jl.tidwell666jl.tidwell666 Member, PRO Posts: 1

    Hey guys, this took me so long to figure out. The Mouse does not work for touch scrolling. What you need to do is instead of selecting Mouse, you have to change it to Touch OUTSIDE. But everything tshirtbooth said, works outside of using the Mouse. If you don't know what I'm referring to, here is the link.

    http://learn.gamesalad.com/course-status/

    There is honestly so much information missing for Windows, for little things like this and answers posted that are completely incorrect.

    But I got this to work. Also be sure that if your scrolling is on the Y access (Up and Down) not X (Left to Right) change it accordingly.

    So once again, follow the tut' from tshirtbooth. Change all Mouse actions to Touch Outside and ensure if you are attempting to scroll up and down change the axis to Y instead of X.

Sign In or Register to comment.