Sign in to follow this  
Ninjadoodle

Question about graphics and anchors

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!

Share this post


Link to post
Share on other sites

Yes you can set anchor points in Graphics.

1 hour ago, Ninjadoodle said:

When I put the graphic inside the original canvas size

I'm not sure what you mean by that or what actually is the issue?

 

Share this post


Link to post
Share on other sites

@enpu - it seems that wherever I put the graphic on the stage, it tweens its scale from the ‘stages’ (0, 0) position.

This could very well be something I might be doing wrong, I just can’t seem to get it working correctly.

Share this post


Link to post
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 :)

Share this post


Link to post
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);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.