Move room image in the editor

Started by jomalin, Thu 27/11/2014 22:52:37

Previous topic - Next topic

jomalin

Hi, i'm a computer programmer, but i am completely new in AGS. Sorry about my english please.

I want to try doing a 320x200 adventure game. I have successfully loaded a large room that is 1280 x 128 pixels, so obviously, it has horizontal scrolling to make the character walk around all that room, but as the height of the room is 128, and my game height is 200, there is a black border below the room, so the question is, can i move the room vertically in the editor, to have a black border upside and downside of the room? I don't see any option to let me move the room in the editor in the Y axis (neither in the X axis). I know i can do an image for the room having 200 pixels of height and adjust the room pixels inside my image, but i would like to have the posibility to move the room instead. That will let me to have smaller rooms images and smaller game size.

THANKS!

formica

Hey, I don't think there's a way to do this in the editor (maybe someone else knows?) But you could do it manually using SetViewport. Something like this in the room repeatedly execute function:

Code: ags

SetViewport((player.x - 160), desired y coord);


The saving in image size may not be worth it though.

Crimson Wizard

jomalin, for some reason AGS does not support having room image smaller than the chosen game resolution. AFAIK people usually just make black borders around actual room background. This does add to resource size, but should not add that much because of the bitmap compression (since black color is all zeroes).

I am not sure why it was made this way; I suppose this restriction could be removed with certain effort, its just that not many people complain about this.

Monsieur OUXX

Quote from: Crimson Wizard on Fri 28/11/2014 08:37:02
AFAIK people usually just make black borders around actual room background
Definitely the solution.
 

jomalin

#4
Quote from: Crimson Wizard on Fri 28/11/2014 08:37:02
jomalin, for some reason AGS does not support having room image smaller than the chosen game resolution.
AGS let me import the room that is 1280x128! (not those images i posted here). It makes me black borders automatically downside of the room (to add 72 pixels of black border (200-128)).

Thank you for your responses.

I'm trying to mimic the Maniac Mansión behaviour ("engine") in AGS, so i have analized and measured some things: you can only move the mouse arrow every 8 pixels in the X axis, but pixel by pixel in the Y axis, the characters moves every 8 pixels also in the X axis, also i have created a ttf font with the letters from the game and they are pixel perfect, etc. I am so perfectionist, and also as i do computer programming, i always like to do things in the more optimal way... So this is my visual explanation, there is 16 pixels upside the room and 56 downside the room:


And the room itself (128 of height):


If it is not possible, maybe it will be good to add this suggestion: have the possibility to enter the initial position (X and Y) of each room in the editor (and also make possible to get and set it from scripting). That will let us:

- having clear image rooms
AND THE MOST IMPORTANT:
- if in some part of the game development, we change the GUI dimensions (verbs panel), only changing two constants from our code (X and Y position value for all of our rooms), will make all the rooms fit perfectly with the modified GUI, instead of changing each of our room images in a image editor to add or supress black borders...

NOTE: Rooms internally in Maniac Mansion are stored as 128 pixeles of height (room without any borders), it is drawn 16 pixels down starting from the top of the screen by code (see my first image).

Tell me your opinion

THANKS!

Gurok

#5
You could use a custom property for this. Click the Properties (Properties) entry in the properties list of the room you're editing. Click Edit Schema..., then right click to add a new property. In your case, something like OffsetY with a default of 16. You could then adjust the viewport in the on_event function (eEventEnterRoomBeforeFadein).

Edit: formica's SetViewport suggestion didn't seem to work for me. You might be better off with a functions like this:

Code: ags
function ShiftRoomY(int offsetY)
{
	DynamicSprite *background;
	DrawingSurface *surface;

	background = DynamicSprite.CreateFromBackground();
	surface = Room.GetDrawingSurfaceForBackground();
	surface.Clear(0);
	surface.DrawImage(0, offsetY, background.Graphic);
	surface.Release();

	return;
}

function on_event(EventType event, int data)
{
	if(event == eEventEnterRoomBeforeFadein)
		ShiftRoomY(GetRoomProperty("OffsetY")); // You would need to define this first in the schema as outlined above

	return;
}
[img]http://7d4iqnx.gif;rWRLUuw.gi

jomalin

#6
Quote from: Gurok on Fri 28/11/2014 18:12:07
You could use a custom property for this. Click the Properties (Properties) entry in the properties list of the room you're editing. Click Edit Schema..., then right click to add a new property. In your case, something like OffsetY with a default of 16. You could then adjust the viewport in the on_event function (eEventEnterRoomBeforeFadein).

Edit: formica's SetViewport suggestion didn't seem to work for me. You might be better off with a functions like this:

Code: ags
function ShiftRoomY(int offsetY)
{
	DynamicSprite *background;
	DrawingSurface *surface;

	background = DynamicSprite.CreateFromBackground();
	surface = Room.GetDrawingSurfaceForBackground();
	surface.Clear(0);
	surface.DrawImage(0, offsetY, background.Graphic);
	surface.Release();

	return;
}

function on_event(EventType event, int data)
{
	if(event == eEventEnterRoomBeforeFadein)
		ShiftRoomY(Room.GetProperty("OffsetY")); // You would need to define this first in the schema as outlined above

	return;
}


Thanks a lot Gurok, it Works!

But it is to be written like this (i am using last AGS: v3.3.2, maybe some objets and methods have changed):

function on_event(EventType event, int data)
{
   if(event == eEventEnterRoomBeforeFadein)
      ShiftRoomY(GetRoomProperty("OffsetY")); // You would need to define this first in the schema as outlined above
   return;
}

Gurok

#7
Quote from: jomalin on Fri 28/11/2014 18:59:02
Thanks Gurok, i have added that property to my room correctly but now, where i write your code? I wrote it to the "Room script" and it gives me an error:
Undefined token 'ShiftRoomY'

Looks like it is not taking the ShiftRoomY function... Why?

You should be able to add that code to your global script and have it work for every room. Make sure ShiftRoomY occurs before on_event in the code (as shown above).

EDIT: Oh yes, GetRoomProperty is actually the correct function. I was working with a future version of the engine.

Code: ags
function ShiftRoomY(int offsetY)
{
        DynamicSprite *background;
        DrawingSurface *surface;

        background = DynamicSprite.CreateFromBackground();
        surface = Room.GetDrawingSurfaceForBackground();
        surface.Clear(0);
        surface.DrawImage(0, offsetY, background.Graphic);
        surface.Release();

        return;
}

function on_event(EventType event, int data)
{
        if(event == eEventEnterRoomBeforeFadein)
                ShiftRoomY(GetRoomProperty("OffsetY")); // You would need to define this first in the schema as outlined above

        return;
}
[img]http://7d4iqnx.gif;rWRLUuw.gi

jomalin

Quote from: Gurok on Fri 28/11/2014 19:01:46
Quote from: jomalin on Fri 28/11/2014 18:59:02
Thanks Gurok, i have added that property to my room correctly but now, where i write your code? I wrote it to the "Room script" and it gives me an error:
Undefined token 'ShiftRoomY'

Looks like it is not taking the ShiftRoomY function... Why?

You should be able to add that code to your global script and have it work for every room. Make sure ShiftRoomY occurs before on_event in the code (as shown above).

EDIT: Oh yes, GetRoomProperty is actually the correct function. I was working with a future version of the engine.

Code: ags
function ShiftRoomY(int offsetY)
{
        DynamicSprite *background;
        DrawingSurface *surface;

        background = DynamicSprite.CreateFromBackground();
        surface = Room.GetDrawingSurfaceForBackground();
        surface.Clear(0);
        surface.DrawImage(0, offsetY, background.Graphic);
        surface.Release();

        return;
}

function on_event(EventType event, int data)
{
        if(event == eEventEnterRoomBeforeFadein)
                ShiftRoomY(GetRoomProperty("OffsetY")); // You would need to define this first in the schema as outlined above

        return;
}


It Works but now the walkable area of that room does not fit :-( I must also move all the areas of the room by code (walkable área, edges, etc)? :-(

Gurok

:-( I'm sorry, I didn't think of this. You're probably better off padding your room image instead. There's currently no way to draw walkable areas and edges at runtime. If the SetViewport function interpreted negative coordinates and centred the view accordingly, that would be ideal. Right now though, I think your best bet is to modify the image, sorry.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Scavenger

I believe room background images are compressed, however, and by adding areas of pure black at the top and bottom, you're not likely to get much in the way of file size savings if you omit them and use code to compensate. I don't remember whether the compression algorithm is RLE or LZW (I THINK it's LZW? I know RLE is the sprite one), but it will compress large areas of flat colour incredibly well. You're likely to see little to no size increase if you buffer them with black areas. Likely at most around a few bytes per image.

Crimson Wizard

Quote from: jomalin on Fri 28/11/2014 16:07:25
Quote from: Crimson Wizard on Fri 28/11/2014 08:37:02
jomalin, for some reason AGS does not support having room image smaller than the chosen game resolution.
AGS let me import the room that is 1280x128! (not those images i posted here). It makes me black borders automatically downside of the room (to add 72 pixels of black border (200-128)).

Let me elaborate: AGS engine does not support having room image smaller than the chosen game resolution. That's why Editor automatically increases the room size, producing black borders, but only at the right and bottom side.

I accept your suggestion about letting developer to specify room offset on screen; that is something I was thinking about some time ago too.
Can't tell if that will be easy to do, AGS program code is pretty tangled one.

jomalin

Quote from: Scavenger on Fri 28/11/2014 19:42:57
I believe room background images are compressed, however, and by adding areas of pure black at the top and bottom, you're not likely to get much in the way of file size savings if you omit them and use code to compensate. I don't remember whether the compression algorithm is RLE or LZW (I THINK it's LZW? I know RLE is the sprite one), but it will compress large areas of flat colour incredibly well. You're likely to see little to no size increase if you buffer them with black areas. Likely at most around a few bytes per image.

Yes, file size will not be so much with compression, but the second point i told, is the main reason: if you modify the GUI (a verb panel for example) to a bigger one, now you must resize all the rooms to fit with it, so having the clear room and moving it by code will save so many time retouching each of the rooms.

jomalin

Quote from: Crimson Wizard on Fri 28/11/2014 20:51:01
I accept your suggestion about letting developer to specify room offset on screen; that is something I was thinking about some time ago too.
Thank you for accepting my suggestion! Does i need to paste it on any web or to-do list?

Quote from: Crimson Wizard on Fri 28/11/2014 20:51:01
Can't tell if that will be easy to do, AGS program code is pretty tangled one.

Are you planning to do a completely rewritte of AGS to have clear source code? As you know, having tangled code make software having many bugs and more difficult to make modifications when it's needed.

Gurok

Quote from: jomalin on Sat 29/11/2014 09:29:14
Are you planning to do a completely rewritte of AGS to have clear source code? As you know, having tangled code make software having many bugs and more difficult to make modifications when it's needed.

http://www.joelonsoftware.com/articles/fog0000000069.html
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

#15
Quote from: jomalin on Sat 29/11/2014 09:29:14
Quote from: Crimson Wizard on Fri 28/11/2014 20:51:01
I accept your suggestion about letting developer to specify room offset on screen; that is something I was thinking about some time ago too.
Thank you for accepting my suggestion! Does i need to paste it on any web or to-do list?
You may post it here: http://www.adventuregamestudio.co.uk/forums/index.php?project=3;area=issues


Quote from: jomalin on Sat 29/11/2014 09:29:14Are you planning to do a completely rewritte of AGS to have clear source code? As you know, having tangled code make software having many bugs and more difficult to make modifications when it's needed.
Me, personally, no. I am afraid I simply won't have enough free time for this. To be honest, I also don't have enough trust in my abilities.
So I am gradually cleaning the code, but most time I stick to the plan of minimal modifications when possible.

BTW, I do not completely agree with the statement in the article Gurok referenced :). I WOULD rewrite AGS, or rather completely new system from scratch, if I had stronger belief that 1) I can; 2) I won't be alone doing this; 3) This product will be able to provide good alternative to already existing solutions (like already existing AGS, Visionair Studio etc).

Cassiebsg

Okay, that explains why Netscape "disappeared" from my computer. (roll)
There are those who believe that life here began out there...


jomalin

Quote from: Gurok on Sat 29/11/2014 09:30:48
Quote from: jomalin on Sat 29/11/2014 09:29:14
Are you planning to do a completely rewritte of AGS to have clear source code? As you know, having tangled code make software having many bugs and more difficult to make modifications when it's needed.

http://www.joelonsoftware.com/articles/fog0000000069.html

Hi Gurok, why did you post that link about Netscape? Sorry, i don't understand what are you trying to say me with that.

Gurok

Quote from: jomalin on Wed 03/12/2014 07:04:23
Quote from: Gurok on Sat 29/11/2014 09:30:48
Quote from: jomalin on Sat 29/11/2014 09:29:14
Are you planning to do a completely rewritte of AGS to have clear source code? As you know, having tangled code make software having many bugs and more difficult to make modifications when it's needed.

http://www.joelonsoftware.com/articles/fog0000000069.html

Hi Gurok, why did you post that link about Netscape? Sorry, i don't understand what are you trying to say me with that.

I'm just saying that it's not always a good idea to completely rewrite source code. Specifically, I think "having tangled code make software having many bugs" isn't necessarily true. AGS may be ugly, but it's been tested thoroughly. In the article, Joel talks about this under "It's harder to read code than to write it".
[img]http://7d4iqnx.gif;rWRLUuw.gi

SMF spam blocked by CleanTalk