Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Best way to move an object to a location on touch/click
  • What is the best method to animate an object to a point where the user has touched/clicked? it'd be nice if the animation has some easing, for adding smothness.

    I've been thnking about the posibilities of animation inside GBS. What can be achieved?
    I mean, I we leave out spritesheets and Spine, how can we animate at runtime? hardcoding animations? It'd be great to have some components for that, like "go to click point" with easing control, alpha blending, size changing and the like. For example a componet called something like "parametric animation" where you can choose what property to animate, in what amount of time, triggered by what input, 

    i.e.: 
    change: alpha
    from 100 to 0
    interpolation: ease-out.
    duration: 3s
  • 5 Comments sorted by
  • How about a RulesMap on the object listening for a touch/klick. If this happens, it stores the coordinates and stops listening (or it can listen for a new touch/klick if you like). Then you just need to implement an Interpolate Property from the objects current coordinates to the touch/klick ones.
  • Thanks Cavaron! I've just done that but it doesn't move,

    I put a rules map on entity, triggered when MouseDown.
    changed entity Spatial for Basic Spatial, so it don't take into account physics. 
    Put an interpolate Property on the triger action field.
    Interpolate the entity x position with the mouse x position
    Create a text fiels and a rules map into it to check mouse.x value.
    Run.
    The text shows the mouse position correctly changing on every click, yet the entity doesn't move.

  • @kikubu


    Make sure when you are moving spatials to reference the spatial.position

    and then use the setPoint Helper to move the spatial.

    P.S to make it a little cooler you add a mouse constraint to it, and try to release it once it gets to its destination. 
  • @kikubu

    "changed entity Spatial for Basic Spatial, so it don't take into account physics"
    I think the physics works with the Body Type-option in a normal spatial, not a basic one. If you don't want physics, you just set the Body Type from "Simulated (DYNAMIC)" to "Non-Simulatet (KINEMATIC)". I don't know if it is even possible to move basic spatials ingame. I thought of them like static (or scrolable) background images.

    I greatly recommend to watch Lavons HungryHero-video tutorial. The Hero-Movements are very close to what you want to do - at least on the y-axis.
  • Ok, thanks, I got it working!!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion