jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.29k stars 454 forks source link

[Question] #656

Closed car1ot closed 2 years ago

car1ot commented 2 years ago

Describe your question

Hello. How can I make camera following object?

Your code (either pasted here, or a link to a hosted example)

const circle = two.makeCircle(x, y, radius);
// Circle added to TWO.JS scene 
tick((dt) => circle.position.x += 10 / dt) 
// Circle is moving right
// ... I need camera to follow this circle!
// So this circle always should be at the screen center, and only objects around are moving when circle moves
jonobr1 commented 2 years ago

Something like this? https://codepen.io/jonobr1/pen/wvmYXXr

car1ot commented 2 years ago

Something like this? https://codepen.io/jonobr1/pen/wvmYXXr

Yes, exactly! Thank you.

car1ot commented 2 years ago

The issue was resolved. Example how to make following camera effect: https://codepen.io/jonobr1/pen/wvmYXXr