Last active
December 26, 2015 00:29
-
-
Save videlais/7064983 to your computer and use it in GitHub Desktop.
ActionScript 3 Example 6 NPCSpriteGroup Version 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
/** | |
* ... | |
* @author Dan Cox | |
*/ | |
import org.flixel.*; | |
public class NPCSpriteGroup extends FlxGroup | |
{ | |
private var dialog:FlxDialog; | |
private var npc:NPCSprite; | |
[Embed(source="data/NPC1.png")] | |
private var NPCPng:Class; | |
public function NPCSpriteGroup() | |
{ | |
dialog = new FlxDialog(0, 160, FlxG.width, 80); | |
dialog.setFormat(null, 8, 0xFFFFFFFF); | |
dialog.finishCallback = removeDialogBox; | |
npc = new NPCSprite(48, 320, NPCPng); | |
npc.addSpeech("Hi, player! I'm a NPC."); | |
add(npc); | |
} | |
override public function update():void | |
{ | |
super.update(); | |
FlxG.collide(Registry.player, npc, showDialog); | |
} | |
private function showDialog(a:FlxObject, b:FlxObject):void | |
{ | |
if(FlxG.keys.justPressed("ENTER")) | |
{ | |
Registry.player.isStopped = true; | |
add(dialog); | |
dialog.showDialog(npc.speech); | |
} | |
} | |
private function removeDialogBox():void | |
{ | |
remove(dialog); | |
Registry.player.isStopped = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment