Jump to content

Question about graphics and anchors


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

I'm making a timer bar using drawRect, and I'm wondering if you can set anchor points?

When I put the graphic inside the original canvas size, it tweens as if the anchor was at (0,0), however when I move the graphics slightly outside the canvas, it looks like the anchor is always at (0,0) of the canvas.

Thank you for your help!

Link to comment
Share on other sites

Hi @enpu

Unless I'm doing this wrong there is something up with graphics and tweening.

I've setup a bar png and tried tweening its scale and that works perfectly fine.

When I try tweening a graphic tho, the tweening / anchors seem all out of whack.

This is my graphics setup code.

this.bar = new game.Graphics();
this.bar.fillColor = '#ff0000';
this.bar.drawRect(320, 320, 480, 100);
this.bar.addTo(game.scene.fg);

game.Tween.add(this.bar.scale, {
    x: 0
}, 20000, {
    easing: 'Linear.None'
}).start();

The bar scales as if it anchor point was set somewhere else but its top left corner .

Am I missing something/ doing something wrong here?

Thanks again :)

Link to comment
Share on other sites

You should draw your rectangle at position 0,0 and then move the whole graphics object to the position 320,320.

Position of Graphics object and the position of shape is different thing, shapes have also positions because Graphics object can contain multiple shapes.

this.bar.drawRect(0, 0, 480, 100);
this.bar.position.set(320, 320);

 

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...