Concerning Objects (Walk-to-points and multiple objects)

Started by Kamileon, Thu 05/06/2014 09:42:55

Previous topic - Next topic

Kamileon

I have a few questions regarding objects:
1. Can you make a walk-to-point for an object, like you do for hotspots? I want to make it so if I want to pick up oKey the player has to walk to it first.
2. I currently have 2 objects; oCupboardClosed and oCupboardOpen (when the player interacts with the closed door it switches sprites, appearing open - vice versa). I have also tried to put a new object (oBag) into the cupboard, but only visible when the player has the cupboard open. However, I have encountered a problem - oBag appears behind oCupboardClosed because of its bigger size. Is there a way to move the object in front of oCupboardClosed? Or is there another way to solve this?

If anyone could help that'd be appreciated :)
It's not who I am underneath, but what I do that defines me.

Khris

1. Asked and answered many times already. Basically: there are no walk-to points for objects, but given the sprite size and position/baseline you can calculate where the bottom center is. You might also want to use this to make the walk to the object non-blocking.

2. Size has nothing to do with it; whether object A appears before object B is a question of the y coordinate or baseline.
First of all: ideally, the room background shows an open cupboard. Then a door object is added, which simply changes its sprite when interacted with, alternating between two aligned sprites showing the open and closed door. This also allows animating opening/closing the door. Objects inside the cupboard will have baselines a bit further up and thus appear behind the door.

AnasAbdin

1. If you are trying to make the player walks to the object's coordinates then you could try this:
Code: ags
player.Walk(oKey.X, oKey.Y, eBlock, eWalkableAreas);


2. You don't actually need two objects for the cupboard, you can switch sprites for a single object.
Code: ags
function oCupboard_Interact()
{
       player.Walk(oCupboard.X, oCupboard.Y, eBlock, eWalkableAreas);
       if ( oCupboard.Graphic == ... ) //closed cupboard sprite number...
       {
            oCupboard.Graphic = ...;   // put sprite number of the opened cupboard...
       }
       else
       {
            oCupboard.Graphic = ...;   // put sprite number of the closed cupboard...
       }
}


To make sure the bag is not visible while the cupboard is closed you can assign a baseline to the bag less than the cupboard's baseline.

Code: ags
 oBag.Baseline = ...; 


I hope that was helpful  :smiley:

Kamileon

All is working well, thanks for the scripting help AnasAbdin :grin:
It's not who I am underneath, but what I do that defines me.

SMF spam blocked by CleanTalk