Animating an object...Opening a chest SOLVED

Started by harmonicapress, Tue 27/08/2013 05:32:09

Previous topic - Next topic

harmonicapress

I want my character to open a chest, see an object in it, then pick up the object leaving the remaining chest behind. So far I have attempted this by bit-mapping 3 objects, 1. the tool chest closed, 2. the tool chest open, revealing a wrench inside, 3. I placed the tool chest as object one and set it to visible, then the open chest with the wrench as object 2, set it invisible, then the empty chest as object 3, set as invisible. The objects rest in layers upon one another in the build suite. For some reason, only a tiny area of the object is recognized by the cursor and so you have to pixel hunt like crazy to get the chest to open. I can't figure out how to make the rest of the object available to the cursor actions, and now I've changed the objects in and out a few times and the animation I set up doesn't seem to be working at all. Here is a look at my coding for the room. Any ideas?

Code: AGS
function ToolChest_Look()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("It's a ToolChest, left behind by the construction workers.");
}

function ToolChest_PickUp()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("I'm not gonna lug that thing around, but maybe there's something inside I can use...");
}

function ToolChest_Interact()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("Let's see what we have in here...");
ToolChest.Visible = false;
Wrench.Visible = true;
cKilroy.Say("A wrench! That could be useful!");
}

function Wrench_Look()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("It's a wrench!");
}

function Wrench_Interact()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("Hmmm...It might be more useful if I took it with me.");
}

function Wrench_PickUp()
{
cKilroy.Walk(269, 141, eBlock, eWalkableAreas);
cKilroy.Say("Ok monkey, your coming with me.");
cKilroy.AddInventory(iWrench);
Wrench.Visible = false;
EmptyChest.Visible = true;
}

function EmptyChest_Look()
{
cKilroy.Say("It's empty.");
}

