Extremely amateur, need help with something simple
by Lexi Harari · in Torque Game Builder · 04/19/2013 (2:19 pm) · 11 replies
I'm in a game design class at a university that has no pre-requisites, so I'm coming into this class with absolutely no knowledge of coding or any of that. We have to make a video game for the class, and I'm making a really, really simple platformer. Keep in mind I have no knowledge of coding, so everything is oversimplified. Basically, I have a character that's running and jumping around just fine with the proper animations. In the sky above him, I wanted a big moon to be following him around. So we have the moon image, and we put it in. We mount it to the character, but that means the moon jumps around whenever he does, and is on top of him, which is not what a moon does. We want the moon to not have any vertical movement, just horizontal movement, and move with the player. Move when he moves to the right, move when he moves to the left. I managed to follow some tutorials, but I only go to the point where I can move the moon and character independently of each other, not both at the same time. Basically, we need the moon to be in view the whole time. I'm sure this is an incredibly easy fix, but since I have no knowledge with ANYTHING pertaining to this, I am utterly lost. Please help, you will save my project and quite possibly my grade... thank you!
I have no idea if this would even help, but I'm testing stuff out with a cloud right now and named it firstCloud and the class allCloud... maybe this would help someone who is trying to help me with coding. My character's name is pGuy and the class is playerClass
I have no idea if this would even help, but I'm testing stuff out with a cloud right now and named it firstCloud and the class allCloud... maybe this would help someone who is trying to help me with coding. My character's name is pGuy and the class is playerClass
About the author
#2
Or mount the moon sprite to the background image or perhaps the camera instead of the player. I'm guessing that if you have a background it is stationary - probably mounted to the camera already - so mounting other sprites to it should work as well.
04/19/2013 (4:43 pm)
You're using T2D MIT I assume?Or mount the moon sprite to the background image or perhaps the camera instead of the player. I'm guessing that if you have a background it is stationary - probably mounted to the camera already - so mounting other sprites to it should work as well.
#3
04/19/2013 (4:51 pm)
You can mount stuff to the camera? That sounds like a better idea.
#4
Richard, I'm going to try mounting the sprite to the background, I was not under the impression you could do that.. but the problem is that there isn't just one solid background, if that makes any sense. If I could mount it to the CAMERA, that would be different, but my TA told me that requires some scripting but the camera is already following the player, so that's some good news.
04/19/2013 (7:47 pm)
To the first response, I'm amateur to the point that I have pretty much no idea what you just said. Haha. I really appreciate your help. I'm working with Torque Game Builder 2d, not the Open Source stuff. My computers at school have the real thing, it's the licensed one. I'm not exactly sure if it's MIT or not because I'm not 100% sure what that means, but I think it's saying something about version 1.8? Richard, I'm going to try mounting the sprite to the background, I was not under the impression you could do that.. but the problem is that there isn't just one solid background, if that makes any sense. If I could mount it to the CAMERA, that would be different, but my TA told me that requires some scripting but the camera is already following the player, so that's some good news.
#5
Sorry, I was assuming you'd written a bit of script - you knew about the object and class names ;). I'm used to working with the MIT release which doesn't have the editors.
04/19/2013 (9:38 pm)
T2D MIT refers to the MIT-licensed open-source release of T2D, so no, you're not working with it. 1.8, I think, is the most recent version of TGB, but T2D MIT is a bit different.Sorry, I was assuming you'd written a bit of script - you knew about the object and class names ;). I'm used to working with the MIT release which doesn't have the editors.
#6
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%force = 20;
sceneWindow2D.mount($pGuy, "0 0", %force, true);
}
function playerLeft()
{
$pGuy.moveLeft = true;
$pGuy.setFlip(true, false);
}
function playerLeftStop()
{
$pGuy.moveLeft = false;
}
function playerRight()
{
$pGuy.moveRight = true;
$pGuy.setFlip(false, false);
}
function playerRightStop()
{
$pGuy.moveRight = false;
}
function playerJump()
{
%yVelocity = $pGuy.getLinearVelocityY();
%xVelocity = $pGuy.getLinearVelocityX();
//if(!(%collision $= ""))
if($pGuy.getLinearVelocityY() == 0)
{
$pGuy.setLinearVelocityY(-225);
}
else
{
$pGuy.setLinearVelocityY(%yVelocity);
}
$pGuy.setLinearVelocityX(%xVelocity);
}
function playerClass::updateMovement(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}
if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}$pGuy.setCollisionMaxIterations(2);
%yVelocity = $pGuy.getLinearVelocityY();
$pGuy.setCurrentAnimation(%yVelocity);
$pGuy.setLinearVelocityY(100);
%collision = $pGuy.castCollision(0.005);
$pGuy.setLinearVelocityY(%yVelocity );
}
function playerClass::setCurrentAnimation(%this, %yVelocity)
{
if(%yVelocity < 0 )
{
%this.playAnimation(playerJumpUp);
}
else if(%yVelocity > 0 )
{
%this.playAnimation(playerJumpDown);
}
else
{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}
}
}
function t2dSceneGraph::onUpdateScene()
{
$pGuy.updateMovement();
}
if(%collision $= "")
{
$pGuy.setConstantForceY(100);
}
else
{
$pGuy.setConstantForceY(0);
}
This is basically him running, jumping, with the right animations. I got that far. Everything is pretty much good other than getting the moon to follow the guy around. We did mount the character itself to the moon which is the closest we've gotten, but it jumped and moved vertically when the character did, and obviously we can't have any vertical movement because moons in real life do not do that and it looks.. odd. I'm thinking some kind of "if" statement. I don't know a lot about coding, but wouldn't it be something like (not in coding language): "if pGuy moves, Moon moves too"?
I know I sound dumb, but I'm just trying to figure this out in time for class and I'm so lost. This forum is my last hope.
04/19/2013 (10:08 pm)
Okay, so not MIT. I tried getting MIT on my own computer at home, but it was a no go... I'm apparently retarded with computers. I'm posting my code... (I did write it, but I followed closely to a tutorial and surely would not have been able to do it without it, I have NO experience with coding, period. Unfortunately... for this class..) function playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%force = 20;
sceneWindow2D.mount($pGuy, "0 0", %force, true);
}
function playerLeft()
{
$pGuy.moveLeft = true;
$pGuy.setFlip(true, false);
}
function playerLeftStop()
{
$pGuy.moveLeft = false;
}
function playerRight()
{
$pGuy.moveRight = true;
$pGuy.setFlip(false, false);
}
function playerRightStop()
{
$pGuy.moveRight = false;
}
function playerJump()
{
%yVelocity = $pGuy.getLinearVelocityY();
%xVelocity = $pGuy.getLinearVelocityX();
//if(!(%collision $= ""))
if($pGuy.getLinearVelocityY() == 0)
{
$pGuy.setLinearVelocityY(-225);
}
else
{
$pGuy.setLinearVelocityY(%yVelocity);
}
$pGuy.setLinearVelocityX(%xVelocity);
}
function playerClass::updateMovement(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}
if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}$pGuy.setCollisionMaxIterations(2);
%yVelocity = $pGuy.getLinearVelocityY();
$pGuy.setCurrentAnimation(%yVelocity);
$pGuy.setLinearVelocityY(100);
%collision = $pGuy.castCollision(0.005);
$pGuy.setLinearVelocityY(%yVelocity );
}
function playerClass::setCurrentAnimation(%this, %yVelocity)
{
if(%yVelocity < 0 )
{
%this.playAnimation(playerJumpUp);
}
else if(%yVelocity > 0 )
{
%this.playAnimation(playerJumpDown);
}
else
{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}
}
}
function t2dSceneGraph::onUpdateScene()
{
$pGuy.updateMovement();
}
if(%collision $= "")
{
$pGuy.setConstantForceY(100);
}
else
{
$pGuy.setConstantForceY(0);
}
This is basically him running, jumping, with the right animations. I got that far. Everything is pretty much good other than getting the moon to follow the guy around. We did mount the character itself to the moon which is the closest we've gotten, but it jumped and moved vertically when the character did, and obviously we can't have any vertical movement because moons in real life do not do that and it looks.. odd. I'm thinking some kind of "if" statement. I don't know a lot about coding, but wouldn't it be something like (not in coding language): "if pGuy moves, Moon moves too"?
I know I sound dumb, but I'm just trying to figure this out in time for class and I'm so lost. This forum is my last hope.
#7
04/20/2013 (12:11 am)
Let me ask you this: is your goal to make the moon appear stationary relative to the camera? If so then what I would do is create a t2dSceneObject called "Rig" and mount the camera to Rig with a force of 0 (rigid), then mount your moon to Rig, and finally mount Rig to $pGuy with whatever force suits you. What you're doing here is essentially creating a camera frame-of-reference which you can mount to.
#8
Also, sincere thanks to EVERYONE who has helped or replied at all... you guys are saving me!!
Okay, I tried to do what you said... here's my "noob" way of doing it:
I dragged a new sceneobject out, named it "Rig" under name under Scripting tab
I added this to mount the camera to this "rig", it's the 2nd line:
sceneWindow2D.mount($pGuy, "0 0", %force, true);
sceneWindow2D.mount($Rig, "0 0", %force, true);
(I'm assuming this is very very wrong but I do not know how to mount a camera to an object any other way)
I mounted the moon onto Rig
I mounted Rig, which also had the moon mounted onto it, onto pGuy, my character
Several problems come up when I do, which we also tried to do in class
One, the moon is on top of my character, essentially we are now controlling a moon. When we jump, the moon jumps, etc. Just a big moon walking around, pretty much :P
Even if we can move it a little bit above to where it's not on top of our character, the moon still bounces around and moves vertically whenever the player does, which is what we're ultimately trying to avoid.
However, I am what I believe to be the closest I've ever been to getting rid of this problem. I have the moon mounted to that sceneobject Rig, and it's high above my character. If only it were not allowed any vertical movement and were forced to stay in one horizontal axis, it would be fixed.
04/20/2013 (1:04 am)
Basically, we want the moon to always remain in view in the same horizontal axis of the screen. When the player moves to the right, the moon moves to the right at the same speed, or maybe a little slower or whatever. When the player moves left, the same deal. Always in view. So I'm not sure whether you classify that as stationary, because while it kind of is, it kind of isn't. I hope this makes sense. Do you mind giving me a more "dumbed down" tutorial of what you just said, Justin? I'll try to follow it to the best of my capabilities anyhow... I'm still just learning. It's like a person looking at coding and Torque for the first time ever, if you could imagine.Also, sincere thanks to EVERYONE who has helped or replied at all... you guys are saving me!!
Okay, I tried to do what you said... here's my "noob" way of doing it:
I dragged a new sceneobject out, named it "Rig" under name under Scripting tab
I added this to mount the camera to this "rig", it's the 2nd line:
sceneWindow2D.mount($pGuy, "0 0", %force, true);
sceneWindow2D.mount($Rig, "0 0", %force, true);
(I'm assuming this is very very wrong but I do not know how to mount a camera to an object any other way)
I mounted the moon onto Rig
I mounted Rig, which also had the moon mounted onto it, onto pGuy, my character
Several problems come up when I do, which we also tried to do in class
One, the moon is on top of my character, essentially we are now controlling a moon. When we jump, the moon jumps, etc. Just a big moon walking around, pretty much :P
Even if we can move it a little bit above to where it's not on top of our character, the moon still bounces around and moves vertically whenever the player does, which is what we're ultimately trying to avoid.
However, I am what I believe to be the closest I've ever been to getting rid of this problem. I have the moon mounted to that sceneobject Rig, and it's high above my character. If only it were not allowed any vertical movement and were forced to stay in one horizontal axis, it would be fixed.
#9
If I were working on the project, my approach would be to have a second t2dSceneGraph loaded. All background objects and UI elements you need on screen should be in this scene, instead of the main one with your player. I show an example of how to accomplish this approach in this blog.
It's simpler and requires far less code.
04/20/2013 (5:02 am)
Moved to the TGB forum.If I were working on the project, my approach would be to have a second t2dSceneGraph loaded. All background objects and UI elements you need on screen should be in this scene, instead of the main one with your player. I show an example of how to accomplish this approach in this blog.
It's simpler and requires far less code.
#10
I honestly don't think I have enough experience to even follow your blog, but I'll try.
04/20/2013 (1:39 pm)
So I'll follow your blog step by step, but what will I ultimately need to do to get what I want out of the moon?I honestly don't think I have enough experience to even follow your blog, but I'll try.
#11
First, everything exists on a main GUI control called "Canvas". All GUI controls you create that you want to see should be pushed to Canvas. Your stock TGB game has a single t2dSceneWindow, which is a GUI control. That is pushed to the canvas. In stock TGB, you usually have a single t2dSceneGraph, which is loaded into you t2dSceneWindow. So this is the stock hierarchy:
Canvas
--t2dSceneWindow
---t2dSceneGraph
Out of the box, without modifications, you are usually only working with a single window and multiple levels. When you are using the editor, you are modifying the a t2dSceneGraph of your choice, which is what you know as a level. All of the scripts we provide account for a single t2dSceneWindow, which is named SceneWindow2D. That will load the levels you are working on.
My blog covers the concept of creating a second t2dSceneWindow, which will load a separate t2dSceneGraph. This second t2dSceneGraph, while just a level, can represent a GUI using sprites. In your case, one of those sprites would be the moon. In your main level, you have your game objects like the player, which move around. The second t2dSceneGraph does not move based on camera. It's just a static scene that does not move, regardless of what your game does. This would be the new hierarchy:
Canvas
--t2dSceneWindow (game window)
---t2dSceneGraph (game level)
--t2dSceneWindow (GUI window)
---t2dSceneGraph (menu level)
The "menu level", can be created and edited just like any other level:
1. Open the TGB editor
2. Create a new level
3. Add your moon
4. Position the moon based on how you want it to appear during the game
5. Save
From there, you can look at my blog to see how to create the second t2dSceneWindow and load the your static level containing the moon. Now, the one big catch is that my blog was targeting iTorque 2D. You are using Torque Game Builder, so some of the files and scripts are different.
This post just covers the concept. I don't have TGB installed on this machine, so I can't dig up all the changes that would be required to convert my blog to a TGB project. Hopefully another user here can help translate between the two engines.
If you are still stuck, just shoot me an e-mail. My e-mail address is listed in my profile. Just use a subject title along the lines of "Lexi: Need help with moon level". That should catch my attention.
04/20/2013 (2:33 pm)
@Lexi - Alright, I'll break it down step by step.First, everything exists on a main GUI control called "Canvas". All GUI controls you create that you want to see should be pushed to Canvas. Your stock TGB game has a single t2dSceneWindow, which is a GUI control. That is pushed to the canvas. In stock TGB, you usually have a single t2dSceneGraph, which is loaded into you t2dSceneWindow. So this is the stock hierarchy:
Canvas
--t2dSceneWindow
---t2dSceneGraph
Out of the box, without modifications, you are usually only working with a single window and multiple levels. When you are using the editor, you are modifying the a t2dSceneGraph of your choice, which is what you know as a level. All of the scripts we provide account for a single t2dSceneWindow, which is named SceneWindow2D. That will load the levels you are working on.
My blog covers the concept of creating a second t2dSceneWindow, which will load a separate t2dSceneGraph. This second t2dSceneGraph, while just a level, can represent a GUI using sprites. In your case, one of those sprites would be the moon. In your main level, you have your game objects like the player, which move around. The second t2dSceneGraph does not move based on camera. It's just a static scene that does not move, regardless of what your game does. This would be the new hierarchy:
Canvas
--t2dSceneWindow (game window)
---t2dSceneGraph (game level)
--t2dSceneWindow (GUI window)
---t2dSceneGraph (menu level)
The "menu level", can be created and edited just like any other level:
1. Open the TGB editor
2. Create a new level
3. Add your moon
4. Position the moon based on how you want it to appear during the game
5. Save
From there, you can look at my blog to see how to create the second t2dSceneWindow and load the your static level containing the moon. Now, the one big catch is that my blog was targeting iTorque 2D. You are using Torque Game Builder, so some of the files and scripts are different.
This post just covers the concept. I don't have TGB installed on this machine, so I can't dig up all the changes that would be required to convert my blog to a TGB project. Hopefully another user here can help translate between the two engines.
If you are still stuck, just shoot me an e-mail. My e-mail address is listed in my profile. Just use a subject title along the lines of "Lexi: Need help with moon level". That should catch my attention.
Torque Owner Daniel Buckmaster
T3D Steering Committee