How can I press a button (actor) and have another actor move ?

xyloFUNxyloFUN Member Posts: 1,593
edited November -1 in Working with GS (Mac)
Howdy,
my coffee has not kicked in yet ....

How can I click on a button (actor) and have another actor holding an image moves 50 pixels left.
When I click the button again, the image moves another 50 pixels left ....

I've looked for a tut ... but for some reason nothing suitable popped up!

If anyone can help me with this, I'd be very grateful! :)

P.S. Even pointing me to a tut will do ... i love to learn :)

Comments

  • xyloFUNxyloFUN Member Posts: 1,593
    never mind ... AppTrainer covers it nicely :)
  • xyloFUNxyloFUN Member Posts: 1,593
    OK I spoke too soon!

    Here is what I need to do ...

    When i click on an actor, I want another actor or move x units in one direction

    Do I need to read up an "joystick" control tutorials or is this something different?
    So far, I haven't found a tut that covers that. - thanks :)
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    You mean click, or when your holding it down?
  • xyloFUNxyloFUN Member Posts: 1,593
    John,
    yes. I want to click once and have an image move down say 50 pixels. When I click again, I'd like to move another 50 pixels .... repeat that as necessary

    Also, do you know how I can cover an actor so that once it is bellow another actor, it is no longer movable?
  • simo103simo103 Member, PRO Posts: 1,331
    Hi xyloFUN .. I'm fairly new here .. but want to contribute as I am taking advantage of others help also. That said someone may want to correct me if any of this is wrong.

    First create two actors (one the button, the other the object). Then create an attribute like ButtonTouch can be an integer and a value of zero.

    Click on the button actor and create a rule 'when actor is touched' and add a behavior 'change attribute' and select the attribute ButtonTouch and change to 1.

    Then click on the object actor and create a rule 'when attribute "ButtonTouch is 1' ... add a behavior 'Move to' and select Self.PositionX +50, a Y position which will match the height the object is already at and a speed.

    then also add a 'change attribute' and change ButtonTouch back to zero.

    I believe that should be all you need.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    simo103 said:
    Hi xyloFUN .. I'm fairly new here .. but want to contribute as I am taking advantage of others help also. That said someone may want to correct me if any of this is wrong.

    First create two actors (one the button, the other the object). Then create an attribute like ButtonTouch can be an integer and a value of zero.

    Click on the button actor and create a rule 'when actor is touched' and add a behavior 'change attribute' and select the attribute ButtonTouch and change to 1.

    Then click on the object actor and create a rule 'when attribute "ButtonTouch is 1' ... add a behavior 'Move to' and select Self.PositionX +50, a Y position which will match the height the object is already at and a speed.

    then also add a 'change attribute' and change ButtonTouch back to zero.

    I believe that should be all you need.

    This is correct. Just make sure when your chaning the attribute to 1 its in the touch is pressed rule, and in the rule when you change it back to zero its when touch is released. Let me know if you run into any trouble
  • xyloFUNxyloFUN Member Posts: 1,593
    Thanks guys,
    that is excellent!

    I will tend to this in a minute ... first i have to figure out why my piano keys are flying up in the air after playing for a few minutes??????
  • xyloFUNxyloFUN Member Posts: 1,593
    I just tried to follow the instructions and experiment so that I wouldn't have to ask more questions but .... i have to!

    I made the two buttons you suggested!

    Where do I create the attribute "ButtonTouch" in the scene or on one of the 2 buttons??

    Also, navigating to "Self.PositionX is hard because I can't type it in like in ActionScript. Maybe it was not possible to do because the attribute was not created correctly in the first place? I created it in the scene ... was that wrong?

    thanks :0
  • simo103simo103 Member, PRO Posts: 1,331
    the attribute ButtonTouch is created in the left upper window when looking at your scene (it should have Actors/Attributes/Devices at the top so click attributes and then click the + sign to add one. You will need to click on it to edit the name and make it ButtonTouch.

    The Self.Position.X part you get when adding the moveto behavior ... where it show position: and a right arrow (ie: X axis) click on the 'e' .. then teh first down triangle and it should show three (or more items ... Game, Devices and then Actor names). select the Actor in which you are applying the behavior then Position in the next column that loads and then the X in the next column that shows. You will likely need to double click to get that to load into the field and then click the 'green tick' to apply
  • xyloFUNxyloFUN Member Posts: 1,593
    Simo103,
    THANK YOU for clearing that up and adding the extra information!

    I was not able to get it working but because there has been so much information posted and daily more new users start to work with gamesalad, it would be an advantage and do it proper. In order to save you the typing, I will write out the tutorial and hopefully you or another kind soul will fill in the details :)

    Goal:
    Have 2 buttons in a scene that move an image on the Y axis up or down by 50 pixels as often as clicked

    1) add two actors to your scene, call one button and the other picture
    2) click on "Attributes" (beside Actors) and add and integer attribute with a value of 0
    3 rename the attribute ButtonTouch (double click to rename)

    4) double click the button actor which will open the attributes window bellow the button and to the right of the screen and new page where you can enter rules needed to give an actor functionality
    5) create a new rule > Actor receives event > touch > pressed
    6) drag "Change Attribute" behaviour into that rule: Change Attribute: game.Button.Touch ... > 1

    Click the back arrow (left upper screen) once to leave the button attribute window

    7) double click the actor names "picture (the second one we added at the beginning)
    8) add a rule > Attribute > game.Button.Touch ????? (i'm lost how to do this step?????????)
    9) drag an "Move to" behaviour onto the rule and select (again self. is not an option so I assume "Game" to begin with ????? can you please clarify this as well??

    Please add what ever needs to be done to complete still :)

    I know this is not easy but for those of us who are new to GS, this will help a lot so BIG THANKS for finishing this :)))
  • simo103simo103 Member, PRO Posts: 1,331
    if think you are okay until 6 so I'm going to add in a new 7 and 8 so it gets moved a bit so:

    7) create a second rule >Actor receives event > touch > released

    8) drag "Change Attribute" behaviour into that rule: Change Attribute: game.Button.Touch ... = 0

    9) double click the actor names "picture (the second one we added at the beginning)

    10) add a rule and change the 'Actor receives event' (pulldown) to Attribute click the '...' part select 'Game' then 'ButtonTouch' set it to = 1 (which means when the attribute ButtonTouch is equal to one ie: the button has been pressed)

    11) drag a moveto into that rule where it shows 'position:' and a right arrow (ie: X axis) click on the 'e' .. then the first down triangle and it should show three (or more items ... Game, Devices and then Actor names). select the Actor (which gets named 'self' automatically) in which you are applying the behavior (picture) then 'Position' in the next column that loads and then the 'X'in the next column that shows. You will likely need to double click to get that to load into the field, then type +50 and then click the 'green tick' to apply. so it should look like this: Self.Position.X +50

    think that should do it. Work it thru and come back for further clarification if need be so we can get the instructions clear.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    for 8) when game.button.touch is 1 then have your behaviors under it. And for 9) When you click on the ... to bring up the attributes, its will be game on top, then devices, then under devices will be the name of the actor thats where you want to click. Then go to position, and y. Then in the part where you state where you want to change it to do the same thing, make sure the position.y attribute is in the blue bubble thing, then click to the right of the bubble and type +50 then click the check mark to complete it. THat should do it for you
  • expired_012expired_012 Member Posts: 1,802
    Make 2 game attributes: 1.up, and 2. down

    Make 2 button actors, one for up and the other for down.

    Put the following rule in the UP button:
    When touch is pressed, change attribute game.up to 1....OTHERWISE, change attribute game.up to 0

    Put the following rule in the DOWN button:
    When touch is pressed, change attribute game.down to 1....OTHERWISE, change attribute game.down to 0

    Next go into your moving actor

    Put in the following rules:

    1. When attribute game.up=1

    change attribute: self.position.Y to self.position.Y+50

    OTHERWISE....change attribute game.up to 0

    2. When attribute game.down=1

    change attribute: self.position.Y to self.position.Y-50

    OTHERWISE....change attribute game.down to 0

    If you wanted a left and right button then you would do the same but using the X axis rather then the Y axis...

    And you do not have to use the move to behavior. Remember, the position of the actor is an attribute itself...take advantage of that

    I just made a demo right now, its not letting me upload for some reason tho....email me at artonskyblue(@)gmail(dot)com and I can send over the game file to you if you still haven't worked everything out...

    EDIT:
    OOPS already got beat to it! :)
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    dont feel bad, i got beat to it as well haha :)
  • xyloFUNxyloFUN Member Posts: 1,593
    WOW,
    this will help me a lot guys :)
    But no matter how I tried, this is the best way to let user "make" or create the songs!

    I hope that I can give you a copy once it's done to do some testing? I really appreciate all the help and time you guys have given me :)
  • simo103simo103 Member, PRO Posts: 1,331
    xyloFUN said:
    Also, do you know how I can cover an actor so that once it is bellow another actor, it is no longer movable?

    thought I might give a go at my thoughts on the other part of your query whilst you see if our descriptions above help the first item.

    In this case I think you need to create an attribute say 'Picture2_move' and set it to 1 (1 will mean Picture2 can be moved. Then put you move code into a rule which say when attribute 'Picture2' = 1 ... then the move code will run.

    You will then need to create an attribute for Actor1 positionX and Actor1 positionY and have Actor1 code assign its self.position.x to the appropriate attribute and self.positionY likewise.

    Lastly you would create a rule for Picture2 that says when attribute self.position.x = attribute Actor1_positionX and a second condition of that rule when self.position.Y = attribute Actor1_positionY then drag change attribute and have it set attribute Picture2 to 0.

    thus when the images are in the same position attribute Picture2 is 0 which will not allow you move code to execute.

    Haven't tried it myself but thought it would give you a place to start and for others to redirect you if I'm on the wrong tack.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    :)
  • xyloFUNxyloFUN Member Posts: 1,593
    Well guys,
    it's more or less DONE!! YAY

    If I can figure out why the iPad does not shut off when I run my own app AND when I close the app, WHY it does not start from scene one ... than I'm more or less ready to submit (did a lot of reworking everything)

    Again, thanks! I could have not done this much without your help :)
Sign In or Register to comment.