Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Text hovering above inventory object; anti-aliased fonts  (Read 6656 times)

0 Members and 1 Guest are viewing this topic.

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Text hovering above inventory object; anti-aliased fonts
« on: May 30, 2004, 03:42:27 PM »

I've got two minor questions.

Firstly, am I limited to using .bmps for fonts? Or can I use a png not with a pink background, but just a transparent background so I can have nice smooth edges? The same question goes for character sprites, actually. (The game's own alpha blending is a little weak considering how pixelated the edges of my character still are :) )

Secondly, I'm trying to project some text on top of an inventory object. You see, I need to have a lot of similar inventory objects except with a different word on top of them, and I need the text to stay dynamic. Don't ask why, heh. What's the proper approach for this? I gather I should place a window of the same size on top of the inventory object and put the text in it, but I'm not sure where to put the code that refers to this window. If you've got a rough starter, that would be cool.

Edit: oh, and here's another question.
I need inventory items to play a little animation when they appear. That's easy. But I also need some of them to fade them out and make a sound when they are dropped. This can either be an animation or a fade that's coded (whatever does the trick). I take it I have to write some kind of loop that decreases the alpha of the item until it's at 0. Again, I am probably already on the right line of thought, but I am always a little hamstrung when I have to decide where to put this code, where to reference it, and so on. A little help on this would be awesome!
« Last Edit: May 30, 2004, 03:49:01 PM by Marek »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #1 on: May 30, 2004, 04:21:52 PM »

Firstly, am I limited to using .bmps for fonts? Or can I use a png not with a pink background, but just a transparent background so I can have nice smooth edges? The same question goes for character sprites, actually. (The game's own alpha blending is a little weak considering how pixelated the edges of my character still are :) )

No, you are not limited to BMPs. You can use PNG and TGA files with an alpha channel.


Secondly, I'm trying to project some text on top of an inventory object. You see, I need to have a lot of similar inventory objects except with a different word on top of them, and I need the text to stay dynamic. Don't ask why, heh. What's the proper approach for this? I gather I should place a window of the same size on top of the inventory object and put the text in it, but I'm not sure where to put the code that refers to this window. If you've got a rough starter, that would be cool.

Well, I guess it *could* be scripted, but IMHO it would be quite difficult (depending on the the "layout" of your inventory). I added the ability to display an amount number beside the inventory items, so I think the easiest way will be to allow the user to set this amount string to watever he wants to display. I intended to do this before anyway, but I forgot :) So unless you want this feature very quickly, I recommend we go this way, ok?


Edit: oh, and here's another question.
I need inventory items to play a little animation when they appear. That's easy. But I also need some of them to fade them out and make a sound when they are dropped. This can either be an animation or a fade that's coded (whatever does the trick). I take it I have to write some kind of loop that decreases the alpha of the item until it's at 0. Again, I am probably already on the right line of thought, but I am always a little hamstrung when I have to decide where to put this code, where to reference it, and so on. A little help on this would be awesome!

The inventory items are now fully scriptable so you can set their AlphaColor attribute. The most ellegant way would be to override the Game.DropItem or Game.DeleteItem methods and incorporate the fading into them.

For example, if you add the following method to your game.script, then all your Game.DeleteItem() calls will automatically fade out the items before destroying them.

[code]
////////////////////////////////////////////////////////////////////////////////
method DeleteItem(var ItemName)
{
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #2 on: May 30, 2004, 04:38:28 PM »

Quote
So unless you want this feature very quickly, I recommend we go this way, ok?
Sorry if this will make me sound retarded, but to recap: you're saying that amount accepts strings besides just numbers, so although the amount feature wasn't intended for what I want to do, I could use this for now? (Fine by me, heh. Whatever gets it to work!)

As for the fade out code, awesome. Thank you!

Sadly, a new issue arised. After having worked on my inventory all afternoon, it doesn't seem to display items. :-\

FYI, here's the related bits of code:

inventory.def:
Quote
INVENTORY_BOX
{
  ITEM_WIDTH = 65
  ITEM_HEIGHT = 65
  SPACING = 10
  SCROLL_BY = 1
  HIDE_SELECTED = TRUE

  AREA { 30, 522, 620, 587 }
  EXCLUSIVE = FALSE
;  ALWAYS_VISIBLE = TRUE

  WINDOW
  {
    X = 0
    Y = 510
    WIDTH = 650
    HEIGHT = 90
    IMAGE = "interface\inventory.bmp"
 
    BUTTON
    {
      NAME = "prev"

      IMAGE = "ui_elements\inventory_left_normal.bmp"
      IMAGE_HOVER = "ui_elements\inventory_left_normal.bmp"
      IMAGE_PRESS = "ui_elements\inventory_left_pressed.bmp"
      IMAGE_DISABLE = "ui_elements\inventory_left_disabled.bmp"
      IMAGE_FOCUS = "ui_elements\inventory_left_normal.bmp"

      WIDTH = 27
      HEIGHT = 27
      X = 0
      Y = 32
    }

    BUTTON
    {
      NAME = "next"

      IMAGE = "ui_elements\inventory_right_normal.bmp"
      IMAGE_HOVER = "ui_elements\inventory_right_normal.bmp"
      IMAGE_PRESS = "ui_elements\inventory_right_pressed.bmp"
      IMAGE_DISABLE = "ui_elements\inventory_right_disabled.bmp"
      IMAGE_FOCUS = "ui_elements\inventory_right_normal.bmp"

      WIDTH = 27
      HEIGHT = 27
      X = 623
      Y = 32
    }
  }
}

from game.script:
Quote
// initial items
Game.TakeItem("money");

item definition and sprites for the money item = identical to the demo

I made a minor adjustment to game_deamon.script:
Quote
  // display the inventory window
  if(Game.Interactive && Game.MouseY < 45 && !Game.ResponsesVisible && !WinMenu.Visible) Game.InventoryVisible = true;
  else if(Game.MouseY > 100 || Game.ResponsesVisible || !Game.Interactive) Game.InventoryVisible = false;

So that it's always on-screen (like in Monkey Island 2 or whatever).

However, I see no money :-\ Any ideas?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #3 on: May 30, 2004, 04:45:16 PM »

Sorry if this will make me sound retarded, but to recap: you're saying that amount accepts strings besides just numbers, so although the amount feature wasn't intended for what I want to do, I could use this for now? (Fine by me, heh. Whatever gets it to work!)

Err, no :) I meant I'll need to modify the code. Currently it only displays numbers.


As for the inventory, I don't see anything wrong, does the log file say anything?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #4 on: May 30, 2004, 04:55:14 PM »

Ah, okay. Yeah I can wait for that. I have to demo the game to my teachers on thursday but I can "fake" the idea for now.

The log is clean.

For what it's worth, here's my inventory image. Basically the same as yours (in the demo) except with 2 slots less to make room for other stuff.
www2.hku.nl/~marek2/images2/inventory.bmp
Logged

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #5 on: May 30, 2004, 04:57:29 PM »

is the area between "prev" and "next" with the inventory slots supposed to be "<unnamed>" ?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #6 on: May 30, 2004, 05:10:46 PM »

Oh, I see it now. The "area" rectangle is relative to the window's coordinates, not the screen, i.e. change the area back to the values from WME demo and it should work.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #7 on: May 30, 2004, 06:11:47 PM »

Woo hoo!
Logged

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #8 on: May 30, 2004, 07:21:51 PM »

I'm trying to make a fade in now.

Quote
method TakeItem(var ItemName)
{
  // get the item
  var Item = this.GetItem(ItemName);
  if(Item==null) return;
 
  // fade it in
  for(var i=0; i<=225; i=i+10)
  {
    Item.AlphaColor = RGB(255, 255, 255, i);
    Sleep(20);
  }

  // call the original method we have just overriden
  this.TakeItem(ItemName);
}

That should work, but it doesn't. I probably need more coffee. Any ideas?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #9 on: May 30, 2004, 08:53:13 PM »

Put the original TakeItem call to the beginning of the method, so that the item is taken first and can be queried.
Like this:

Code: [Select]
method TakeItem(var ItemName)
{
  // call the original method we have just overriden
  this.TakeItem(ItemName);

  // get the item
  var Item = this.GetItem(ItemName);
  Game.Msg(Item);
  if(Item==null) return;
 
  // fade it in
  for(var i=0; i<=225; i=i+10)
  {
  Game.Msg(i);
    Item.AlphaColor = RGB(255, 255, 255, i);
    Sleep(20);
  } 
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Text hovering above inventory object; anti-aliased fonts
« Reply #10 on: May 30, 2004, 09:44:23 PM »

Ahhh of course, with taking it, that comes first as opposed to last. Makes complete sense. Thanks!
Logged
 

Page created in 0.046 seconds with 20 queries.