Anchor Scene Behavior to Screen?

KitsuneQuills

  • Posts: 14
Hello. I'm working on a project where the player moves an actor by typing in a text box (using Tuo's "Demo- Real Text Boxes" scene behavior codes). It seems to work great, except that I can't get the text box to anchor to the screen. No matter what I try, it just scrolls with the scenery. Any ideas? The (very rough) alpha test version is available on StencylForge under the name "Noventure Alpha" if you want to give it a try or look at the code. I haven't imported any of my own graphics yet, obviously. The name "Noventure" is a play on "novel" and "adventure," but it's just a working title that I'll most likely change later.

Photon

  • Posts: 2691
Wherever you are setting x/y of the text box (or however location is set), add the appropriate x/y of camera to those values.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

KitsuneQuills

  • Posts: 14
Oh. Thank you! That sounds so simple. I'll give it a try.

KitsuneQuills

  • Posts: 14
Erm, the x,y is set using the following code. How would I insert the camera x,y in there?

      public var _X:Number = 30;
      public var _Y:Number = 300;
      public var _Width:Number = 575;
      public var _Height:Number = 120;
      public var _TextSize:Number = 25;
      public var _Attribute:String = "DelayText";

Dax85

  • *
  • Posts: 97
I looked at your project on stencylforge and saw that you dont use any actor for the textbox, but simply draw a box and work over it. Easiest way would be to make a specific actor "textbox" and anchor that to the screen.
Otherways you can try using
Code: [Select]
_X:Number = getScreenX();

KitsuneQuills

  • Posts: 14
Hmm, the "_X:Number = getScreenX();" didn't seem to work. Now I'm trying to figure out how to create a "textbox" actor that I can attach the code to, and make it show up on the screen.

Edit: I guess what I want to do is attach the behavior to a HUD actor, but I'm not sure how to do that since Tuo originally designed the code to be a behavior that attaches to the Scene. Sorry, I'm really new at this.

« Last Edit: November 21, 2013, 09:49:16 pm by KitsuneQuills »

Photon

  • Posts: 2691
Make sure you are constantly updating the "_X:Number" to the camera/screen X (plus whatever offset you want to add onto it). If you just set it in a "when created", it won't move like you want it to.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

KitsuneQuills

  • Posts: 14
Make sure you are constantly updating the "_X:Number" to the camera/screen X (plus whatever offset you want to add onto it). If you just set it in a "when created", it won't move like you want it to.

I think that's the problem I've been having. This behavior I'm using forces me to work with the raw code, which is something I'm not used to. I've been trying to figure out what to do by making temporary behaviors in design mode, then looking at the code, but none of the blocks seem to use anything like the x,y commands I'm trying to modify.

Code: [Select]
_X:Number = getScreenX();
That worked the same as the original code, but I'm trying to offset it by +30 pixels and make it constantly update.

Photon

  • Posts: 2691
The offset part is simple. Just write:

_X:Number = getScreenX() + 30;

As for updating it consistently... let me see if I can't pull up the code myself...

EDIT:

OK, I'm back. You see this part of the code?

Code: [Select]
addWhenUpdatedListener(null, function(list:Array):void
{
if(wrapper.enabled)
{
setGameAttribute("" + _Attribute, inputField.text);
}
});

Try this:

Code: [Select]
addWhenUpdatedListener(null, function(list:Array):void
{
if(wrapper.enabled)
{
_X = getScreenX() + 30;
_Y = getScreenY() + 30;
setGameAttribute("" + _Attribute, inputField.text);
}
});

« Last Edit: November 22, 2013, 11:31:12 am by Photon »
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

KitsuneQuills

  • Posts: 14
The code you suggested is viable, but doesn't seem to anchor the text box to the screen. The behavior acts the same as the "Noventure Alpha" demo currently on the Forge. I'm starting to think that my only option is to somehow turn this text box into an actor that I can anchor to the screen. I don't know how to do that either. I have been able to convert the code into an actor behavior that attaches successfully (to an actor added to the scene) and lets the game load, but the text box is nowhere to be seen during actual gameplay. I'm probably doing it wrong. The reason I'm trying to use Tuo's "Demo- Real Text Boxes" instead of any of the other available text boxes is because I want to be able to select and copy the text. I also want to be able to type and move the player actor at the same time by pressing the same keys.

Thanks for all your help. If I can't figure this out soon, I should probably shelf this project until I learn a bit more about coding and game making.

KitsuneQuills

  • Posts: 14
So any ideas on how to draw this text box on an actor? Keep in mind that I'm using "real" code for this, not design blocks. I'm not opposed to utilizing design blocks, I just haven't been able to get the code to work with them.

There are also two other ideas I'm considering for this project (if I can't get the text box to anchor):

1: Keep the camera stationary and turn the ground into an actor (or actors) that move left when the space bar is pressed. With the right animations, this could create the illusion that the player character is walking right.

2: Abandon the whole idea of a side-scroller and turn this project into a single-screen platformer that uses regions to determine whether the space bar makes the character step, climb, or fight. When they reach their mini-goal number of words, it will move on to the next scene. I know. It doesn't sound like the most fun game. The focus is really more on motivating people to type more.

Any programming suggestions you guys have would be more than helpful.