Jump to content

Tweening a fixedToCamera sprite?


markus.n
 Share

Recommended Posts

Hi,

I need a popup-style text box (sprite image) appear and disappear at times at the bottom of the screen, while everything else stays as it is. However, this sprite doesn't move by tweening, and the problem seems to be the fact that it's fixed to the camera. If I remove that fixedToCamera-line, the tween works just ok, but not with it, there's just no movement whatsoever.

I can always console.log the tween object and it looks ok, and .onComplete also fires on time without the tween movement actually happening.

Any way around this problem?

this.game.load.image('textbg', 'img/general/dummyimage.png');this.textbg = this.game.add.sprite(0, 668, 'textbg');this.textbg.fixedToCamera = true; // Disabling this makes it work!this.textbg.anchor.setTo(0, 0);tween = this.game.add.tween(this.textbg).to({x: 0, y: 468}, 1000, Phaser.Easing.Linear.None, true);
Link to comment
Share on other sites

  • 1 month later...

Just bumped into this issue too!

 

The problem is that x and y are the text's world coordinates, so the tween is probably completed before it starts due to that.

 

To change the offset to the camera you should tween the cameraOffset instead:

tween = this.game.add.tween(this.textbg.cameraOffset).to({x: 0, y: 468}, 1000, Phaser.Easing.Linear.None

However I think this solution is a bit sub-optimal, in some cases like mine where I would like to have several serial tweens on a text and I want to tween properties of the text (alpha) as well as the offset:

 

I can't pass {alpha: 1, cameraOffset.x: game.width/2} to the tweening due to that the dot is not allowed between cameraOffset and x.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...