Comments (4)
Why not using the move method from e.g. the Sprite?
If you want to implement a Camera without moving the Sprites: the projection
member of the Window class is intentionally public:
Member and loading method
from dgame.
Why not using the move method from e.g. the Sprite?
Convenience, and I'm also drawing basic shapes and vertex arrays which don't supply a move
method.
If you want to implement a Camera without moving the Sprites: the projection member of the Window class is intentionally public:
I'll look into this, thanks. If this does not work for me I'll reopen this.
from dgame.
With your suggestion, I was able to come up with the code below, thanks!
Maybe it could be added to the tutorials on the website?
struct Camera {
private Window *window;
private Matrix4x4 original;
private Vector3f eye = Vector3f(0, 0, 1);
private Vector3f look = Vector3f(0, 0, 0);
private Vector3f up = Vector3f(0, 1, 0);
this(ref Window window) {
this.window = &window;
this.original = this.window.projection;
}
void moveToPosition()(float x, float y) {
// Keep the camera in the level
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (x > (MAP_WIDTH * TILE_SIZE) - WINDOW_WIDTH)
x = (MAP_WIDTH * TILE_SIZE) - WINDOW_WIDTH;
if (y > (MAP_HEIGHT * TILE_SIZE) - WINDOW_HEIGHT)
y = (MAP_HEIGHT * TILE_SIZE) - WINDOW_HEIGHT;
// reset
this.window.projection = this.original;
eye.x = x;
eye.y = y;
look.x = x;
look.y = y;
this.window.projection.lookAt(eye, look, up);
this.window.loadProjection();
return;
}
void moveToPosition()(Vector2f v) {
moveToPosition(v.x, v.y);
}
}
from dgame.
I would not copy the whole Matrix, since it is has a size of 16 * float.sizeof (=4 byte)
= 64 Byte. But besides that it looks nice. I have currently not that much time, so, if you would write the tutorial it would be there much quicker. :)
from dgame.
Related Issues (20)
- Iterating over SpriteSheet starts at index 1 and ends at index 0 HOT 13
- small issue on page HOT 2
- Dgame Does not render on multiple windows HOT 3
- Make Rect a template to allow for floating point HOT 1
- Necessary code doesn't execute when compiling in release mode HOT 3
- Shape color is being changed by unrelated objects HOT 5
- TTF_Init is not being called, formatting Text always errors "Font Invalid" HOT 5
- StopWatch Divide by 0 when trying to fill frame_ms HOT 1
- DerelictGL3 not able to find symbol ( glGetnTexImage ) HOT 3
- Window.wait Timeout is milliseconds, not seconds. HOT 1
- Collision detection HOT 4
- Wrong links in README.md? HOT 1
- Dgame crashing HOT 6
- Is this project still alive ? Couple bugs I ran into. HOT 8
- What about adding more built in colors? Like 400 plus . Color Enhancement idea . HOT 8
- Rect methods questions ? Add new method clamp ? HOT 1
- `object.Error@(0): Access Violation` on `DMD32` HOT 7
- D program quits unexpectedly when using Text HOT 11
- Text colors are wrong HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dgame.