TypeWrite effect


#1

Hi, i’m new in FlashPunk. i have a question, how i can do the Typewrite effect (like on the rpg games)? thanks <3


(mikale) #2

Hi there phanblood,

I used this tutorial yeears ago (back when I made online games in Flash CS4). Code for it starts around step 14 or so. It’s pretty outdated now but the basic ActionScript functions should work for you. You should be able to use code from this in your game in an Event.ENTER_FRAME function.


(Mike Evmm) #3

Hello, welcome to the forums!

If your textbox is parented to an entity, e.g.

import net.flashpunk.Entity;

public class TypingTextBox extends Entity
{
	protected var textfield:Text;
	protected var toDisplay:String;

	public function TypingTextBox(toDisplay: String, x:Number=0, y:Number=0)
	{
		super(x,y);
		this.toDisplay = toDisplay;
		textfield = new Text("");
		this.graphic = textfield;
	}
}

You can (crudely?) typewrite text by displaying more letters over your update(), i.e.:

// ...
	protected var displayIndex: uint = 0;

	override public function update():void
	{
		if (displayIndex < toDisplay.length) {
			displayIndex++;
			this.textfield.text = this.toDisplay.substr(0, displayIndex);
		}
	}

Now, I haven’t tested this (or used FP in a few years haha) but hopefully this’ll help you get started!