Why are cloned spawn actors destroyed when overlapped and clicked?

swongswong Member Posts: 15

Hi all,

I found a tower defence template and the original (white and red actors in link) where you can click, drag and drop the spawned actor but cannot move once dropped.

What I want to do is - be able to select the spawned actors and move them again (like the blue actors in link) but when you move them together so some of the actor area overlaps, and click the intersection, the latter actor(s) are destroyed.

What's causing this? How can i prevent it from destroying? I can't seem to find any other discussions that relate or have a similar problem.

arcade.gamesalad.com/game/121657

Game attribute:
spawned (boolean false)

'Spawner' Actor (to be clicked to spawn new actors ['newspawnedactor']):

  • spawn actor action - to spawn 'newspawnedactor' relative to actor

  • touch is pressed - spawn 'spawner' actor relative to actor - change attribute game.spawned to true - then destroy 'spawner' (as it spawns again right after touch)

'Newspawnedactor' Actor:

Attribute:
Moveable (boolean true)

  • change attribute - self.color.alpha to 0

  • touch is pressed & if Moveable is true & game.spawned is true - constrain attribute self.position.x to game.mouse.position.x - self.position.y to game.mouse.position.y

  • touch is released - change attribute self.Moveable to false - change attribute game.spawned to false

  • if game.spawned is true & touch is pressed - change attribute self.color.alpha to 1

Now for the blue one - I added - touch is pressed - constrain attribute self.position.x to game.mouse.position.x - self.position.y to game.mouse.position.y

But as you can see from the link, the blue ones destroy when they are overlapped and clicked in a cross over section.

Can anyone help me? I would really appreciate it, and sorry for the long post. Thanks!

Comments

  • MoikMoik Member, PRO Posts: 257

    I think they aren't being destroyed. Just stacked on top of each other. They all get pulled into the same Constrained mouse position.

    Just as a theory, try a Collision rule for Actors of same type, with a Accelerate Toward behavior that has a negative value. That might push them away from each other.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @swong‌ -- @Moik is right. The blue actors are not getting destroyed. They are snapping to the mouse position. (So one is exactly underneath the other one and you can't see it.)

    You need to add an offset take into account where the mouse is clicked on the actor. You need to find the distance from the center of the actor to the mouse. That is the offset.

    Here is how -- in the blue actor, make two actor attributes (type = real) and call them 'offsetX' and 'offsetY'.

    When touch is pressed & Moveable is true & game.spawned is true
      Change Attribute: self.offsetX To: game.Mouse.Position.X - self.Position.X
      Change Attribute: self.offsetY To: game.Mouse.Position.Y - self.Position.Y
      Constrain Attribute: self.Position.X To: game.Mouse.Position.X - self.offsetX
      Constrain Attribute: self.Position.Y To: game.Mouse.Position.Y - self.offsetY
    
  • swongswong Member Posts: 15

    @RThurman‌ - thanks for the help. Does this work for you? Because it isn't working for me :\

    I tried adding the code to the existing rule where those conditions are true; tried with only touch is pressed; tried without touch is pressed rule (the one i added to make it moveable after dropping); and nothing works!

    I understand what you're trying to help me do, but it isn't happening for some reason. The results are just the same.

    Any further help?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @swong‌ -- Yes it will work just fine.
    By any chance did you type those attributes? They need to be selected from the drop down menu in the expression editor.

  • swongswong Member Posts: 15

    @RThurman‌ the actor attributes? Well I need to select real from the drop down menu then type in offsetX and offsetY.

    Unless you mean the conditions and rules? Of course I didn't type them in.

    Hmmmm... so your additional code - should i include that into the existing rule after self.position.x to mouse.position.x and y? Or new rule?

    And will i still want the rule i created - touch is pressed - constrain attribute self.position.x to game.mouse.position.x - self.position.y to game.mouse.position.y?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited May 2014

    @swong -- Its probably easier to experiment with a working prototype. Hold on a minute.......

    Take a look at this example of using offsets when dragging actors. The nice thing is that you can click on the actor and it does not snap to the center. Instead its just a nice smooth mouse drag.

    --RT

  • swongswong Member Posts: 15

    @RThurman‌ Hey thanks man! It looks great, and I'll try to use it to what i'm trying to do, thanks.

    I just found you on another discussion - forums.gamesalad.com/discussion/44456/pinch-spread-rotate which i'm also looking to implement with these actors too.

    I downloaded your CameraRotatePinchZoom zip and works and I'd need to play around with to change to what I want.

    But when I tried to download PinchZoomRotate zip it didn't have a project file, any chance you can re-upload it for me please? Unless they are the same.

    Thanks!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Must be too old or something. Here you go...

  • swongswong Member Posts: 15

    Sorry mate, i'm looking for the PinchZoomRotate one, or is that the same?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Oops try this one. Its quite a bit larger so I put it in dropbox so that it does not clog up the forum.

    http://www.mediafire.com/download/7rdvhu4m377kgtq/PinchZoomRotate.zip

  • swongswong Member Posts: 15

    Sorry to bother you again, but is it just me or is the project file missing again?

    Tried to attach a screenshot but needed to be verified first.

    As I understand, you're a GS pro with mad skills - so I would like to ask:

    If I am using Tshirtbooth's multiscreen menus and the spawner is on a scrollable layer, does that mean my new spawns must be on the same layer too? Is there any way of spawning on a new/different layer or be not scrollable with the menu?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    OK lets try it again!

    http://www.mediafire.com/download/mrvkmkk8ka3dia4/NewPinchZoomRotate.zip

    I don't think I've ever seen Tshirbooth's multiscreen menu template. But if the new actors are not part of the menu system, I don't think its necessary to have new actors spawned on the same scrollable layer.

  • swongswong Member Posts: 15

    Perfect! Thanks a lot.

    Hmm. Well the spawner is part of the scrollable menu system - basically like a list of items and I want to spawn new actors from this list. But the problem is they're spawning on the scrollable layer. Is there a way to spawn on a different layer or not be scrollable?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Hmm... make a new spawner on a different layer? Tell it to start and stop spawning through a game-level attribute?

  • swongswong Member Posts: 15

    @RThurman‌ -- thanks man, your work is genius! Everything you've supplied is perfect.

    I have a question though - when I preview my work in GSC, everything works. But when I upload it to arcade, some things don't work - like, one (of two) pause behaviours and spawning doesn't work as well (if at all), any ideas why this may be happening?

    Also a quick one about publishing - with a free account and no apple developer, is there no way to test/publish my game for personal use? I'm looking to publish it to iPad but I'm using windows.

    And also relating to the previous question - which source would be more reliable for testing towards the final product? Preview or arcade?

    Thanks for your help!

  • swongswong Member Posts: 15
    edited May 2014

    a

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @swong‌

    I don't know much about what works (and does not) in the arcade. But I do know there are differences in performance between arcade and GSC.

    Publishing requires at least a Developer License. This is an apple requirement. (Not sure about publishing to android devices.)

    Testing should always be done on an ad-hock build (on the actual target device) before making it available to the masses. (Definitely don't trust Arcade or Preview as the final build before publishing.)

    Hope this helps!
    --RT

Sign In or Register to comment.