Spawning Actor at Mouse Position when click pressed
Cataloupe
Member Posts: 3
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 ?
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
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
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
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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
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