Touch to fire

PortgasPortgas Member Posts: 71
edited November -1 in Working with GS (Mac)
I have no idea how to make "gun" shoot in specific place where i tap on screen (click mouse button)
can anyone help me with this? tried to understand something from demos but i cant make my gun shoot at all(

Comments

  • ChobbifaceChobbiface PRO Posts: 491
    In your background actor, make a rule:

    When actor receives event 'mouse button' is 'down'

    Then drag in behaviour:

    Spawn actor:
    Then select your bullet actor.
    For the position, set it as mouse.position.X for the 1st box,and mouse.position.Y for the second box and set it to 'relative to scene' in the last box. That should work.

    Chobbipod
  • HachikoHachiko Member Posts: 330
    chobbipod, that way the bullet would be spawned right where he touches, I think.
    To make the bullet spawn at the point of the gun AND go to where you touch, do something like:
    In the gun ->
    when screen is touched then game.where = vectorToAngle(gun.x-mouse.x, gun.y-mouse.y), spawn bullet at gun.x, gun.y .
    In the bullet -> changeVelocity to game.where .

    And that should do it. Don't set a move, or else the direction of the bullet will change when you touch another spot, the changeVelocity should fire just once, using the angle of the vector between the gun and the touch to set himself a direction where to travel.
  • ChobbifaceChobbiface PRO Posts: 491
    Hachiko, yes you're right, that's a good point. Thanks, I am still learning a lot about Gamesalad :)

    Chobbipod
  • HachikoHachiko Member Posts: 330
    Was doing a lil template for this, and gamesalad crashed. lol xD
    I lost the habit to save every 5 seconds.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    quick and dirty method:

    create actors called bullet and trigger, bullet sized 10x10 and trigger the size of the window, so 480x320
    create two global attributes, touchX and touchY

    on the trigger actor have a rule that says
    when actor receives touch
    set game.touchx to touch.position.x
    set game.touchy to touch.position.y
    spawn bullet at position 0,0 relative to scene

    on the bullet create two new attributes called X and Y

    then put a few rules:
    change attribute self.X to game.touchX
    change attribute selft.Y to game.touchY

    moveto self.X, self.Y

    this way, every time you touch the point is recorded, when a bullet is spawned it saves a local copy of that point and moves to it from the lower left of the screen, you can click multiple times and each one will go to it's own point.

    but do a search, there are a TON of threads on this, and there might be better ways than mine.
  • HachikoHachiko Member Posts: 330
    Done with the template. Man, it crashed twice =_=.
    Just some blank square, but it should help anyway.
    Basically it's done with just one game.variable, a rule, a change attribute, a spawn. And a change velocity in the bullets. That's it.
    I added a way to get a delay between a shot and the other, that means that you can't shoot 100 bullets in 1 sec if I don't want you too. Just change the variable delayBetweenBullets in the gun to raise up or low the delay.
    Since gamesalad didn't let me upload it, I uploaded the gameproj to megaupload :)
    http://www.megaupload.com/?d=S4LGZNYA
  • PortgasPortgas Member Posts: 71
    thanks a lot!
Sign In or Register to comment.