function EmptyChest_PickUp()
{
cKilroy.Say("I'm not lugging that thing around.");


Lewis

"doesn't seem to be working at all"

It would be helpful if you could be more specific about what isn't working.

At first glance, the code looks fine. Difficult to advise without seeing the objects. Generally speaking I would work with objects that are the same size (so ToolChest would be the whole chest, closed; Wrench would be the open chest with a wrench visible; and EmptyChest would be the whole chest, open, with the wrench gone).

By default, the game also ignores clicks on alpha channel areas of an object, so this could be another reason.

If you could post pics of your objects and explain exactly what isn't working, that might help.
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

Slasher

#2
Hi

You should start all Object names with an o (as in object).
You should start all Inventory names with an i (as in inventory).

So ToolChest should be oToolChest. This is in keeping with AGS etiquette and organisation.
So Wrench should be iWrench. This is in keeping with AGS etiquette and organisation.

you can simply change an object graphic by setting its sprite number:

Example:
Code: ags

 //After interacting with oToolChest
oToolChest.Graphic=157;// Changes object oToolChest sprite number: now with appearance of the object inside (image has drawing of wrench within). 

//After interacting with the oToolChest yet again you receive the Wrench (iWench) in your Inventory and the oToolChest graphic changes oToolChest object as 'Empty' sprite number:
oToolChest.Graphic=158;// Object graphic sprite number that shows oToolChest as 'Empty'.


Obviously you would amend the above sprite numbers with yours.

So you only need 1 object oToolChest with 3 sprites and just change its graphic sprite number when required.

Hope this helps.



Khris

Is there maybe a walkbehind that covers part of the chest? Or a GUI without any background graphic? Something invisible must catch the click.

chest implementation advice:
Spoiler
The best solution is often the one that is closely modeled after the real world, at least in my experience.
I'd draw the open chest without lid into the room and implement it as hotspot. Then I'd place the wrench object on top, then a lid object on top of that. (If necessary, move the lid objects baseline down so it covers the wrench.)
Interacting with the chest hotspot or the lid object will change the lid object's .Graphic from the number of the "lid closed" sprite to "lid open"'s (and back, [using an animation]).
The wrench works completely independent of the chest, but since it's only visible and thus clickable when the chest is open, that doesn't matter.
[close]

harmonicapress

Alright, feeling super noobie, especially since I can't figure out how to post my images. However I can say that I built them just as Lewis described, one fits right over the top of the other. What is this about alpha channels though? where would I go to change that feature within the suite? It's strange because I got the animation to work one time (the character opened the chest, revealing open chest with a wrench, character picks up wrench revealing empty chest) however I was frustrated with the pixel hunting I had to do, and all my coding seemed right, so I deleted the objects and re-loaded them into the game (leaving the code I had written, since it looked good). Now when I load the game, I still have to pixel hunt to find the object, and when I am able to click (interact) with it, there is no response. When I reloaded the objects I made sure to select their functions from the drop down window as I did before, this time I had the code already written so theoretically, I shouldn't need to recode everything right? Should I just erase my code and start from scratch? also, I will try the i/o prefixes, I have been using the i for inventory objects but not the o prefix for room objects. Thanks all

Slasher

#5
The Wrench Clickable area(s) may be a bit too small and you need to click in correct places of the object: hence the pixel hunt.

Remember that mouse clicks don't respond to transparent area(s).

Expand the area around the Wench to match the open chest (re-draw Wrench image). This will make the image clickable area bigger.

This is something many newbies encounter.

QuoteWhat is this about alpha channels though?
Check out: http://en.wikipedia.org/wiki/Alpha_compositing



Khris

Just to be absolutely sure that we're dealing with a technical problem, as opposed to a design one:

You don't happen to build a high res game, have a big hand sprite as interact cursor with a cursor hotspot somewhere in the center and simply have a hard time of getting the click to line up with a relatively tiny wrench sprite, right?
Because if that's the case, there's not much we can do unless you use a more suitable cursor or make the wrench sprite bigger, or add mouseover text.
Just to get this out of the way.

As for rewriting the code after doing the objects again from scratch:
Assuming you haven't renamed the object in between, just click on the event's [...] button and it should work with the existing function. AGS simply looks for a function with the name entered next to the event; there's no deeper level of linkage.
Even if you do use other names, you can either move the code from the existing functions to the new ones (then delete the old, empty functions) or simply rename them.

To post images, make a screenshot in AGS (press F12, it should appear in WinUserDir/Saved Games/GameName/). Upload it to an imagehost like http://imgur.com, then put the direct link in between [img] and [/img]. (Or use imgzoom instead of img if the game is lowres.)

Slasher

From Khris:
Quoteinteract cursor with a cursor hotspot somewhere in the center and simply have a hard time of getting the click to line up with a relatively tiny wrench sprite

This is so relevant when placing the mouse cursor hotspot position. Many times people have placed it at the palm of the hand and you generally use the fingers and therefore clicking will not work. I usually place it at the tip of the middle finger for the hand cursor.

Take this into account for the other mouses cursors as well.


harmonicapress

Okay, so after much tinkering, changing the objects color and mouse cursor hotspot to no effect, I simply tried placing it somewhere else in the room and BAM! Everything lined up and worked just as it should according to the coding I had done. I assume the objects were too close to the room's edge, which is strange because when I selected the "show this room's edges" drop down, I was still a good inch away from the yellow lines designating the playable screen area. Anyone know if AGS has a built in "safety zone" around the edges that might have this effect? maybe this is why I could only find the top row of pixels on the object??? Anyways, thanks for all your help, I actually gleaned quite a bit of info in trying to fix this stubborn issue:tongue:

Slasher

QuoteAnyone know if AGS has a built in "safety zone" around the edges that might have this effect?
Not to my limited knowledge.

As a rule, if I am not using any edges to run events, I put the all edges tight to the rooms edges giving the whole background as the 'game area'.

If you were an inch 'inside' an edge then it should be within the 'game area'.

Obviously if it works elsewhere there is a definite problem.




harmonicapress

Could It be because I was using the LucasArts styled GUI? The object was sitting really close to the bottom of the screen/at the top of the GUI. Also, maybe someone can direct me to a good forum page about working with said LucasArts styled GUI. I have been hesitant to post for help because I am certain the answers I need are in the forum already, but I have been looking all morning and have been unsuccessful. I just want to know how to integrate the other functions in the GUI, like push and pull. There is no option for these actions in the drop down ellipses for objects, how can I make them work?

Slasher

QuoteI just want to know how to integrate the other functions in the GUI, like push and pull. There is no option for these actions in the drop down ellipses for objects, how can I make them work?
They can be manually scripted (if you know how)  but there are also some Templates you can use to do this and I would suggest you find and use one of these.

I'm sure someone will give you a link to a suitable one.



Khris

The edges you can move in the room editor shouldn't have any effect on whether mouse clicks are registering. They can be used to make the player character go into another room, but they don't have any other function. (Apparently they can mess up the pathfinding algorithm in scrolling rooms if you forget to move them near the background's edge though.)

The LucasArts template's gAction GUI is positioned at y = 143, so any click on that coordinate or lower will register on the GUI, not the room. If you want the background to reach down to the verbs, with the action text displayed on top of it, simply turn gAction's Clickable property to "false" in the GUI editor.

The template comes with extensive documentation, since it doesn't use the standard AGS way of processing actions, and has all kinds of extra functionality built in. Check inside your game dir for a file called 9Verbs.pdf.

(Also, always state whether you're using any templates, plugins or modules when you make a thread about a technical problem.)

Lewis

Quick design tip: Unless there's a very specific reason to implement a ton of different interaction mechanics (eg you're aping a particular classic style of adventure game, or it's a learning challenge you've set yourself), think carefully about whether your game will really benefit from the distinction between push, pull, use etc. Often, complex interfaces are what lead to frustrating puzzles where you try every interaction on everything until you guess the logic the designer was using. Generally I prefer to stick to very simple two button interfaces - left click to interact, right to examine - and find that games feel much tighter as a result and lead you to think up more meaningful puzzle designs. Just my two cents, feel free to ignore or disagree. :-)
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

SMF spam blocked by CleanTalk