spritewidget / spritewidget

BSD 3-Clause "New" or "Revised" License
1.25k stars 174 forks source link

convertPointToNodeSpace problem after set Pivot #26

Open cmk961012 opened 6 years ago

cmk961012 commented 6 years ago

There is a problem this function - convertPointToNodeSpace

I created a rootNode and then add a new node (CustomRect) which draws a Rectangle like below.

canvas.drawRect( new Rect.fromLTWH(PADDING, PADDING , size.width - PADDING 2, size.height- PADDING 2), new Paint()..color = const Color(0x8ffb9f61) );

in the CustomRect handleEvent

Offset localOffset = convertPointToNodeSpace(event.boxPosition);

when the pivot of the CustomRect is not set, convertPointToNodeSpace translate successfully. e.g. CustomRect with size width:300, height:300, when touched the top right of the CustomRect, it returns 300,300.

However, when I changed the pivot of CustomRect customRect.pivot = new Offset(0.5,0.5)

When I touched the top right of the CustomRect, it returns 150,-150 . I expect it returns 150,150.

Is that there are anything I need to set before using this function?

TheKashe commented 5 years ago

I've implemented a workaround, but it requires classes to inherit from a custom class (making work with Sprite etc seems tricky without changing the framework itself):

https://gist.github.com/TheKashe/520536ba61767cebfe90e16698bb1100