Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Gtween & rotation ! — Gideros Forum

Gtween & rotation !

unclekinguncleking Member
edited March 2014 in Bugs and issues
Hi,

I have a very peculiar behaviour.
I have parent sprite which holds some child sprites. Now both child sprites and parent sprites have their own Gtween animations. All of that works fine till i add a rotation behaviour to the child sprite and it makes the entire sprite go jump around !!
 
local properties = {};
 
local parentSprite = Sprite:new()
parentSprite:setPosition(512, 400)
parentSprite:set("anchorX", 0.5)
parentSprite:set("anchorY", 0.5)
-- parentSprite:setWidth(1024)
-- parentSprite:setHeight(800)
 
local parentAnim = {}
parentAnim.x = 1177
parentAnim.y = 400
parentAnim.anchorY = 0.5
parentAnim.anchorX = 0.5
 
local down = Bitmap.new(Texture.new("star.png"))
local up = Bitmap.new(Texture.new("star.png"))
 
up:setPosition(197, 205)
up:setAnchorPoint(0.5, 0.5)
 
down:setPosition(197, 95)
down:setAnchorPoint(0.5, 0.5)
 
local upAnim = {}
upAnim.x = 197
upAnim.y = 95
upAnim.anchorX = 0.5
upAnim.anchorY = 0.5
 
 
local downAnim = {}
downAnim.x = 197
downAnim.y = 205
downAnim.anchorX = 0.5
downAnim.anchorY = 0.5
 
 
local rotor = Bitmap.new(Texture.new("star.png"))
 
rotor:setPosition(286, 225)
rotor:setAnchorPoint(0.5, 0.5)
rotor:setRotation(0)
 
local rotorAnim = {}
rotorAnim.x = 286
rotorAnim.y = 225
rotorAnim.anchorX = 0.5
rotorAnim.anchorY = 0.5
rotorAnim.rotation = 360
 
 
 
local properties = {};
properties.delay = 0;
properties.dispatchEvents = true
 
stage:addChild(parentSprite)
parentSprite:addChild(up)
parentSprite:addChild(down)
parentSprite:addChild(rotor)
 
stage:addChild(parentSprite)
 
local upTween = GTween.new(up, 5, upAnim, properties)
local downTween = GTween.new(down, 5, downAnim, properties)
local rotorTween = GTween.new(rotor, 1, rotorAnim, properties)
local parenttweener = GTween.new(parentSprite, 5, parentAnim, properties)
Try commenting the rotorTween line and tween goes smoothly !

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @unlecking unfortunately although the star is round, the image itself is a box, thus on rotation (due to the edges) it changes the dimensions of the parent.
    As anchorpoint of the parent is calculated based on starting dimensions of the parent, the changes in its dimensions make them jump.
    If you disable setting anchorpoint to parent it should work as expected.

    So what you can do, is not setting an anchor point to parent, but rather set negative position values to some child members, thus making it behave like anchored to some specific position ;)
  • so essentially what you are saying is that if i add two 1px images at "top", "left" and "bottom", "right" should do the trick ? it would make the sprite as big as the screen and the jumping goes away !

    something like
    local dummy1 = Sprite:new()
    dummy1:setPosition("left", "top")
    local dummy2 = Sprite:new()
    dummy2:setPosition("right", "bottom")

    Is there no better way to set the bounds to parent sprite ?
    Is there a memory impact to setting the sprite to screen size ? ( assuming not! )

    BTW- The jerkiness does go away as expected !
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    1) Yes it will work
    2) No there is no better way
    3) No I don't think there will be much of an impact, as Sprite is only a holder and does not impact rendering

    :)

    Likes: uncleking

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    Actually, I think even better, you can create empty sprite and position it in the bounds. Also if not sure always add setVisible(false) to remove elements from drawing
    :)
  • Well.. i just added a one pixel transparent image to both ends. That does seem to hold the sprite all right.
Sign In or Register to comment.