How do I drag multiple sprites smoothly?

Get help using Construct 2

Post » Mon Nov 30, 2015 6:58 pm

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.
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Mon Nov 30, 2015 7:01 pm

ryanrybot wrote: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.
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Mon Nov 30, 2015 7:46 pm

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.
B
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests