Move a whole View's x and y position **SEMI-SOLVED**

Started by Knox, Fri 27/08/2010 23:06:30

Previous topic - Next topic

Knox

Hi guys,

Im not sure if this is a simple one, but seems to me it should be pretty easy.

I looked up view and viewframe but  I didnt seem to find the "x,y" property of a view. Right now Im showing a view over a gui for a custom portrait animation and Id like to change the view's position directly (not creating a new gui, and moving the gui)...is this possible?

The view in question is a series of sprites smaller than the base of the portrait so I dont have to use large sprites for parts that arent animating.

Hope this makes sense, if not I can clarify with pics.
--All that is necessary for evil to triumph is for good men to do nothing.

GarageGothic

Strictly speaking, Views aren't on-screen objects but just a way to structure animation frames that you then assign to an Object, Character, Button, Cursor etc. with its own coordinates. It would be lovely to have custom coordinate offsets for Views and individual Frames (like SCUMM did two decades ago ;)), but there's no such thing in AGS yet.

Are you using standard Sierra portraits, or the custom dialog module with portraits? If the latter, you could just create a new button in that GUI and use that to display the smaller sprites - though you'd have to move it around in script if it changes size/position.

Knox

#2
Ah ok, too bad we didnt have that feature, could be really time saving! Imagine being able change a view's x,y position from within the view editor in relation to what its attached to! Has someone asked if we can add that in the next release? If not, I think I will!
Right now I just have sprites for the face, the rest is just a static image.

Ok, Ill look into what you suggested then for creating a button in the custom gui module...Im also using GuiPortrait that I already modified a bit to add a background behind the animated views so I can change character's clothes without having to make a gazillion animated sprites for each change :P

**EDIT**

Ok, well here is where I'm at...Ive got the "face" view animation appearing in the top left corner of the gui cause its directly drawn onto that surface (I think?)...Ive got the buttons setup, which later, will move depending on the character, but Ill get to that later. Also, Ive got a background gui behind everything that also appears under the view, and this gui's background image will also update when the other dialog partner talks...



What Im not sure how to do is how do I actually draw that view onto the button itself? Also, if I draw the view on the button, will the text move with it? Id like the text to be displayed off-set from the border of the portrait, not the button...if you look at the image up top, notice how the text box is close to the "face" view...of course if I make the "face view" the full size of  the actual portrait frame, it will be OK, but Im trying to avoid that to save sprite-size space.

Im guessing using btn.Animate, but Im not too sure how to modify the module further to get this to work. Here is what Ive got so far:

**ACL MODIFICATIONS are what I added.

Code: ags

// GuiPortrait module script 
//MODIFIED ACL 27/08/2010

function game_start() 
{
  gPortrait.Visible = false;
  Portrait_Sierra_Y = 57; 
  Portrait_Left_Indent = 20;
  Portrait_Right_Indent = 10; 
  Portrait_Counter = -1;
  Portrait_BlinkTimer = -1;
#ifdef PORTRAIT
  Portrait_GUI = gPortrait;
#endif
  BasePortrait_GUI = gBasePortrait; //ACL MODIFICATIONS
  BasePortrait_GUI.BackgroundGraphic = 1087; //ACL MODIFICATIONS
}

function DialogPartner(Character *dialogPartner2)
{
  partner = dialogPartner2;
}

function Portrait_DoFrame() 
{
  //this will eventually be a variable called from startDialog in DialogFunctions_ACL
  BasePortrait_GUI.BackgroundGraphic = iBasePortrait;  //ACL MODIFICATIONS
  //move the player's view in the right position onto face
  
  Portrait_vf = Game.GetViewFrame(Portrait_View, Portrait_Loop, Portrait_Frame);
  bool flip = Portrait_vf.Flipped;
  // Something like:
  if (Portrait_AutoFlip && Portrait_AtRight) flip =! flip;
  Portrait_Mod = DynamicSprite.CreateFromExistingSprite(Portrait_vf.Graphic, true);
  if (Portrait_BlinkTimer == 0) 
  {
    DrawingSurface *mod = Portrait_Mod.GetDrawingSurface();
    Portrait_bvf = Game.GetViewFrame(Portrait_BlinkView, Portrait_BlinkLoop, Portrait_BlinkFrame);
      
    mod.DrawImage(0, 0, Portrait_bvf.Graphic);
    mod.Release();
      
    Portrait_BlinkFrame++;
    if (Portrait_BlinkFrame == Game.GetFrameCountForLoop(Portrait_BlinkView, Portrait_BlinkLoop)) 
    {
      Portrait_BlinkTimer = Portrait_BlinkInterval;
      Portrait_BlinkFrame = 0;
    }
  }
  // Flip AFTER blink, if required
  if (flip) Portrait_Mod.Flip(eFlipLeftToRight);
  Portrait_GUI.BackgroundGraphic = Portrait_Mod.Graphic;
}

function repeatedly_execute_always() 
{
  if (Portrait_Counter == 0) 
  {
    Portrait_Frame++;
    if (Portrait_Frame == Game.GetFrameCountForLoop(Portrait_View, Portrait_Loop)) Portrait_Frame = 0;
    Portrait_DoFrame();
    Portrait_Counter = (Portrait_AnimSpeed + Portrait_vf.Speed + 1);
  } 
  else if (Portrait_Counter >= 0) Portrait_Counter--;
  if (Portrait_BlinkTimer > 0) Portrait_BlinkTimer--;   
}

// TBD: Animate
// Check for flipped frames
// Blinking: goes on top of speech view

function GSay(this Character*, String what, int view, int loop) 
{
  if (view < 1) view = this.SpeechView;
  Portrait_Frame = 0;
  Portrait_Loop = loop;
  Portrait_View = view;
  Portrait_AnimSpeed = this.SpeechAnimationDelay;
    
  int positioning = GetGameOption(OPT_PORTRAITPOSITION);
  int x;
    
  //Left
  if (positioning == 0) Portrait_AtRight = false;
  //Right
  else if (positioning == 1) Portrait_AtRight = true;
	//Alternate
  else if (positioning == 2)
  {
    if (this != Portrait_Last_Talker) Portrait_AtRight =! Portrait_AtRight;
  }
  // Based on Character Position Relation to the Main Player
  else
  { 
    if (this == player)
    {
      if (partner == null)//means its a dialog with dispatch
      {
        if (Portrait_Last_Talker != null && this != Portrait_Last_Talker) Portrait_AtRight = this.x > Portrait_Last_Talker.x;
        else 
        {
          if (this.x < (System.ViewportWidth/2)) Portrait_AtRight = false;
          else Portrait_AtRight = true;
        }          
      }
      else
      {
        if (this.x <= partner.x) Portrait_AtRight = false;
        else if (this.x > partner.x) Portrait_AtRight = true;
      }
    } 
    else
    {
      if (this.x >= player.x) Portrait_AtRight = true;
      else if (this.x < player.x)Portrait_AtRight = false;
    }  
  }
  Portrait_DoFrame();

  if (Portrait_AtRight == true) x = (System.ViewportWidth - Game.SpriteWidth[Portrait_vf.Graphic] - Portrait_Right_Indent);
  else if (Portrait_AtRight == false) x = Portrait_Left_Indent; 
		
  Portrait_GUI.X = x;
  Portrait_GUI.Y = Portrait_Sierra_Y;
  
  BasePortrait_GUI.X = x; //ACL MODIFICATIONS
  BasePortrait_GUI.Y = Portrait_Sierra_Y; //ACL MODIFICATIONS 
  
  SetGameOption(OPT_PORTRAITPOSITION, Portrait_AtRight);
  
  BasePortrait_GUI.Visible = true; //ACL MODIFICATIONS 
  
  Portrait_GUI.Visible = true;
  Portrait_Counter = (Portrait_AnimSpeed + Portrait_vf.Speed + 1);
    
  if (this.BlinkView > 0) 
  {
    Portrait_BlinkTimer = this.BlinkInterval;
    Portrait_BlinkInterval = this.BlinkInterval;
    Portrait_BlinkView = this.BlinkView;
    Portrait_BlinkLoop = 0;
    Portrait_BlinkFrame = 0;
  }
  else Portrait_BlinkTimer = -1;
  
  this.Say(what);
    
  BasePortrait_GUI.Visible = false; //ACL MODIFICATIONS 
  
  Portrait_GUI.Visible = false;
  SetGameOption(OPT_PORTRAITPOSITION, positioning);
  Portrait_Counter = -1;
  Portrait_BlinkTimer = -1;
}

