Trying to get my paddle to start in the correct position
stannen
Member Posts: 16
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?
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
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
Constrain Attribute: self.Position.Y To: max(self.bottomLimit,min(self.TopLimit,game.Mouse.Position.Y))
Is that what you have?
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