|
+20hours on just Camera |
trieveonc
Member #15,638
June 2014
|
and Fail still I even was using xOff and yOff But its not really as effective as adding a camera im willing to pay//also i have a $10bucks amazon card (i know its not much) if someone could just please go in my code and add a camera thats it!I would deeply and sincerely appreciate it. i tried over countless methods tyring to implement it. If someone could do it for me and ill learn from it I know its not typical but me about to shoot myself . Its very complicated adding a camera when your using function and game states. InitShip Player P.S |
beoran
Member #12,636
March 2011
|
It may be a bit overkill but my RPG engine has a fully featured camera module, here: I know it can be frustrating to work a long time without finding an answer, but it's important not to just copy what others are doing. As for a camera system, think of it like this: a camera can be represented by a struct that contains the x, y, width and height values of the camera. For the x |
Dizzy Egg
Member #10,824
March 2009
|
trueveonc, listen, you can't just say "add a camera". I looked through your code, and it's too much. Tell us how it works, what doesn't work, take snippets of code that don't work AND TELL US WHY THEY DON'T WORK and what you expect them to do. You can't just say "add a camera". Too arbitrary, too vague.
---------------------------------------------------- |
trieveonc
Member #15,638
June 2014
|
thank you for your replies. For the Camera if(cameraPosition[0] < 0) int fx =(ship.curFrame % ship.animationColumns) * ship.frameWidth; al_draw_bitmap_region(ship.image, fx, fy, ship.frameWidth, and its intiated in main as so.... if(redraw && al_is_event_queue_empty(event_queue)) if(state == TITLE) ive also tried doing it as a voidUpdateCamera prototype instead of just pasting it in my player struct. P.S**this maybe easier* for example..... the 1's if this was a tile map. I can only move through the 0s is there a way to fix to this to avoid the headache of the camera 111111 xOff += keys[RIGHT] *5; if(xOff < 0) NO ERROR OR WARNINGS BTW. sorry for being a newb |
Dizzy Egg
Member #10,824
March 2009
|
I don't understand what you mean....you're saying that if camera.x, or xOff goes below 0, make it 0, and it it goes above the screen width etc, make it the screen width... ...what exactly are you trying to do? Are you saying that this is your map: 0000000000000000 ...but you can only move like this (you're trapped in the 1's, which are SCREEN_W and SCREEN_H)??: 1111100000000000
---------------------------------------------------- |
trieveonc
Member #15,638
June 2014
|
Sorry for being confusing. i can move like this(using mappy btw using 1s and 0s as examples) if this was my entire map this is using xOff and yOff no camera. I have a quick question since you went through my code. |
Dizzy Egg
Member #10,824
March 2009
|
Ok, so let's assume you're using xOff and yOff....show me the code where you use xOff and yOff to affect your tiles....(ie, show me how you use xOff and yOff when drawing)... [edit] You store your camera wherever you want to! Personally I would have: Player ...etc etc, and then have functions like.... funcDrawPlayer() ...etc etc....
---------------------------------------------------- |
trieveonc
Member #15,638
June 2014
|
edit sending the actual code shortly. the code above is all the xOff Yoff in my program i just put it in before it draws my map so it sets map boundaries,it also allows me to move through the map and yIm just gunna scrap this xOff yOff stuff ima do the the way you mentioned in objects.h i have //struct int width; in main.cpp //prototypes //main allegro_transform *camera //below main if(cameraPosition[0] < 0) } al_draw_bitmap_region(ship.image, fx, fy, ship.frameWidth, //i put in game state playing if state playing... NO Errors or Warnings |
Mark Oates
Member #1,146
March 2001
|
If you use an ALLEGRO_TRANSFORM, you have the option to no longer need offset_xs or offset_ys littered throughout your sprite drawing routines. -- |
trieveonc
Member #15,638
June 2014
|
**the relevant parts of the code***I included the code same document in both attachments* //Structs in .h 1struct SpaceShip {
2 int ID;
3 int x;
4 int y;
5 int lives;
6 int speed;
7 int boundx;
8 int boundy;
9 int score;
10
11 int maxFrame;
12 int curFrame;
13 int frameCount;
14 int frameDelay;
15 int frameWidth;
16 int frameHeight;
17 int animationColumns;
18 int animationDirection;
19
20 int animationRow;
21
22 ALLEGRO_BITMAP *image;
23struct Camera
24{
25
26
27int width;
28int height;
29float x;
30float y;
31float *cameraPosition;
32};
33
34};
35//in MAIN.cpp
//prototypes void InitShip(SpaceShip &ship, ALLEGRO_BITMAP *image); void InitCamera(Camera &camera,float *cameraPosition, SpaceShip &ship); void DrawShip(SpaceShip &ship,Camera &camera); //int main() int main() Camera camera; float cameraPosition[2]={0,0}; InitCamera(camera,cameraPosition,ship); else if(state == PLAYING) MapDrawBG(0,0, 0, 0,WIDTH, HEIGHT); DrawShip(ship,camera); return 0; //protype below main 1void DrawShip(SpaceShip &ship,float *cameraPosition,Camera &camera)
2{
3 int fx =(ship.curFrame % ship.animationColumns) * ship.frameWidth;
4 int fy = ship.animationRow * ship.frameHeight;
5
6 al_draw_bitmap_region(ship.image, fx, fy, ship.frameWidth,
7 ship.frameHeight, ship.x-cameraPosition[0],ship.y-cameraPosition[1], 0);
8
9void InitCamera(Camera &camera,float *cameraPosition, SpaceShip &ship)
10{
11 int x=0;
12 int y=0;
13cameraPosition[0] = -(WIDTH / 2) + ( x+30 / 2);
14cameraPosition[1] = -(HEIGHT / 2) + ( y+30 / 2);
15
16if(cameraPosition[0] < 0)
17cameraPosition[0] = 0;
18if(cameraPosition[1] < 0)
19cameraPosition[1] = 0;
20if(cameraPosition[0] > (mapwidth * mapblockwidth) - WIDTH)
21cameraPosition[0] = (mapwidth * mapblockwidth) - HEIGHT;
22if(cameraPosition[1] > (mapheight * mapblockheight) - WIDTH)
23cameraPosition[1] = (mapheight * mapblockheight) - HEIGHT;
24
25}
26void ChangeState(int &state, int newState)
27{
28
29 state = newState;
30
31 if(state == TITLE)
32 {
33 }
34 else if(state == PLAYING)
35 {
36 InitCamera(camera)//saying undefined
37 InitShip(ship);
38
39 al_play_sample_instance(songInstance);
40 }
41 else if(state == LOST)
42 {
43 }
44}
saying camera is undefined when i Init it i feel like im in the right direction with it stuck on 23 hours working with stupid camera. im online if anyone wants to walk me through it idk why it isnt following me |
Mark Oates
Member #1,146
March 2001
|
Well, when posting, please put your code inside <code></code> tags. Also, you can edit your previous posts to make those changes, by clicking that icon:
-- |
trieveonc
Member #15,638
June 2014
|
AFTER 25 HOURS I DID IT!!! thank you all... |
Mark Oates
Member #1,146
March 2001
|
I'm curious, what was the "thing" that you didn't get until the end? -- |
trieveonc
Member #15,638
June 2014
|
I was used to setting up a camera for small programs. void UpdateCamera prototype then everything else in main without calling the player function whereas I used functions to get the variables i wanted like the player variables and correlated them with my camera function. But im a newb atm so i greatly appreciate the collective information from the allegro community. thanks again. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
trieveonc said:
1draw ship()
2{
3cameraPosition[0] = -(WIDTH / 2) + (x + width / 2);
4cameraPosition[1] = -(HEIGHT / 2) + (y + height / 2);
5
6if(cameraPosition[0] < 0)
7cameraPosition[0] = 0;
8if(cameraPosition[1] < 0)
9cameraPosition[1] = 0;
10if(cameraPosition[0] > (mapwidth * mapblockwidth) - WIDTH)
11cameraPosition[0] = (mapwidth * mapblockwidth) - HEIGHT; 12if(cameraPosition[1] > (mapheight * mapblockheight) - WIDTH) 13cameraPosition[1] = (mapheight * mapblockheight) - HEIGHT;
14
15int fx =(ship.curFrame % ship.animationColumns) * ship.frameWidth;
16int fy = ship.animationRow * ship.frameHeight;
17
18al_draw_bitmap_region(ship.image, fx, fy, ship.frameWidth,
19ship.frameHeight, x-cameraPosition[0],y-cameraPosition[1], 0);
You've swapped WIDTH and HEIGHT there on the two highlighted lines. It should be : if(cameraPosition[0] > (mapwidth * mapblockwidth) - WIDTH) And, you should share your solution in case it would help someone else. I still don't know what you did. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
trieveonc
Member #15,638
June 2014
|
so i implented the basic camera, but its causing my sprites to follow the player on the screen instead of staying at their world coordinates. whats going on with my camera its moving my screenheight and width along my map instead of a small camera just on the player. the code void CameraUpdate(float *cameraPosition, float x, float y, int width, int height,SpaceShip&ship) { cameraPosition[0] = ship.x-WIDTH/2; cameraPosition[1] = ship.y-HEIGHT/2; if(cameraPosition[0] < 0) cameraPosition[0] = 0; if(cameraPosition[1] < 0) cameraPosition[1] = 0; if(cameraPosition[0] > (mapwidth * mapblockwidth) - WIDTH) cameraPosition[0] = (mapwidth * mapblockwidth) - WIDTH; if(cameraPosition[1] > (mapheight * mapblockheight) - HEIGHT) cameraPosition[1] = (mapheight * mapblockheight) - HEIGHT; } playerr al_draw_bitmap_region(ship.image, fx, fy, ship.frameWidth, ship.frameHeight, ship.x-cameraPosition[0],ship.y-cameraPosition[1], 0); the sprite following the screen at 1,1 instead of staying there void DrawSprites(Sprite &sprite) al_draw_bitmap_region(sprite.image, fx, fy, sprite.frameWidth, basically the problem is the camera is following my screen instead of my player i believe. |
|