Copy link to clipboard
Copied
I am trying to make a side scrolling rpg game similar to South Park Stick of Truth. Right now I have the player done and i sketched the outline of the room i wanted in order to test the the collision detector. So right now there are only 4 classes. The main class that adds the walls, player and does something with the constants class.The walls class that doesn't really do anything. The player class that moves with keyboard input, test for collisions with the walls and initiates the walking animation. There is also a constants class that i don't really know how it works but based on tutorials I have seen they want me to use it. I want to add different things in the room that when the player gets close enough to, it allows the person playing to press a button and it will interact with it. It could be for making a small animation, having the player do some different dialog or have a closer look at the object. I can't find any tutorial on how to do that. All the actionscript 3 tutorials are for really simple shooter and platform games that don't interact with the game world at all. Any help would be greatly appreciated.
Copy link to clipboard
Copied
You could make all of your "interactable" objects implement an interface. Say for example your Interface defines showButton() and hideButton() functions. Then, when you detect a collision on any of these objects, you call showButton(). The button can be set up to dispatch an event that your Main Class is listening for. For example, this might be a custom MoreInfoEvent that has its own "infoItem" property in addition to the other properties Event has.
The code might look like this:
protected function onButtonClick(e:MouseEvent):void {
dispatchEvent(new MoreInfoEvent(MoreInfoEvent.SHOW_INFO, true, "rockObject"));
}
Then the MainClass would do something like this:
protected function onMoreInfoEvent(e:MoreInfoEvent):void {
switch(e.infoItem) {
case "rockObject":
rockInfo.visible=true;
break;
//other case statements for other info
default:
break;
}
}
If you don't know how to create a custom event, there are a lot of tutorials for that.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now