Creating sprites in script
by Koen Van Baelen · in Torque Game Builder · 05/13/2007 (4:08 am) · 2 replies
I know it's probably a very stupid mistake I'm making, but I can't get this to work. I want to make the player shoot fireballs by pressing the spacebar. Here's the function for firing:
function Player::onLevelLoaded(%this, %scenegraph)
{
$PlayerShip = %this;
...
moveMap.bindCmd(keyboard,"space","Player::SpacePress();","");
}
function Player::SpacePress(%this)
{
%PlayerFire = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
WeaponSpeed = %this.WeaponSpeed;
};
%PlayerFire.setImageMap(Player_Weapon);
%PlayerFire.setSize(40,30);
%PlayerFire.setVisible(true);
}
I haven't set any speed or other options, all this should do is create a fireball sprite in the middle of the screen. I have checked if the SpacePress function is actually executed by writing some text to the console and it is. No sprite appears, however. What am I doing wrong?
function Player::onLevelLoaded(%this, %scenegraph)
{
$PlayerShip = %this;
...
moveMap.bindCmd(keyboard,"space","Player::SpacePress();","");
}
function Player::SpacePress(%this)
{
%PlayerFire = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
WeaponSpeed = %this.WeaponSpeed;
};
%PlayerFire.setImageMap(Player_Weapon);
%PlayerFire.setSize(40,30);
%PlayerFire.setVisible(true);
}
I haven't set any speed or other options, all this should do is create a fireball sprite in the middle of the screen. I have checked if the SpacePress function is actually executed by writing some text to the console and it is. No sprite appears, however. What am I doing wrong?
Torque Owner Neo Binedell
You need to change that to: