Bring Object To Front

Started by DrewCCU, Sat 15/05/2010 04:48:13

Previous topic - Next topic

DrewCCU

Okay - so I have a bunch of identical objects with minor changes made to each object (so they arent exactly identical but they are all the same size - put it that way).  I've stacked them directly on top of each other in my room.  For the sake of argument, just go with me on this next part:

Based on what the player does, a new object will appear.  So if there were only 2 objects it may work something like this:

Player does Thing1
  Object1.visible=true
  Object2.visible=false
(this will make it so when player does thing1 object 1 will appear and in case object2 was visible - it is set to disappear ... just in case it was there)

also works vice versa
Player does Thing2
  Object2.visible=true
  Object1.visible=false


This would be just fine if i ONLY had 2 or 3 or even 4 objects.  But i'm using A LOT of objects. So to reduce the size of the code i was hoping i could do something where all the objects could stay visible on the screen (instead of turning the uneeded ones off) ... and since all the objects are the same size when player does thing1 object1 would be "brought to the top/front" and all of the objects below it would no longer be seen.  I tired playing with the baseline function but i couldnt get it to work just right.  I know there has to be a way to do this with objects ... right?
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

ThreeOhFour

Couldn't you just change the graphic of a single object, then check the interactions against the graphic of the object?

Ie:

Code: ags

hButton_interact()
{
  if (object[1].Graphic != 70)
  {
    object[1].Graphic ++;
  }
else object[1].Graphic = 50;
}

hButton2_interact()
{
  if (object[1].Graphic != 50)
  {
    object[1].Graphic --;
  }
else object[1].Graphic = 70;
}


As long as you import all your sprites one after the other then this should work happily, then when you interact with the object have something like

Code: ags

if (object[1].Graphic == 50)
{
  do your stuff
}
else if (object[1].Graphic == 51)
{
etc


(this is all untested bleh code)

Otherwise I'd use baselines (what exactly were you having trouble with?

DrewCCU

well i dont fully understand baselines mainly ... and the helpfile didnt really help my understanding ... could u give me a simpler definition/explanation of how they work?
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

ThreeOhFour

The baseline of something just dictates the y-coordinate required in order to appear in front of something (this isn't the best explanation, really)

If you're really keen on using tons of objects, try something like this (much less simple to use, and again assuming 20 objects):

Code: ags

hButton1_interact()
{
  if (object[1].Baseline == 1)
  {
    object[1].Baseline ++;
    object[2].Baseline ++;
    ...
    object[20].Baseline = 1;
  }
etc


It is possible that you could use a while loop:

Code: ags

hButton1_interact()
{
  if (object[1].Baseline == 21)
  {
    int obj = 2
    while (obj < 20)
    {
      object[obj].Baseline ++;
      obj++
    }
    object[1].Baseline = 1;
  }
  else if (object[1].Baseline == 1)
  {
    int obj = 1
    while (obj < 19)
    {
      object[obj].Baseline ++;
      obj++
    }
    object[20].Baseline = 1;
  }
}
etc


or an array for this but apparently today I am too dumb to figure out how to do it neatly.

Seriously though, consider shifting the graphics each time (I'm sure someone else can provide better help if this doesn't work)

Khris

To elaborate a bit on baselines:
Since games are usually depicting a 3D world projected onto a 2D plane, stuff with a lower Y coord is usually supposed to be depicted behind other stuff.
There are exceptions though; think e.g. of something afloat. Using the baseline, you can provide an object with a height above the ground, moving its position in the screen's depth, i.e. changing the order of what obscures what. Think of the baseline as the position of its shadow at noon.

Now, to change the appearance of an object in-game, you don't need a multitude of objects. Just do like Ben said and change its .Graphic.

(It's usually a good idea to tell us what you want the final result to be; that way we can better address a specific problem.)

SMF spam blocked by CleanTalk