Spawning Actor at Mouse Position when click pressed

Hi there, just started out on Game Salad, and have to say its looking pretty good. Ive followed a few good tutorials around a 'continuous running' game style, and now have a character running, jumping and falling. All good. I am now however stuck on another feature.

I want to click the mouse button (eventually 'touch' the screen) and spawn an actor at that point. Ive tried various options like have a large mouse click actor the size of the screen then spawn a 'bubble' actor at the mouse click, and also just spawning an actor at the mouse position...but it either spawns at the middle of the screen in the 'large mouse click actor' scenario or follows the mouse cursor around. I know its a noddy problem, but somehow can't crack it.

Any ideas ?

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2014

    Hi @Cataloupe Welcome to GameSalad and to the Forums. :-)

    Your problem is very straightforward. Firstly, you do need an actor - probably your background - which covers the screen, which will register where you touch.

    In its Rules, put:

    Rule: when touch is pressed
    Spawn YourActor - in the x position, put game.Touches.Touch1.X and in the y position, put game.Touches.Touch1.Y, both via the Expression editor, and set Relative to scene.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CataloupeCataloupe Member Posts: 3
    Hi Gyroscope, thx for the response !

    Maybe Im confused with touch as Im testing using mouse click, but Ive added the actor 'MouseClickZone' which covers the entire screen. In there I have the Rule set up Actor Receives.Mouse Button.Down, and the Behaviour is Spawn Actor ('Bubble' in this case), and Expression of 'self.Position.X' and 'self.Position.Y' with Relative to scene. Is that correct in this case do you think ?

    thx
  • CataloupeCataloupe Member Posts: 3
    Thought Id also mention that the 'Bubble' always spawns in the centre of the MouseClickZone regardless of where I click.
  • CataloupeCataloupe Member Posts: 3
    Think I got it sorted...got the spawning as you said...only thing is, how to get the actors destroyed too so there is only one...
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Gyroscope, thx for the response !

    Maybe Im confused with touch as Im testing using mouse click, but Ive added the actor 'MouseClickZone' which covers the entire screen. In there I have the Rule set up Actor Receives.Mouse Button.Down, and the Behaviour is Spawn Actor ('Bubble' in this case), and Expression of 'self.Position.X' and 'self.Position.Y' with Relative to scene. Is that correct in this case do you think ?

    thx
    Hi again, your actor "MouseClickZone" covering the scene if fine. But in the x and y positions in the Spawn behaviour, you don't have self.Position.X or Y, you have game.Touches.Touch1.X and game.Touches.Touch1.Y. These are found via the Expression Editor in Devices > Touches > Touch 1.
    Thought Id also mention that the 'Bubble' always spawns in the centre of the MouseClickZone regardless of where I click.
    If you amend as I suggest above, that won't happen any more...
    Think I got it sorted...got the spawning as you said...only thing is, how to get the actors destroyed too so there is only one...
    Give me a short while and I'll think of a way here...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    OK, here's the way I'd tackle it so that if there's a Bubble actor on-screen when you touch for another one, it destroys itself:

    I'd make a game boolean attribute, let's call it Toggle, and then I'd make an identical actor in the Inspector of the actor Bubble, call them BubbleA and BubbleB.

    & then amend the Rules in your background like this:

    Rule: when touch is pressed
    Rule --nested in above rule-- : When game.Toggle is false
    Change Attribute game.Toggle to true
    Spawn BubbleA - in the x position, put game.Touches.Touch1.X and in the y position, put game.Touches.Touch1.Y, both via the Expression editor, and set Relative to scene
    Otherwise
    Change Attribute game.Toggle to false
    Spawn BubbleB - in the x position, put game.Touches.Touch1.X and in the y position, put game.Touches.Touch1.Y, both via the Expression editor, and set Relative to scene

    ---
    --then in BubbleA in the Inspector:

    Rule: When game.Toggle is false
    Destroy

    --and in BubbleB in the Inspector:

    Rule: When game.Toggle is true
    Destroy

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Actually, you can have the test file I checked it out with, if you like:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.