How do I restrict a sprite from moving on the x axis?

0 favourites
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • I have a project that Im testing on an Android mobile device. Im using a small sprite in the center of the viewport and when I detect a swipe up I move the sprite in the direction of the swipe (up or down). I use a timer behavior with this sprite to slow the sprite down in increments after a swipe is detected and the sprite is set in motion. Im having a problem where on about the second or third swipe the sprite takes off across the x axis. Can I restrict this sprite where it will NEVER move along the X axis? Thank you for any suggestions or insight!

  • Are you using Bullet behavior? This can happen when you set Bullet Angle of Motion while Bullet speed is 0. Make sure to set sprite speed before setting angle of motion.

    You can also simply set sprite X to viewport center one every tick.

  • Thank you dop2000 . Im now to the point where I can't determine if the sprite is being dragged up or down the Y axis. I set the start Y of the touch to an instance variable and try to compare it to the AbsoluteY of the touch every tick and it should be an easy greater than and less than comparison but it doesn't seem to work. Any suggestions?

  • I don't really understand what are you trying to achieve. You can use Touch.SpeedAt and Touch.AngleAt expressions to recognize swipe gestures.

    It would help if you could share your capx.

  • RunningRazor

    I am not totally clear on what you are trying to do either... but I had to do something similar a while ago and this is how I did it...

    I do a lot with multi touch, so I like to create a "touchpoint" object to track the details about each touch (like where it started, how many ticks long the touch goes for, where it last was, how fast, etc.)

    this sample checks how fast and how far a touch goes for, and then sets the coasting speed and relative distance accordingly.

    https://www.rieperts.com/games/forum/coasting.capx

  • Amazing AllanR Thank you! Exactly what I was currently trying to achieve tonight. Please explain to me the setting of the Sprite position, particularly the ViewportLeft, Right Up, and Down part. Is this finding the center of the screen?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks dop2000 Im trying to scroll a series of 6 sprites that are stacked up kinda like am image carousel. Im making a mobile application for my businesses. I have my company logo across the top of the viewport in a locked layer and below it I have 6 images of my 6 stores. When the user touches down and drags they can scroll the images of the stores.

  • Have you seen this post?

    construct.net/en/forum/construct-2/how-do-i-18/3d-carousel-42745/page-2

    There are cool examples by R0J0hound which you may be able to modify for your needs.

  • I have a project file. Ive got a nice scroll going on. I can't seem to figure out how Im setting the difference in Y axis wrong. The top two images get placed at the bottom. If you want to check it out and lmk would appreciate. Thanks 1drv.ms/u/s!Aky113ixKPF-mTB1t5pn1ZDuhw3A

  • This can be done much-much easier, in literally two events. Put all your store sprites into a family, add Pin behavior to it, pin family to a panel with Drag And Drop behavior and that's it!

    Here is an example (with added inertia scrolling):

    dropbox.com/s/50cl8ipks3wyr95/ScrollingList.capx

  • Thanks dop2000 Ive implemented this pin and panel but the final event System every tick Panel clamp(Self.Y, -Self.Height+LayoutHeight, 0) seems not to work. It makes everything blurred or flicker rapidly and can't scroll.

  • Does it work smoothly when you disable this event?

    Check position of the Origin image point, it should be at the top. Make sure to set "Axis: Vertical" in Drag and Drop behavior and "Set angle: No" in Bullet.

  • Ive set Drag Drop To Vertical Only and Set Bullet Angle to No. Im not sure how to check the Origin of the image point? Can you explain?

  • Even with all of these settings correct it still flashes rapidly and won't scroll. When I disable the System every tic Set Y event it work without inertia scrolling.

  • Please share your project file.

    "Origin" is the image point #0, you set it in the Animation Editor.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)