Hi everyone again, trying to make a platform tile that is either on or off and collides with the player.
My idea is that the static function is called once as a Class and changes all objects to the other state of on/off. I think I am not understanding things properly.
Basically I don’t want to have to call every objects function to change on/off I am hoping to just be able to call TogglePlatform.togglePlatform();
public class TogglePlatform extends Entity
{
private var isOn:Boolean;
public function TogglePlatform(x:Number, y:Number, width:int, spriteAsset:*, isOn:Boolean=true)
{
this.x = x;
this.y = y;
this.width = width;
this.isOn = isOn;
setHitbox(width, 8);
}
override public function update():void
{
if (isOn)
{
if (collide("player", x + 1, y + 1) || collide("player", x - 1, y + 1))
{
type = "platform"; // Just make every other NPC/Enemy collide with Platform. They won't fall through when type changes.
}
else if (!collide("player", x, y))
{
type = "wall";
}
}
else type = "none";
}
public static function togglePlatform():void
{
isOn = !isOn;
}
}