How do I drag multiple sprites smoothly?

0 favourites
  • 13 posts
From the Asset Store
Use inertion of your movements to throw, rotate your objects and etc. Objects can interact with others while dragging.g
  • I have a sprite that is draggable. There are a few smaller sprites positioned on/around this sprite that need to stay in there correct spot when the parent is dragged. I have this working fine, but there is one big problem. The smaller sprites lag pretty far behind the parent when it's dragging. It looks bad. Is there a correct way to do this so they will move at the same speed as the parent?

    Thank you very much for any advice

  • Oh Ok, there is the "pin" behavior. I'll try this. Hopefully the sprites will stay together smoothly with this.

  • Pin does the trick, but other objects lag behind like a trail of ducklings. Nothing can be done to fix.

  • Pinning should do the trick..

    Could it be you are pinning every tick instead of once?

    Without seeing your events/capx the question is hard to answer..

  • Pinning should do the trick..

    Could it be you are pinning every tick instead of once?

    Without seeing your events/capx the question is hard to answer..

    Even dragging just 1 sprite around on the screen (nothing pinned) lags behind the mouse cursor. Even in the NW.js export. A little better in the export, but still noticeable. I have a modern laptop (i7 4810, 16GB RAM) too so I think it's just an inherent performance issue with JavaScript games. I don't think there is a solution other than using another tool and building a native app.

    I'm doing what I can to minimize the visual performance things. I think it will be Ok.

    Question: Is there any way to completely turn off Physics in the whole game? I don't need any.

  • > Pinning should do the trick..

    > Could it be you are pinning every tick instead of once?

    >

    > Without seeing your events/capx the question is hard to answer..

    >

    Even dragging just 1 sprite around on the screen (nothing pinned) lags behind the mouse cursor. Even in the NW.js export. A little better in the export, but still noticeable. I have a modern laptop (i7 4810, 16GB RAM) too so I think it's just an inherent performance issue with JavaScript games. I don't think there is a solution other than using another tool and building a native app.

    I'm doing what I can to minimize the visual performance things. I think it will be Ok.

    Question: Is there any way to completely turn off Physics in the whole game? I don't need any.

    If you haven't added the physics behaviour, it isn't present..

    I've never really noticed a lag while dragging anything other than DOM elements..

    Could it be something else is interfering with the behaviour?

  • >

    > > Pinning should do the trick..

    > > Could it be you are pinning every tick instead of once?

    > >

    > > Without seeing your events/capx the question is hard to answer..

    > >

    >

    > Even dragging just 1 sprite around on the screen (nothing pinned) lags behind the mouse cursor. Even in the NW.js export. A little better in the export, but still noticeable. I have a modern laptop (i7 4810, 16GB RAM) too so I think it's just an inherent performance issue with JavaScript games. I don't think there is a solution other than using another tool and building a native app.

    >

    > I'm doing what I can to minimize the visual performance things. I think it will be Ok.

    >

    > Question: Is there any way to completely turn off Physics in the whole game? I don't need any.

    >

    If you haven't added the physics behaviour, it isn't present..

    I have not so I guess I'm Ok there.

    [quote:1bh7eyw9]

    I've never really noticed a lag while dragging anything other than DOM elements..

    Could it be something else is interfering with the behaviour?

    Does the number of events or type of events affect this? I have no "every tick" events. I do use a lot (well several, like 10ish) of event sheets, 1 sheet for each main game object to keep related code together. Would this have an effect on performance?

    One last possibility: I'm working on a Win 10 VM. Maybe the VM is causing the lag?

  • You have absolutely no events that run every tick, or just no events where you use the condition system every tick?

    Not that that would normally interfere, unless one of them has actions attached that conflict with the dragging..

    Does the sprite you are dragging have any (other) movement behaviours attached, or are there events with actions setting it's position that could be conflicting/interfering?

    Using multiple event-sheets and/or many events shouldn't have effect..

    I guess the only reason the VM would have any effect is if it's somehow reducing framerate, or hasn't got enough memory/cpu/gpu assigned..

    Did you check your framerate and (image) memory usage and cpu usage (using the debugger)?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You have absolutely no events that run every tick, or just no events where you use the condition system every tick?

    Not that that would normally interfere, unless one of them has actions attached that conflict with the dragging..

    Does the sprite you are dragging have any (other) movement behaviours attached, or are there events with actions setting it's position that could be conflicting/interfering?

    Using multiple event-sheets and/or many events shouldn't have effect..

    I guess the only reason the VM would have any effect is if it's somehow reducing framerate, or hasn't got enough memory/cpu/gpu assigned..

    Did you check your framerate and (image) memory usage and cpu usage (using the debugger)?

    No event using "Every tick" event.

    It's a local Hyper-V so I can bump up the specs waaaaay up and try again this eve.

  • You have absolutely no events that run every tick, or just no events where you use the condition system every tick?

    Not that that would normally interfere, unless one of them has actions attached that conflict with the dragging..

    Does the sprite you are dragging have any (other) movement behaviours attached, or are there events with actions setting it's position that could be conflicting/interfering?

    Using multiple event-sheets and/or many events shouldn't have effect..

    I guess the only reason the VM would have any effect is if it's somehow reducing framerate, or hasn't got enough memory/cpu/gpu assigned..

    Did you check your framerate and (image) memory usage and cpu usage (using the debugger)?

    No event using "Every tick" event.

    It's a local Hyper-V so I can bump the specs waaaaay up and try again this eve. If that doesn't work I'll temporarily install C2 in the host OS and see what happens.

  • I had this problem about a year ago and got so frustrated with it that I gave up.

    If you are setting the sprite position with every tick, it MAY have to do with the event placement in the event sheet. I found I had better luck when I placed the every tick event at the top of the event sheet. Even so, I never got a sprite to follow the cursor one to one.

  • I had this problem about a year ago and got so frustrated with it that I gave up.

    If you are setting the sprite position with every tick, it MAY have to do with the event placement in the event sheet. I found I had better luck when I placed the every tick event at the top of the event sheet. Even so, I never got a sprite to follow the cursor one to one.

    No I'm not using any "Every tick" events. Just the out-of-the-box drag/drop behavior on a sprite.

  • The slight lag you see when a sprite is positioned to the mouse is a pretty common thing encountered in games in general.

    What happens is the sprite is positioned and the next vsync update the sprite is drawn. In that time the mouse could continue moving. In practice this delay is typically about a frame, but it can be longer if double or triple buffering is used as I recall which basically render frames ahead of time to help with performance.

    One solution in C2 to have an image match the mouses position exactly is to use the "set cursor from sprite" action of the mouse object. Other software can do something similar.

    Stuff like a windows app often use a different rendering pattern that allow things to be synced with the mouse exactly. Namely things are only redrawn when an event happens like a mouse move/click etc instead of at a regular rate of 60fps. Even then it's only part of the screen that gets redrawn, instead of everything.

    Edit:

    Going back to C2 the reason objects lag behind other objects they're pinned to is the the order the the pin behavior is run.

    Say you have three objects A, B and C.

    A is pinned to B and B is pinned to C.

    Ok next you move C.

    That frame first A's pin behavior runs first, but since B hasn't moved A isn't moved.

    Next B's pin behavior is run and it's position is updated from C.

    The result is A will lag behind a frame before getting in the correct location.

    This is the problem with behaviors sometimes, and why events are better imo, because you can control when things are done exactly.

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