create actor x y when touch is pressed

UtopianGamesUtopianGames Member Posts: 5,692
edited November -1 in Working with GS (Mac)
Hi Guys,

Learning loads from this forum and videos etc but cant seem to find a solution for below,

Create an actor at x y relative to touch and if finger is still touching (pressing down on iphone) follow finger/touch....when finger is released destroy actor.

Actor will be a circle between 30-50 in radius.

Sorry if it's unclear whay im trying to do.

Darren.

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    I'm not in front of my GS right now, but I believe you will have to do this:

    Create a background Actor the size of the iPhone screen.
    Create the small circle foreground Actor called `Target.`
    Create a boolean Game Attribute called `SpawnedByTouch` that will hold the status of whether or not the foreground Actor has spawned.

    In the background Actor, give it these Rules:
    - if touch is pressed AND `SpawnedByTouch` is false, set `SpawnedByTouch` to be true, then spawn `Target.`
    - if touch is released, set `SpawnedByTouch` to be false.

    In the `Target` Actor, create this Behavior and Rule:
    - Constrain Attribute `Target.Position.X` to `Mouse.Position.X.`
    - Constrain Attribute `Target.Position.Y` to `Mouse.Position.Y.`
    - if `SpawnedByTouch` is false, Destroy Actor.

    Hope that helps.
  • UtopianGamesUtopianGames Member Posts: 5,692
    Thank you i will try that asap.

    Darren,
  • UtopianGamesUtopianGames Member Posts: 5,692
    Still having trouble with this.....tried what you said but cant find spawnedbytouch in the target actor to set it to false.

    Do i need to create 2 spawnbytouch booleans (one for background and one for the target)...i did try this but it still didnt work.

    I also changed the mouse.position to touch.position.

    Darren.
  • UtopianGamesUtopianGames Member Posts: 5,692
    Hi tshirtbooth,

    Similar..just looking at your code now.

    Scene starts..no actor is in the scene.

    Player touches screen and actor appears and follows the touch so player could move all around the screen with actor following.

    Player lifts finger off screen = destroy actor.

    Repeat.

    Darren.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I would do something like this:

    Create a global game attribute (boolean) called something like "TouchingScreen".

    Create an actor - a simple box is fine. Name it TouchController or something like that.
    Place it in the Scene just out of view.

    In the TouchController actor, create two Rules like this:

    Rule
    All
    When Touch is Pressed
    When game.TouchingScreen is FALSE
    Change Attribute: game.TouchingScreen to TRUE
    Spawn Actor

    Rule
    When Touch is Released
    Change Attribute: game.TouchingScreen to FALSE

    In the spawned Actor:

    Constrain Attribute
    self.Position.X To: game.Touches.Touch1.X

    Constrain Attribute
    self.Position.Y To: game.Touches.Touch1.Y

    Rule
    When game.TouchingScreen is FALSE
    Destroy Actor

    Hope this helps!
    Joe
  • UtopianGamesUtopianGames Member Posts: 5,692
    BIG thanks guys.

    Hope to show you the game soon.

    Really pleased i joined GS, you guys rock!

    I can see where i was going wrong now....i was setting up variables in the actor instead of game.

    Darren.
Sign In or Register to comment.