Trying to get my paddle to start in the correct position

stannenstannen Member Posts: 16
edited November -1 in Working with GS (Mac)
I have a paddle locked at a specific X value and the Y position is constrained to Touch input. As the scene begins the paddle is supposed to start at Y value 160, but every time I test the scene the paddle begins at Y value 0.

My guess is this because there is no touch input when the scene begins. If that is the case, does anyone know how to get the paddle to start where it's supposed to?

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    just have a change attribute in the paddle by its self changing self position y to160. So as soon as the game starts, it will be at 160, then go to the touch like you said
  • firemaplegamesfiremaplegames Member Posts: 3,211
    You can add other conditions to your Rules that check for that scenario, so:

    Rule
    when all conditions are valid:
    game.devices.Touches.count = 1
    .....Constrain attribute: self.position.X To: Mouse.position.X
    otherwise
    .....Rule
    .....when all conditions are valid:
    .....game.playerHasTouchedPaddle = false
    ..........Change Attribute: game.playerHasTouchedPaddle To: true
    ..........Change attribute: self.position.X To: 160

    game.playerHasTouchedPaddle is a boolean attribute that you will create. Use that to initialize the paddle to x = 160. The reason you would need something like that, is so that if the player releases their finger while playing, it doesn't arbitrarily snap to 160.

    You can also add in some expressions to the Constrain behavior so the paddle does not leave the screen, so:

    Rule
    when all conditions are valid:
    game.devices.Touches.count = 1
    .....Constrain attribute: self.position.X To: max(self.leftLimit,min(self.rightLimit,Mouse.position.X))
    otherwise
    .....Rule
    .....when all conditions are valid:
    .....game.playerHasTouchedPaddle = false
    ..........Change Attribute: game.playerHasTouchedPaddle To: true
    ..........Change attribute: self.position.X To: 160

    self.leftLimit and self.rightLimit are integer attributes that you will create in the paddle. Set them to whatever is appropriate. That behavior will now prevent the paddle from leaving the screen, and will not require any other actors - saving you some performance.

    Hope this helps!

    Joe
  • stannenstannen Member Posts: 16
    @firemaplegames Cool! I'll try this when I get home tonight. Thanks a lot! And also thanks for the advice on how to make the paddle stay on the screen. I was trying to block it with invisible walls, but that wasn't working so well.
  • stannenstannen Member Posts: 16
    @firemaplegames Okay, I've fixed the starting position and it works now. But I'm still having trouble with getting the paddle to stay on the screen. The whole "min/max" for the Y position is not making much sense to me. Since my paddle is moving vertically I made attributes in the paddle called "topLimit" and "bottomLimit" but they don't seem to be working.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    The behavior code should be:

    Constrain Attribute: self.Position.Y To: max(self.bottomLimit,min(self.TopLimit,game.Mouse.Position.Y))

    Is that what you have?
  • stannenstannen Member Posts: 16
    Still not working for me. I have it exactly as you said and the paddle keeps leaving the screen. I've even tried putting up collidable walls and they aren't working either. I have no idea what I'm doing wrong. Argh.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    What are the values that you have for bottomLimit and topLimit?

    Just to make sure, all actors use their centers for the registration point. You have to account for that.

    Also, all of your code should only be in the Actor in the Library. When you double-click on the paddle in the Scene, you should see a padlock on the right-hand side.

    You might have some other Rules somewhere that are conflicting, but it's hard to tell without seeing your code.

    If you are still having issues, you can email me your file and I can take a look.

    joe AT firemaplegames DOT com
Sign In or Register to comment.