mohamed.irshad.k Posted October 1, 2011 Share Posted October 1, 2011 When a WidgetSprite is rotated which has its size set manually by using setWidth() and setHeight() it gives unexpected result. If the size is set to (0, 0) then the rotation works as expected. Below is the sample code: WidgetSprite sprite; int init() { Gui gui = engine.getGui(); sprite = new WidgetSprite(gui,"samples/widgets/textures/background.png"); sprite.setPosition(400, 300); // Uncomment to see the problem. //sprite.setWidth(128); //sprite.setHeight(128); gui.addChild(sprite, GUI_ALIGN_OVERLAP); return 1; } float fAngle = 1.0f; int update() { sprite.setTransform(rotateZ(fAngle)); fAngle += 0.1; return 1; } int shutdown() { delete sprite; return 1; } Link to comment
steve3d Posted October 2, 2011 Share Posted October 2, 2011 Calculate scale from your dimension,and add it to your transform matrix, I'm doing this way never met problem Link to comment
mohamed.irshad.k Posted October 3, 2011 Author Share Posted October 3, 2011 Yeah, that does work well. thanks :(. Still the way it behaves for setWidth and setHeight is a bit unexpected. Link to comment
manguste Posted October 10, 2011 Share Posted October 10, 2011 You rotate the background layer which is strongly not recommended. The reason is that the background layer is used to calculate BB of the widget. We have fixed stretching to some extent, but rotating the background layer is still not option. Use other layers for rotation. Link to comment
mohamed.irshad.k Posted October 12, 2011 Author Share Posted October 12, 2011 If I use a non-background layer, then the background layer will require another dummy(possibly a fully transparent) image to calculate the BB, rt?. Or can we set a blank background layer and set its width and height manually and do the transformations on another layer? Link to comment
ulf.schroeter Posted October 12, 2011 Share Posted October 12, 2011 Why don't you just test it by doing a 10 minutes prototype implementation ? Link to comment
mohamed.irshad.k Posted October 13, 2011 Author Share Posted October 13, 2011 Sure I did and it turns out that setting a non-background layer works like a charm though the getWidth() and getHeight() will return 0 since they are based on the background layer. This solves my issue. One small doubt though, will I loose any benefit if I don't use the background texture at all? Looks like one should never use the background layer at all. Link to comment
manguste Posted October 14, 2011 Share Posted October 14, 2011 Until you are not rotating it, using the background one should be fine. though the getWidth() and getHeight() will return 0 since they are based on the background layer Have you called arrange() first? It forces to calculate widget size in the current frame. Otherwise, it will be calculated and returned only in the next frame, when all GUI elements are updated. Link to comment
mohamed.irshad.k Posted October 15, 2011 Author Share Posted October 15, 2011 Yup, I tried arrange() and I also put log.message("%d, %d\n", sprite.getWidth(), sprite.getHeight()); in the update() function. As long as I don't set a texture to the background layer the size of the sprite is fixed at (1, 1). The moment I set a texture to the background layer, the sprite dimensions are updated to reflect the texture's dimensions. Link to comment
manguste Posted October 17, 2011 Share Posted October 17, 2011 Then it works as intended :) (1,1) are default values for the background layer unless the texture is set. If you want to get the layer size, use getLayerWidth() and getLayerHeight(). Link to comment
Recommended Posts