--All that is necessary for evil to triumph is for good men to do nothing.

Knox

Sorry for two posts one after the other but I noticed something in explorer and I was wondering if its a bug or not...look at these 3 images:





The smaller sprite (07.PNG) is 88x105, and its size is 22.0kb...but the one above it is way bigger but its smaller in size; 13.0 kb...

Why? If this is the case, then I think Ive solved the problem and Ill just make the sprites like the 2nd sprite, magic-pink all around the animated mouth area. I thought I was going to save in memory by reducing the animated sprites to a small area, but looks like its not the case !(?)
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

PNG uses lossless compression; big areas using only one color will decrease the filesize dramatically.

Knox

hmm interesting...I looked up lossless compression...

Well Ill just do it that way then, instead of trying to find a way to move smaller sprites inside views, etc...since the full-size sprite with 1 color in a large area is actually smaller than the small sprite, its not worth it to screw around trying to get the animation on a button.

Oh, I dont know if people are aware of this free program but it seems cool for optimizing png's:
http://benhollis.net/software/pnggauntlet/

Also, there's this plugin for photoshop (not free) that saves png's smaller than the photoshop's standard png plugin:
http://www.ardfry.com/png-plugin/
--All that is necessary for evil to triumph is for good men to do nothing.

Gilbert

Quote from: general_knox on Mon 30/08/2010 00:10:48
... optimizing png
...plugin

That doesn't matter, if you're making an AGS game. This is because AGS would use internally its own compression algorithms on its graphics (RLE for sprites, if 'compress sprite file' is checked, and 'something better' for backgrounds), so no matter what you use for storing the graphic files for import it won't affect the size of the AGS game. Of course, still, graphics with large area of flat colours would make a smaller game.

Knox

#7
ah crap, serious...

Well if I import a png thats 120kb, and one that is 60kb...doesnt AGS still compress both at a certain %...so the 120kb becomes (say) 60kb, and  the 60kb becomes 30kb...? So wouldnt it still be better to make sure the sprites are as small as possible before importing into AGS?

If I understand correctly then, if I import an uncompressed png (120kb), AGS will compress it as if I already did it manually with an external program (like png gauntlet)...and ends up, say, 60kb...so If I imported tha compressed png into AGS, that sprite wont be further compressed cause its already at its maximum compression...right?
--All that is necessary for evil to triumph is for good men to do nothing.

Gilbert

Don't consider this too complicated. The point is, no matter what format you save your graphics files in, it makes no difference in the game's size, as long as the image is the same. So, don't waste your time in finding plugins/programmes that tend to pack an image better to produce a smaller file.

Take this as an example:
You save the same image as a BMP file and a PNG file. As the BMP format is not compressed (99% of the time), the BMP file will obviously be larger in file size in comparison to the PNG. However, if you import the image as a sprite in AGS, the file size would be the same regardless of the format the original image was saved in.
Quote from: general_knox on Mon 30/08/2010 02:54:28
If I understand correctly then, if I import an uncompressed png (120kb), AGS will compress it as if I already did it manually with an external program (like png gauntlet)...and ends up, say, 60kb...so If I imported tha compressed png into AGS, that sprite wont be further compressed cause its already at its maximum compression...right?
It does not really work like this. It will just take whatever the image is like (not the file) and compress it with its own algorithm. So, for your "that sprite wont be further compressed cause its already at its maximum compression" part it's practically incorrect. What AGS does, is that you may assume it first expands the images to their uncompressed, raw format and then compresses them with its own algorithms. Since AGS uses RLE for sprites, which is a far, far inferior scheme than those used in PNGs, you'll expect that the sprites would take up more space in the game than the original PNG file.

Knox

ok, so its pretty much a waste of time then compressing files with external programs/plugins before importing them into AGS...

I guess then what's left for me to optimize, sprite wise, is the number of sprites :P
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk