math - column calc

paranoid_androidparanoid_android Member Posts: 22
edited November -1 in Working with GS (Mac)
I would like to identify which column my actor is in. I am dividing the screen into 4 (480/4 = 120), and I must include the camera offset.

in other apps I would use

int ( (self.postition.x - game.cameraX) / 120 )

How can I accomplish that here
@pa

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Use Column = floor(abs(self.position-game.cameraX)/120)
    That should give you 0,1,2,3 for the values. And 4 if you are at the right border.

    in a scene that is 480 width, actor position 0-119 is the first column, 120-239 is the second column, 240-359 is third, 360-479 is fourth, and 480 is fifth.

    If you want to include that 480 in the 4th column add the min function.
    Column = min(3,floor(abs(self.position-game.cameraX)/120))
  • paranoid_androidparanoid_android Member Posts: 22
    CM - that works perfect thanks
  • paranoid_androidparanoid_android Member Posts: 22
    Here is my next challenge. I am trying to figure out the math for the row the actor is in. But since there is a perspective involved, the math will be uneven.

    I would like to use a similar expression as above. Have a value range for each row.

    The range would actually be a tolerance. (ie 10px)
    row1 actor width = 117 (range 97-127)
    row2 actor width = 85 (range 75-95 )
    row3 actor width = 72 (range 62-82)

    I could create a game variable for each row value. I know I at least have to have row1.

    Ultimately I would like to do it with 1 game variable, and one prototype behavior.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    are those all the rows you have? If not, how many rows do you have and what are their ranges?
    Are the ranges supposed to overlap?
  • paranoid_androidparanoid_android Member Posts: 22
    in total there are 12 instances of the prototype. Four columns by three row. So the ranges I've posted are it.

    The ranges are not suppose to overlap. The reason I have ranges, is to allow for slight variation in the placement and sizing of the actors.

    I wonder if thinking in percentages is a better way to solve this. In the end the behaviour has to set the prototype variable to 1,2,or3.
Sign In or Register to comment.