Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active January 31, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajweeks/a0d6426870895cf5f464 to your computer and use it in GitHub Desktop.
Save ajweeks/a0d6426870895cf5f464 to your computer and use it in GitHub Desktop.
Devember Sixth

Devember Day 06

Again, not a very productive day in terms of the amount of useful programming I got done. I spent the last hour trying to figure out how to get the camera code working in TM495, with no luck. Unfortunately, tomorrow is my busiest day of the week (11 hours of classes), so it's going to be hard to fit in an hour of development somewhere. But I will try nonetheless. It helps that I have only a one to two hour lecture to attend the next day, so I might end up staying up a little later than I usually do to finish off at least an hour of coding. Also, final exams/projects creeping up closer and closer is not making this challenge any easier.

I don't want to keep posting text-only logs, as I'm 'supposed to' be putting up the code I write on the internet everyday, so I'll share a few lines. However, I don't endorse using this method for doing camera offsets, firstly because it isn't even working for me yet. Second, I haven't had much experience with these kinds of systems before, since all of my previous games have used entirely stationary screens. But, I'll throw this stuff up here just to show you what not to do.

This is how I'm setting the camera's vertical offset (Camera.yo) every game tick:

Camera.yo = this.player.pos.y + Main.canvas.height / 2;

The way I'm using that offset value to render is: drawImage(image, x, Camera.yo + Main.canvas.height - y, width, height), but that isn't working, so idk. I'll put the correct way a working way of rendering using a camera in a following post, once I figure it out.

The following is a crude sketch of the layout I'm attempting at using, although it very well may be a naive way of going about it. Figuring out how to get all of the calculations right is really tough for me right now for some reason. It doesn't help that I have to flip the y positions as javascript's 2D canvas' origin is at the top left corner, and mine is at the bottom left.

That's it for now, hopefully I'll be back tomorrow!

Previous Entry | All Entries | Next Entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment