Skip to content Skip to sidebar Skip to footer

Moving Character On Canvas But Not On The Screen

I am making a 2d game in JavaScript but my character can only move around the length of the screen so I was wondering if there was a way to make the canvas move but my character st

Solution 1:

there are multiple ways to deal with this issue, here are the main 2 i can think of right now:

1.- Move the world instead of your character: what you do is that your character actually stays in place, and you move the rest of the world instead, this is mainly useful for runner games, where movement is constant or one-dimensional (only left-right or up-down but never both in the same level)

2.- I haven't tested this, but what if your canvas is actually the size of the level, but it is partially hidden by a parent DIV with a specific width and height? this way you can move your character around the canvas, and move the canvas around the div to keep the character centered.

These solutions may or may not translate properly to your specific game though, since you gave literally no details about how movement is being dealt with at the moment.

Post a Comment for "Moving Character On Canvas But Not On The Screen"