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
Having Problems with Dragging Objects
  • Hi

      I have followed the follow post :


     To allow for an object to be dragged around the screen but I find that this method becomes very difficult to control (especially when dragging up and down) and not very smooth. Is there going to be an improvement over this and I wondered if (like some of the other game makers) that a tick box against each object could be added to allow if the object can be draggable. 
  • 9 Comments sorted by
  • Secondly to this, my first test was with using a stretched square object which had the above problems, now that I have added in an asset and applied the same component action to that, every time I try and drag it, the asset object keeps moving away from the point of which I tried to start dragging it.


    Any ideas because this is really a simple part of the whole project .

     Also I decided to go back into the draggable action which I had copied from the other object to edit it to make sure that all of the references to the new object were correct and as I clicked into the expression line to update it I got this error:

    TypeError: Error #1010: A term is undefined and has no properties.


    at com.gbs.tracing::PolygonTool$/earClip()


    at com.gbs.utils::PolygonUtils$/makeComplexShape()


    at com.gbs.utils::PolygonUtils$/makeComplexShape()


    at com.gbs.utils::PolygonUtils$/createComplexPolygonShape()


    at com.gbs.gameeditor.common.views::CollisionEditor/convertPointsToPolyShapes()


    at com.gbs.gameeditor.common.views::CollisionEditor/storeShape()


    at com.gbs.gameeditor.common.views::CollisionEditor/__tracerCanvas_traceEnded()


    at flash.events::EventDispatcher/dispatchEventFunction()


    at flash.events::EventDispatcher/dispatchEvent()


    at mx.core::UIComponent/dispatchEvent()


    at com.gbs.gameeditor.common.views.components::BitmapTracerCanvas/storeShapeVertices()


    at com.gbs.gameeditor.common.views.components::BitmapTracerCanvas/onMouseDown()




  • @TimCS once again you are mixing to many issues in one post. If you have a question I can answer here but if you have found a bug please report it using the support link with reproducible steps.

    Regarding the drag and drop tutorial, are you trying to drag a basic object without a collision spatial or an object with a collision spatial on it. That tutorial is for dragging an object with a Basic Spatial. If you want to drag objects with a Collision Spatial on it which simulates in the physics engine and is affected by gravity and forces then you need to use a Mouse Constraint.
  • @Lavon

      I was trying to provide as much information as I could about the problem I am having. 

     The drag and drop tutorial is all I could find to help me make this work , can you please provide how to use the Mouse Constraint as I cannot see anything in the documentation or tutorials or forum posts on this.


    The object in question does have a collision spatial, the collision spatial is only on part of the object not the entire object. However I did create a square object based on this new entity and when I was dragging that it did not behave in the same way , any ideas why that would be ?

    ** Edit **
    13/3/2016

    I have looked at the mouse constraint component but I do not see how to make this work with dragging the object can you please help?
  • @Lavon

      Now looking at this again and your reply about whether the object has a collision spatial I was wrong in my last post, the object does not have a collision spatial , I misunderstood your reply sorry. 

     The object in question was loaded in as an asset unlike the square object which I was using as a test first to get things working before moving onto loading an asset object in.

    The asset object that I am having problems with has simple got the standard spatial ( I guess it does then have a basic spatial) and renderer that was created by GBS and I have not change this. The only amendment made is that the collision shape on this asset object has been changed to only be on one part of the object. However I did do just the same with the square object and this had no problems. 

    Also the gravity in this project is set to x = 0 and  y =0 and the object is a kinematic body type but I have also tried it with a Dynamic body type and still have this problem when dragging the object that it simply is "pushed" forward every time I try and drag it 

     
    My apologies is I have mislead you on this matter.  


    ** EDIT ** 15/03/2016


    On looking into this dragging issue I am still very puzzled about your reply. When I added the square object to the project at the start , this already ( now that I understand the two different spatial types a little more) had a collision spatial added to it automatically. I then edited the collision location on this square object and also used your post, as mentioned before, to move the object about. This worked fine apart from the dragging up and down which still seems non intuitive as moving the mouse to quickly stops the square object altogether.

    So then I added the asset which is a PNG file at a resolution of 320 x 54 so it is elongated  in shape. This like the square object has the collision spatial added automatically but applying the same logic to move it causes this object to "jump" away every time it is clicked on or touched. What I have found is that moving the registration point about makes some difference to this problem but it still is not ideal. 

    Any thoughts on why the square object works (I did stretched and shape the square object to be elongated as well) with the dragging and the loaded asset does not ?
  • @TimCS it is important that you watch the basic concept videos on our GameBuilder TV page which covers spatials and renderers and other basic concepts. When I say collision spatial I mean a spatial object that has a collision shape on it and can be simulated in the physics engine. Most objects imported into GBs will default to using a Collision Spatial and have a basic polygon collision shape applied. A basic spatial is just a plain spatial which has position values but it is not simulated in the physics engine.

    To drag an object with a Collision Spatial on it you just need to add one instance of the Mouse Constraint component into your scene on any object and run your game. You will then be able to drag any "DYNAMIC" object in the scene.
  • @Lavon

      Thank you for that, I have watched the videos but I find that the only way I can learn is by "trial and error" so hence my continual questions here because this is how I pick up on how anything works by asking :) 

    ** EDIT **  16/3/2016 7:32am 
    I have added the mouse constraint to the object in question and made sure that it is dynamic , however the behaviour of the dragging has not changed, the object is still "jumping| away from the mouse pointer. 

    From your reply on this, how come the square object that I added with a collision spatial works with the dragging and without the mouse constraint ? I am wondering if it is how GBS is handling this new asset into this project
  • @TimCS Did you remove all of your other dragging logic and just add one instance of the Mouse Constraint? 
  • @Lavon

        I am back with creating my project again since loosing all of my data so my issue still remains with the latest build of GBS. The main issue that i have when dragging an object is if the movement of the hand/finger moves a little quicker because then the object does not follow the movement of the finger quickly enough it very quickly stops and in the case of the game I am trying to make this will cause frustration for the player.

     Is there anyway to make the object move more smoothly and "keep up" with the movement of the finger when going quicker?
  • @TimCS when adding dragging to your object you should listen for mouse/touch movement globally meaning not on the entity. Then match the object's position to the movement offset. This is only required for Basic Spatials. For Collision Spatials you can just use the Mouse Constraint to handle dragging. Which one are you using?

Howdy, Stranger!

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

In this Discussion

Tagged