How do I track the position of an actor properly?

Currently, I have a timer that, every 0 seconds, sets a Game variable to the current position of my actor (both x and y). Then I have a mask that is supposed to track the actor with the constrain attribute.

However, when the actor moves to a certain point in the scene (3/4 of the way to the right or 3/4 of the way up), the mask starts to move differently. I have attached the project I was working on when this happened. The actor that the mask is supposed to track is Frank.

http://www.mediafire.com/download.php?jctxycwpjqmn8g0

Best Answer

  • beefy_clyrobeefy_clyro Posts: 5,394
    edited March 2013 Accepted Answer
    @h.rashid13

    Whose a silly fella then? ;)

    Really easy fix ....

    Ready .....

    Move your mask actor off of the HUD layer, down onto the scrollable layer where Frank is :)

Answers

  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    @h.rashid13 - Hey, this should answer your question. Instead of having a timer that changes the variable every 0 seconds, use the 'Constrain attribute' behavior. So, constrain game.xpos to self.position.x. The same goes for y.
    Then you can tap in to the game.xpos variable wherever you need.

    Hope that helps,
    - Thomas
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @h.rashid13 @SnapFireStudio

    I would probably go with what Thomas has said. So constrain the mask to game attributes and then constrain the actual character to the game attributes ...

    Alternatively, you can cut out one set of constrains by unlocking the prototype into an instance (your character) and then you can constrain the players self.position to scene > Layers > Correct Layer > Mask

    This can save you constraining the mask to game attributes
  • h.rashid13h.rashid13 Member Posts: 4
    @beefy_clyro @SnapFireStudio

    I tried out constraining the the mask to Game and constraining Game to the actor, but the mask is still exhibiting the odd movement.

    If you tried to play the game, you'd notice that as you move right, the mask will suddenly move farther right than the actor. I feel as though gamesalad is not reading the actor's position correctly.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Just to confirm

    game.maskX to self.positionX of mask
    game.maskY to self.positionY of mask

    self.positionX to game.maskX in character
    self.positionY to game.maskY in character

    That would work fine .. unless you have some conflicting rules somewhere.

    I went to look at your project but its in windows format and I dont have the converting method.
  • h.rashid13h.rashid13 Member Posts: 4
    Wait. The game.mask variables are currently integers. Should they be set to real instead?
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    If they're slightly out then they should be real, integers will just round it up in whole pixels
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    Yep, real attributes are best for this type of thing.
    - Thomas
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Just had a quick look and its not that causing the problem ... Hard for me to look at the mo, got some video conversions on the go and its killing my computers performance
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    @beefy_clyro - That's pretty much the feeling I get when I am trying to fix a bug for 2 hours and then I open up the otherwise section... :((
    - Thomas
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Haha I know the feeling all too well .. I'm much better nowadays as after numerous projects and 3+ years of using GS, I have a pretty decent structure now and I now know 'how I think' ... This makes tracking down where things will be put a lot easier :))
  • h.rashid13h.rashid13 Member Posts: 4
    Ah! Thank you so much! Fixed the mask issue! :D
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    No worries, good luck with the rest of your game
Sign In or Register to comment.