I wanted to know if there was a way to fix this problem with the character showing up on the screen. The characters are not big but it seems like the screen(camera) is to low so it starts to cut of their heads of the heads so that you may only see part of them. Is there a way I can fix this? cause I really don't want to have to be scaling down to like 80 or something :(
Is your player right at the top of the screen?
when it comes to standing on a walkable area I believe the hotspot for a character is at his feet so his head may well be cut off if it is outside the top edge.
Perhaps lower the walkable area.
Check the height of the sprite of the character. If that's bigger than the height of the resolution, then the camera is fine. If the room is scrollable (vertically or horizontally), then the viewport (the camera) is facing the player who is probably on a lower part of the screen.
Is there any way to fix that?
Fix what?
Is your room height bigger than your game's resolution? (Answer that first)
If it's a yes, then put this on room after fade in SetViewPort(character[your character].x,character[].y);
if not, take a screenshot for the love of god.
Yeah the room is big. But I'ma try this out and hopefully this works.
The only proper way to fix this is to redesign the room so that walkable areas aren't right at the top of the background, obviously.
Scrolling room or not, if the character sprites are x pixels high, then the top x pixels of the background shouldn't contain walkable ground.
But yeah, please post a screenshot (or better, the room background and a sprite).
The walkable area is nowhere near the the top but rather closer to the button.
Example sprite
(http://www.pictureshoster.com/files/fe0tcityq3qvgqqmd0s.png) (http://www.pictureshoster.com/viewer.php?file=fe0tcityq3qvgqqmd0s.png)
In game shot
(http://www.pictureshoster.com/files/c73i2tawlozlw7degueo.png) (http://www.pictureshoster.com/viewer.php?file=c73i2tawlozlw7degueo.png)
half colored in-game room with in-game sprite.
(http://www.pictureshoster.com/files/p2788t7a6gt692q8d9qd.png) (http://www.pictureshoster.com/files/p2788t7a6gt692q8d9qd.png)
I'm gonna go guessing.
The viewport by default follows the PLAYER character.
Now, you have sprites that are 108px big, and the resolution is 320x200. Increasing the viewport which is what you think is doable, isn't. The best thing to do either move the characters a bit down or
SetViewPort(GetViewPortX(), (GetViewPortY()-60));
Though, still your issue remains as we'll slowly obscure the characters in the bottom.
Right, I see.
The problem is that it's a vertically scrolling room and your characters are taller than screen height/2.
AGS centers the viewport on the characters feet, not just horizontally but also vertically.
The only solution I can see is to manually scroll.
Put this in a new script:
// smooth viewport scrolling with offset
float vpx, vpy;
// I'm using a fixed value instead of the actual sprite
// height to avoid jumps due to irregular sprite sizes
#define charheight 105
void CenterScreen(float step) {
float x = IntToFloat(player.x - System.ViewportWidth/2);
float y = IntToFloat(player.y - System.ViewportHeight/2 - charheight/2);
float dx = (x-vpx)*step; if (dx*dx < 0.01) dx = 0.0;
float dy = (y-vpy)*step; if (dy*dy < 0.01) dy = 0.0;
vpx += dx;
vpy += dy;
SetViewport(FloatToInt(vpx), FloatToInt(vpy));
}
void on_event(EventType event, int data) {
if (event == eEventEnterRoomBeforeFadein) CenterScreen(1.0);
}
void repeatedly_execute() {
CenterScreen(0.1);
}
You can adjust the 0.1 at the very end to change how lazy the camera is. 0.2 produces relatively smooth but strict scrolling, 0.03 tweens the camera to the new position in around 2 seconds.
Thanks khris, I gave it a try but I seem to only get the top part of the room(most likely 320 x 200
I tested it with a 320x480 room in a 320x240 game. Worked flawlessly.
Then I imported your room and sprite, drew the walkable area and tested it again. And again, it looked just fine and worked flawlessly. The camera scrolls so that the character is centered, just like it's supposed to.
To be sure, I then changed the game's resolution to 320x200. Again, perfect scrolling so the character is always centered.
I'm not sure what you mean by "you get only the top part", are you saying your viewport's y is stuck being 0?
Are you using any other modules that might interfere?
If you want to shift the viewport center, change the value of charheight at the top of the script. 0 is the default value AGS uses. Use something like 50 to move the viewport down.
Also, would you please try and give clear feedback, with screenshots or something, not just a one-liner that I have to decode first?
It works and it even has that smooth scrolling effect like I wanted to add from the start. However it's being blocked by the first entry room. The view is locked at the at one the view it was entered in from. And it doesn't fix it self until I gain control of the player again.
Quote from: S3 on Tue 22/11/2011 00:02:32
It works and it even has that smooth scrolling effect like I wanted to add from the start. However it's being blocked by the first entry room(the room seen above has a cutscene right at the start of the game). The view is locked at the at one the view it was entered in from. And it doesn't fix it self until I gain control of the player again.
oops I made a mistake and quoted myself while I was trying to add on to my text.
I will compile the game up and send it over to you if that will help.
Ok, so there's a cutscene running?
Just open my script and turn "repeatedly_execute" into "repeatedly_execute_always", the former isn't run during blocking stuff.
I used that and this and it seemed to fixed the problem
void CenterScreen(float step) {
if(btnInvDown.Visible == true){
}
else if(btnInvDown.Visible == false){
float x = IntToFloat(player.x - System.ViewportWidth/2);
float y = IntToFloat(player.y - System.ViewportHeight/2 - charheight/2);
float dx = (x-vpx)*step; if (dx*dx < 0.01) dx = 0.0;
float dy = (y-vpy)*step; if (dy*dy < 0.01) dy = 0.0;
vpx += dx;
vpy += dy;
SetViewport(FloatToInt(vpx), FloatToInt(vpy));
}
}
Yeah, you might want to disable my script altogether on occasion.
It looks like you're using a button as a global variable though.... if it works for you, I guess...
Also, a simply "else" is enough here; apart from Visible == true and Visible == false being mutually exclusive, there isn't a third option either.
Also, indentation:
void CenterScreen(float step) {
if(btnInvDown.Visible == true){
}
else if(btnInvDown.Visible == false){
float x = IntToFloat(player.x - System.ViewportWidth/2);
float y = IntToFloat(player.y - System.ViewportHeight/2 - charheight/2);
float dx = (x-vpx)*step; if (dx*dx < 0.01) dx = 0.0;
float dy = (y-vpy)*step; if (dy*dy < 0.01) dy = 0.0;
vpx += dx;
vpy += dy;
SetViewport(FloatToInt(vpx), FloatToInt(vpy));
}
}
Also, all you need is this:
if (btnInvDown.Visible) return; // exit the function
Ok, I think my problems are over. Also before I mark this as , am I supposed to place that needed line inside that void?
Ideally, you create a global bool variable named scrolling_disabled, then use my original code and this instead of its repeatedly_execute:
void repeatedly_execute_always() {
if (!scrolling_disabled) CenterScreen(0.1);
}
Then call scrolling_disabled = true; to deactivate the module.
Ok I get now. Thanks Khris for the help :)