Simple ImageFrame Call Code Help
by rennie moffat · in Torque Game Builder · 09/30/2009 (2:44 pm) · 10 replies
Here is a good question, I think.
I have been playing with this code for the better part of an hour. I have it in my playerClass.
I want my code to trigger and image change, of my PlayerShip_ImageMap, as saved in TGB. The object is Named: PlayerShip and Classed as PlayerClass. I Have a call for setImageMap() in my onUpdate().
I have tried all types of variations on this, and none work. I have tried a different function name (and associated onUpdate callback), I have tried different names of the object (%this.PlayerShip) that is being called, for instance %this.PLayerShip_ImageMap (its ImageMap name. Different velocity titles, ex. %yVelocity, %velocityY. The getLinearVelocity() and I tried it as getLinearVelocity(%velocityY), with and with out this line I have been unable to get anything going. So I am going to take 5, but if anyone can give me some insight as to how to make this code work and what I might be doing wrong, I would appreciate the help.
Thanks.
I have been playing with this code for the better part of an hour. I have it in my playerClass.
I want my code to trigger and image change, of my PlayerShip_ImageMap, as saved in TGB. The object is Named: PlayerShip and Classed as PlayerClass. I Have a call for setImageMap() in my onUpdate().
function playerClass::getImageFrame(%this)
{
%this.getLinearVelocityY(%velocityY);
if (%velocityY > 0)
{
$PlayerShip.getFrame(%this.PlayerShip, 0);
}
else if (%velocityY < 0)
{
$PlayerShip.getFrame(%this.PlayerShip, 2);
}
else if (%velocityY = 0 )
{
$PlayerShip.getFrame(%this.PlayerShip, 1);
}
}I have tried all types of variations on this, and none work. I have tried a different function name (and associated onUpdate callback), I have tried different names of the object (%this.PlayerShip) that is being called, for instance %this.PLayerShip_ImageMap (its ImageMap name. Different velocity titles, ex. %yVelocity, %velocityY. The getLinearVelocity() and I tried it as getLinearVelocity(%velocityY), with and with out this line I have been unable to get anything going. So I am going to take 5, but if anyone can give me some insight as to how to make this code work and what I might be doing wrong, I would appreciate the help.
Thanks.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
http://www.garagegames.com/community/forums/viewthread/102763
it calls an animation, this an image, for essentially the same thing. just basic logistics stuff.
thanks
10/01/2009 (4:06 pm)
actually to get a better idea of what i want to do look here.http://www.garagegames.com/community/forums/viewthread/102763
it calls an animation, this an image, for essentially the same thing. just basic logistics stuff.
thanks
#3
This is a copy from the documentation of setFrame:
setFrame(int frame)
Description: Sets imageMap frame.
Params:
frame: The frame to display
Return:
Returns true on success.
So if you change your code to:
Was this what you meant?
10/01/2009 (4:59 pm)
Without testing this myself, I think you mean to use the setFrame(frame); instead of getFrame().This is a copy from the documentation of setFrame:
setFrame(int frame)
Description: Sets imageMap frame.
Params:
frame: The frame to display
Return:
Returns true on success.
So if you change your code to:
function playerClass::getImageFrame(%this)
{
%this.getLinearVelocityY(%velocityY);
if (%velocityY > 0)
{
$PlayerShip.setFrame(0);
}
else if (%velocityY < 0)
{
$PlayerShip.setFrame(2);
}
else if (%velocityY = 0 )
{
$PlayerShip.setFrame(1);
}
}Was this what you meant?
#4
10/01/2009 (6:19 pm)
Thanks for looking and trying on both. I have tried the setFrame as you posted, with different variations on the $PlayerShip, %this. etc but to no avail. Anyhow I will keep going on it, thanks!
#5
10/01/2009 (6:24 pm)
Okay, but you are using a static sprite and the image map is in CELL mode right?
#6
I dragged a static sprite with an imageMap in CELL mode and named it gTest.
How did you initialize your $PlayerShip variable?
10/01/2009 (6:32 pm)
I did a quick test and this works...I dragged a static sprite with an imageMap in CELL mode and named it gTest.
function startGame(%level) {
Canvas.setCursor(DefaultCursor);
Canvas.setContent(mainScreenGui);
new ActionMap(moveMap);
moveMap.bind("keyboard", "right", PlayerRight );
moveMap.bind("keyboard", "left", PlayerLeft );
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
function PlayerRight(%fKeyEvent) {
gTest.setFrame(1);
}
function PlayerLeft(%fKeyEvent) {
gTest.setFrame(2);
}How did you initialize your $PlayerShip variable?
#7
My $PlayerShip is set in onlevelLoaded as being = to %this.
It is also the "Name" of the object, classed as playerClass.
;/
10/01/2009 (7:17 pm)
This is in in your game.cs?My $PlayerShip is set in onlevelLoaded as being = to %this.
It is also the "Name" of the object, classed as playerClass.
;/
#8
I tested the same idea with playAnimation instead of setFrame, that did not work tho.
I am going to next ry and do something that will change the imageMap frame depending on where my player is. So if yPosition is > 10 set imageFrame to 1, if yPosition is >20 setImage frame to 2 etc. If you have any thoughts on this, please let me know.
Thanks!
10/01/2009 (7:29 pm)
ok just tried it too. I just plugged it into my various movement functions and it does work, hooray.I tested the same idea with playAnimation instead of setFrame, that did not work tho.
I am going to next ry and do something that will change the imageMap frame depending on where my player is. So if yPosition is > 10 set imageFrame to 1, if yPosition is >20 setImage frame to 2 etc. If you have any thoughts on this, please let me know.
Thanks!
#9
Good luck!
10/01/2009 (7:48 pm)
I have only been evaluating TGB for about 3 weeks now, I'm still learning the basics, so I don't think I'm ready to advice on design strategies yet.Good luck!
#10
10/01/2009 (8:35 pm)
it's not a strategy, just a way of making my game look cool. but thanks dude, good luck!
Torque Owner Max Kielland
MK Development
Do you want to know where in the current animation you can change to another animation?
...or do you want this function to be called for each frame in your animation?