Author Topic: Sprite not updati g  (Read 929 times)

caladan21ph

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Sprite not updati g
« on: Fri, Nov 23, 2012 »
Hi! I need help making this work. Somehow the sprites are not moving even after I set their velocity. Can anyone show me the problem? Thanks! Heres my code:

Code: [Select]
package Elenin
{
import org.flixel.*;
/**
* ...
* @author
*/
public class Playstate extends FlxState
{

public var player:Elenin.Player;
public var test:Elenin.Obstacle;
override public function create():void
{
FlxG.mouse.show();


add(Elenin.GameUI.Instance());
if (!Elenin.GameUI.Instance()) throw new Error("There must be an instance of GameUi");

add(Elenin.ObstacleManager.Instance());
if (!Elenin.ObstacleManager.Instance()) throw new Error("There must be an instance of obstacleManager");


/*test = new Elenin.Obstacle(200, 200,32);
add(test);
test.velocity.x = 10;*/

player = new Elenin.Player(100, 100);
add(player);


super.create();
}


override public function update():void
{
super.update();
}

public function Playstate()
{

}

}

}

Code: [Select]
package Elenin
{
import org.flixel.*;
/**
* ...
* @author
*/
public class ObstacleManager extends FlxGroup
{
private static var _instance:Elenin.ObstacleManager;

private var maxNumObstacles:uint = 50;
private var timer:uint = 0;
private var deployTime:uint = 5;



public static function Instance():Elenin.ObstacleManager
{
if (_instance == null) {
_instance = new Elenin.ObstacleManager();
}


trace("obstacleManager instantiated");
return _instance;


}

public function ObstacleManager()
{
for ( var i:uint = 0; i < maxNumObstacles;++i)
{
add(new Elenin.Obstacle());
//trace("obstacle added");
}

}


override public function update():void
{
timer += FlxU.getTicks() / 1000;
if (timer >= deployTime) {
Deploy();
timer = 0;
}

//trace(timer);
}


public function Deploy():void
{
var newObstacle:Elenin.Obstacle = Elenin.Obstacle(getFirstAvailable());

//if (newObstacle == null) throw new Error("newObstacle is null");

if (newObstacle)
{
newObstacle.Deploy();

}

//Elenin.Obstacle(getFirstAvailable()).Deploy();
}

}

}

Code: [Select]
package Elenin
{
import org.flixel.*;
import org.flixel.FlxSprite
import org.flixel.FlxG;

/**
* ...
* @author
*/
public class Obstacle extends FlxSprite
{

private var size:uint
public function Obstacle():void
{
super(0, 0);

size = 32;
makeGraphic(size, size, 0xffffffff, false);
exists = false;

}



public function Deploy():void
{

x = Elenin.MathUtils.randRange(100, 600);
y = Elenin.MathUtils.randRange(10, 450);
velocity.x = 100;

trace("x:" + this.x + ",y:" + this.y);
//trace(exists);

trace("obstacle deployed");
exists = true;

}

override public function update():void
{
//x += 1
trace("updated");
super.update();
}

}

}



Thanks!
Check out my game journal: http://alternatdev.wordpress.com

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Sprite not updati g
« Reply #1 on: Sat, Nov 24, 2012 »
You need to call super.update in obstaclemanager update.

caladan21ph

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: Sprite not updati g
« Reply #2 on: Sat, Nov 24, 2012 »
I missed that. :( Thanks a lot! :)
Check out my game journal: http://alternatdev.wordpress.com