create actor x y when touch is pressed
UtopianGames
Member Posts: 5,692
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.
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
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.
Darren,
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.
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.
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
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.