Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the point of setPosition #4

Open
GuichiZhao opened this issue Jan 10, 2018 · 7 comments
Open

What is the point of setPosition #4

GuichiZhao opened this issue Jan 10, 2018 · 7 comments

Comments

@GuichiZhao
Copy link

I can not identify any meaning logic relation to setPosition
Is there anything yet to be implemented?

@GuichiZhao GuichiZhao changed the title What is the point of setPosition What is the point of setPosition Jan 10, 2018
@ericdrowell
Copy link
Owner

ah yes - most people would probably not need it, but you can use it to improve performance for special situations. For example if you have a complex rendering on a layer, but just need to move it around, you could use setPosition() to physically move the canvas element as opposed to constantly re rendering. Alternatively, you could copy the canvas, and then re render the canvas pixels at different locations.

@ericdrowell
Copy link
Owner

you do have a point however, as most folks would probably never use it

@GuichiZhao
Copy link
Author

I think the situation you mentioned is sort of related to what I want.
I need to 'move around' the canvas. From the source code, setPosition looks like 'not implemented'. It do nothing but set this.x this.y, and both of the two variables are not used afterward.
Could you provide more sample code to show how to use setPosition?

Currently, I use clip to simulate 'move around' the whole canvas. It will be very nice if you can point out how to use setPosition

Many thanks

@ericdrowell ericdrowell reopened this Jan 10, 2018
@ericdrowell
Copy link
Owner

you are absolutely correct, setPosition() isn't actually moving the dom element. Must have been something I was thinking about but missed. setPosition() should also do:

this.viewport.container.style.marginLeft = x;
this.viewport.container.style.marginTop = y;

or something similar

@GuichiZhao
Copy link
Author

Currently, I can not come up with a way to make setPosition meaningful.
Because setPosition is a method of Layer, even if it can be inherited by Scene or Hit somehow. They both live in memory (except the scene instance belonging to the viewport). For most in-memory canvas, how to implement setPosition

Correct me If I understand things more wrong, my knowledge of canvas is limited

@marstave
Copy link

marstave commented Jan 25, 2018

Just alter the render function and put layer.x and layer.y for the two 0,0 in drawImage :)

@GuichiZhao
Copy link
Author

@marstave
This is also what I thought where position can fit in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants