Creating Entities with Entities


(Noah) #1

I’m trying to make clickable dialog options in a game that I am working on. Whatever I try to do comes up in an error apparently because it says I can’t use the add function. I tried importing various packages into the class, but nothing seems to be working.

package  {

import net.flashpunk.FP;
import net.flashpunk.Entity;
import net.flashpunk.World;
import net.flashpunk.graphics.Image;

public class ChoiceBox1 extends Entity {
	
	[Embed('assets/choicebox.png')] private const CHOICEBOX:Class;

	public function ChoiceBox1(textchoice:String) {
		super(700, 200);
		graphic = new Image(CHOICEBOX);
		add (new DialogTextLine1(710, 200, textchoice));
	}

}

}

Thank you for your help


(JP Mortiboys) #2

Try world.add(...)


(Jacob Albano) #3

And remember that world is null until the entity has been added to a world…so you can only call world.add(...) in the added() method or later.


(Jesus Boadas) #4

I think in FlashPunk you can’t add a entity inside an entity you need to use the hitbox and masklist to achieve different click regions inside the entity, maybe this can be usefull:

A FlashPunk World that shows how to make a simple button as well as Text manipulation and some fun tricks.

FlashPunk Inventory

hope these help