Lock position with 1 or 2 actors involved

StormtrixStormtrix Member Posts: 256
edited November -1 in Working with GS (Mac)
Evening,
Kind of stumped :)
in my shapes games i use to have a ShapeBackImage actor and a Shape actor to lock into the slot if touched.
With 20 shapes (like square, circle, triangle, etc.) that would be 40 actors.. it was easy to have them lock
into place - once square overlaps ShapeBack-square then would lock with an attribute and the BackImage's x,y..

Well i'm trying to optimize here and do the same thing with 1 or 2 actors and just instances.
So here's what i'm trying to start with -

(Actor 1) ShapeSlot image Square
Rule - If game.square=1
constrain game.lockX To: self.position.x
constrain game.lockY To: self.position.y

(Actor 2) ShapeSquare
Rule - If pressed -- All conditions --
attribute: self.Clicked is false

change attribute: game.square To: 1
2 constrain touch movement attributes

Lock Rule - All conditions -
game.square=1
self.position.x = game.locx
self.position.y = game.locy

constrain self.position.x To: game.LockX
constrain self.position.y To: game.LockY
change attribute game.square To: 0
change attribute self.clicked To: True

So - square moves over the squareback image it should lock it there.
doesn't work... if i add like a +5 to the game.LockX and Y on lock rule then it locks but it
locks when i'm far away from the image/actor.

Here is an example of my old way with 4 individual actors.
http://gamesalad.com/game/7940

any help would be great..
Thanks!
Storm

Comments

  • StormtrixStormtrix Member Posts: 256
    (slowly creeps into room trying to be sneaking and BAM 'bumps' into the forum)
  • MotherHooseMotherHoose Member Posts: 2,456
    looking at your background img... (is it 1 image? can work that way)... presume that the grey shape areas are in a sorta-grid arrangement.... easy to figure out each column's X and each row's Y... and thus the correct coordinates.

    then on drag-able shape...
    Nested rule:
    Rule (Any) when
    Attribute...self.Position.X ≤ exp: correct X for the shape + 5 (or ten)
    Attribute...self.Position.X ≤ exp: correct X for the shape - 5 (or ten)

    --Rule (Any) when
    Attribute...self.Position.Y ≤ exp: correct Y for the shape + 5 (or ten)
    Attribute...self.Position.Y ≤ exp: correct Y for the shape - 5 (or ten)
    ----ConstrainAttribute...self.Position.X To: correct X ...
    ----etc. (think I used interpolate... instead of constrain)

    if you have a boolean Attribute for each shape...set to false... and enclose your drag Rule in when false drag-able
    then when in the correct place change that attribute to true... should only enable drag if false and the shape should hold placement.

    MH
  • StormtrixStormtrix Member Posts: 256
    Thanks for the reply MotherHoose,
    Tried your suggestion which makes sense but doesn't work.. it'll goto the actor-shape-background still even if you are 100+ pixels away... it won't make it precise with + or - 5 pixels... it's weird.

    the background images will be randomized so they'll be in different locations each game.. each of those actors/instances will have a rule to constrain the game.locationX / game.locationY to self.positionX and Y

    that way the actual shape actor will loc into that position if it meets the right rules..
    think about ready to give up and just use 20 separate actors and do the overlaps rule.
Sign In or Register to comment.