Hotspot center

Discussion and feedback on Construct 2

Post » Thu Sep 15, 2011 12:37 pm

How hotspots are positioned?
It look's like their can be set only in the corner of the pixel but not in the center. Having sprite 77x77 it should be placed perfectly on the pixel center in the middle of the sprite, but it's off a bit.
That makes object rotations wobble :/
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 15, 2011 3:17 pm

I can rotate objects totally smoothly without any wobble. What browser are you using? The hotspot position should not affect wobble.

Hotspots are set to the nearest pixel. If you can put them a fraction of a way through a pixel, it means the object is shown at a fraction-of-a-pixel offset. This can cause blurry graphics on some browsers (annoying for pixel games) or other issues like the platform movement "floating" by a fraction of a pixel above the object, because the platform movement only works by whole pixels.

The way the math works out, when zoomed in, a pixel's position is its top left point. Consider the very top-left most pixel: you probably want the hotspot at the top left of the object's bounding box, not appearing a small way inside the object when zoomed in a long way.

Does that help? There should be no wobble no matter where you put the hotspot, that's a different issue (or so I thought). All objects are drawn from their top-left point, so it doesn't matter where the hotspot is, it just changes the math for calculating the top-left point, and that is calculated with floating point precision.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Sep 15, 2011 3:45 pm

I mean something like this
If you insert new sprite, i can set hotspot in the center

after closing and reopening image editor it looks like this


So as I understand it right, hotspot is placeed on the top-left corner of the pixel and can't be set to the center of the pixel?

Send you PM with my project file.

In my project where i have this "fan" thing, i have to to make that sprite bit different so the center point is not one pixel?
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 15, 2011 4:01 pm

Ah, I see. Yeah, this seems to be something I hadn't realised about rounding the hotspot. I guess there needs to be a special override for assigning to the middle... but then that might cause the above floating point issues. Hmmmm! I'll have a think... any ideas yourself about how this should be handled?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Sep 15, 2011 4:13 pm

Fastest and easiest would be to redraw sprites, instead of 1 pixel in the center make 4 pixels. Then you can place hotspot to the bottom-right pixel of that center - hotspot will snap to the top-left corner of that pixel.

It will then rotate smoothly, but it's difficult then to draw circular sprites, they always have one pixel in the center :/
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 15, 2011 5:20 pm

Maybe I could add an option to switch off hotspot rounding?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Sep 15, 2011 5:29 pm

Thinking about global switch or more like per instance (an option to choose in image editor)?
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170


Return to Construct 2 General

Who is online

Users browsing this forum: MilkGames and 15 guests