Page 1 of 2

Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 3:12 pm
by kickstart
How can a filled region control the y velocity of a normal actor? I cannot figure this out and help would be greatly appreciated.
:D

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:01 pm
by skydereign
If the filled region is supposed to only control one actor, and there are no clones of the actor, it is pretty easy. For this I'll assume you are trying to control an actor named player.
filled -> Mouse Button Down left -> Script Editor
Code: Select all
player.yvelocity = -15;

Now this would act as a jump button though it does allow for infinite jumps. You can access any other variables in this method, but it won't work properly if there are multiple player actors, in which case you have to use more advanced methods.

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:17 pm
by kickstart
Okay, and what way could I make this possible for an infinite jump?

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:22 pm
by skydereign
JetpackGrizzly wrote:Okay, and what way could I make this possible for an infinite jump?

Do you mean finite? If so there are plenty of jumping tutorials on the forums. The idea of it though is you create a jump variable, that holds if the player can jump, and set it to 0 after the player jumped.

The method I mentioned allows for infinite jumps, since there is no limit to the number of times you can click the filled region. And if there is no gravity, it will just set the player's yvelocity to -15, making them go up until you change it.

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:43 pm
by kickstart
Well I am in the process of making my game meant for a touch screen, or an iPhone to be specific. I know already about jumping, and have it set for my actor already, with gravity and everything, however it uses the space bar. How can I make the filled region act as the space bar, or work exactly like it? (If I hold in the space bar the actor continues to rise, but for a click it does not.)

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:46 pm
by skydereign
JetpackGrizzly wrote:How can I make the filled region act as the space bar, or work exactly like it? (If I hold in the space bar the actor continues to rise, but for a click it does not.)

What you need is a variable stating if the actor is clicked or not. You can make one that does that by setting it to 1 when the button is clicked, and setting it to 0 when it is released. That's just a matter of having a mouse button down and mouse button up event. With that, you can put in the button's draw actor the jump code.

Another alternative is to put the code in the player's draw actor, that way you don't have to change any of the "Event Actor" and yvelocity calls from your space bar event. You just need to make sure you are checking the variable.

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 7:57 pm
by kickstart
skydereign wrote:
JetpackGrizzly wrote:How can I make the filled region act as the space bar, or work exactly like it? (If I hold in the space bar the actor continues to rise, but for a click it does not.)

What you need is a variable stating if the actor is clicked or not. You can make one that does that by setting it to 1 when the button is clicked, and setting it to 0 when it is released. That's just a matter of having a mouse button down and mouse button up event. With that, you can put in the button's draw actor the jump code.

Another alternative is to put the code in the player's draw actor, that way you don't have to change any of the "Event Actor" and yvelocity calls from your space bar event. You just need to make sure you are checking the variable.


Okay, I got it, thanks. So it there a way I can make a variable if the button is pressed, it will act as a space bar being pressed without actually physically needing a space bar?

Re: Filled Region controlling normal actor help needed!

PostPosted: Wed Jan 30, 2013 8:01 pm
by skydereign
JetpackGrizzly wrote: it will act as a space bar being pressed without actually physically needing a space bar?

That's what I'm saying. You set a variable when your game's jump button is pressed. Set it back to zero when you release the button. That way in the player's draw event, you can put the same code you had in your space bar event, within an if statement. This makes it so you don't need to actually press the space key (you technically don't need to have the space keydown event anymore, but you might keep it for testing on computer).
player -> Draw Actor -> Script Editor
Code: Select all
if(jump_button_pressed==1)
{
    // your code that was originally in the space key down event goes here
}

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:37 pm
by kickstart
Okay, thank you so much. Although I ran into the biggest problem of all,
:evil:

How can the animation change of the actor from the filled region? The velocity will, but the animation refuses to.
(It uses a series of cases and states to change the animation correctly.

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:41 pm
by skydereign
Make sure to change the correct actor's animation Normally it is "Event Actor", so you need to change that to "player" or whatever your player actor's name is. If you did do that, then the problem is that your player code is updating the animation when you don't want it to, and we'll need to see more code to be able to help with that.

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:51 pm
by kickstart
skydereign wrote:Make sure to change the correct actor's animation Normally it is "Event Actor", so you need to change that to "player" or whatever your player actor's name is. If you did do that, then the problem is that your player code is updating the animation when you don't want it to, and we'll need to see more code to be able to help with that.


So on MouseButtonDown the animation changes the flying, and MouseButtonUp, running. Making the filled region do this, I have more or less just pasted the same exact code into the MouseButtonDown of the filled region.

Filled Region>Mouse Button Down>Script Editor:

Code: Select all
touch = 1;
switch(currenttexture)
{
    case 0:
    switch(state)
    {
        case 0:
    ChangeAnimation("Jumper", "charRight", FORWARD);
    break;
 
    case 1:
    ChangeAnimation("Jumper", "flyingg", FORWARD);
    break;
    }
    break;
 
    case 1:
    switch(state)
    {
        case 3:
        ChangeAnimation("Jumper", "flyingp", FORWARD);
        break;
 
        case 2:
        ChangeAnimation("Jumper", "runningp", FORWARD);
        break;
    }
    break;
 
    case 2:
    switch(state)
    {
        case 4:
        ChangeAnimation("Jumper", "runningpanda", FORWARD);
        break;
 
        case 5:
        ChangeAnimation("Jumper", "flyingpanda", FORWARD);
        break;
    }
}

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:55 pm
by skydereign
So that code should work, unless the actor Jumper is also updating the player's animation. It gets a little trickier if that is the case, which it seems to be. What does the draw event for your Jumper actor look like?

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:58 pm
by kickstart
Code: Select all
switch(touch)
{
    case 0:
    yvelocity = yvelocity + .7;
    break;

    case 1:
    yvelocity = -6.5;
    break;
}
 


Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 6:59 pm
by kickstart
JetpackGrizzly wrote:
Code: Select all
switch(touch)
{
    case 0:
    yvelocity = yvelocity + .7;
    break;

    case 1:
    yvelocity = -6.5;
    break;
}
 


That is under Jumper>Draw Actor.
The change animation is under key up and key down. (Space)

Re: Filled Region controlling normal actor help needed!

PostPosted: Tue Feb 05, 2013 7:03 pm
by skydereign
So is the problem that the animation never changes? Or is it that the animation changes, but is changed back to something else immediately? They may look the same at first, but you can find out by disabling all events for your player/button actors using EventDisable. That way nothing should be able to change Jumper's animation. If it is the correct animation after the mouse button down, then you know it is something else changing the animation afterwards. If it didn't change, that just means some of your variables used in the switch statements aren't the values you think they should be.