Exchange position of 2 actors... Any easy way?

networnetwor Member Posts: 89
edited November -1 in Working with GS (Mac)
Hi, I want to make this system:

You touch on one actor --> he change his image to highlighted(selected)
Then I touch another actor and this actors exchange their positions ( So Actor01 x = Actor02x, Actor01 y = Actor02y and Actor02 x = Actor01x, Actor02 y = Actor01y)

I know how to make this but what if I need about 20 actors. I must create a lots of attributes and rules... Is there any easiest way? Maybe I'm missing something...

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you would need attributes for each actor you want to switch with like you said
  • networnetwor Member Posts: 89
    Ok, this is what I want to know... Thanks :)
  • simo103simo103 Member, PRO Posts: 1,331
    could you not use just 5 attributes?

    TouchCount
    Touch1X
    Touch1Y
    Touch2X
    Touch2Y

    Change attribute Touch1X and Touch1Y to selfX and Y when TouchCount=1. Change Touch2X and Y to selfX and Y when TouchCount =2 then trigger the switch (maybe a short Time delay and reset TouchCount to zero)?

    Not sure but think it would work.
  • networnetwor Member Posts: 89
    This looks great, I tried it, but it change position of one block not exchange their position, but great suggestion ! I'll try to get it work :)
  • simo103simo103 Member, PRO Posts: 1,331
    Hey networ ... thought it was an interesting problem so i gave it a try and have uploaded a working template. Search 'switcheroo'' in the GS creator New+ section and let me know if that is what you were looking for?

    Note: I needed a Self.TouchCounter attribute in addition to the ones above so 6 attributes in total. You can drag more of the Actor1 in the scene and just click to change the color and it will work with more than the 3 actors. I have a MoveTo as the movement but you may want to try interpolate or something for smoother motion.

    hope that helps.
  • networnetwor Member Posts: 89
    Yeah, this is what I need! Thank you very much! You're the best man! THANKS its helped me a lot !
  • simo103simo103 Member, PRO Posts: 1,331
    np .. glad to help.
  • networnetwor Member Posts: 89
    I found some bug... Sometimes (I don't know why...) if i click on block they merge together... not exchange their positions. Do you know why ? I can't find the problem... thanks again :)
  • simo103simo103 Member, PRO Posts: 1,331
    I was able to recreate that issue just now after reading your post. I did it if I clicked quickly on numerous blocks before the first two completed their move.

    I believe it is because I have a slight delay timer in the code to reset the TouchCounters back to zero. You may need to play around with the timer (ie make it a smaller time or even try without it). Also try Interpolate rather than move.

    I will try again later today to see if I can solve it but post if you get it resolved and how. I am also a little concerned the issue might be with the known self bug that the new version of GS has and thus may need to wait for the update to be sure.
  • networnetwor Member Posts: 89
    I played arround with timer, but no succes. I'm using interpolate now, it looks better then"move to", but it still buggy... :(
  • simo103simo103 Member, PRO Posts: 1,331
    I added a Condition to the Actor so it says when actor is touched AND when TouchCounter does NOT equal 2 then all the touch and movement stuff happens.

    I also set the time to switch Touchcounter back to zero at 5 seconds just so I could test clicking around and it seems to work. The issue is having the timer NOT change TouchCounter until the actors have arrived at their destination but not so long as it messes with gameplay.
  • networnetwor Member Posts: 89
    Can you upload it? Thanks you :)
  • simo103simo103 Member, PRO Posts: 1,331
    uploaded .. may need to quit and reopen GS for it to show up (at least I did).

    Note: I have it set at 5 seconds before the TouchCounter is reset to zero which is crazy long but allows you to click around to see if the logic fails. Change that interval and maybe consider a visual for the game player like maybe a 'Moving' image that Alphas to zero once the next touches are being accepted, or the actors flash or something depending on your game?
  • networnetwor Member Posts: 89
    Hi, i played around with it today. It looks really great, its better now, but it still sometimes fail. I dont know what i did if it failed...
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    if you use attributes for each one like i said you can make it perfect
Sign In or Register to comment.