Possible to tap near an actor to destroy it?
sniffy176
Member, PRO Posts: 48
I've got a game I'm working on where 40+ little blocks are flying around the screen, they are 26 pixels height and width.
You have to tap them to destroy them, simple stuff.
However, when I test it on the Nexus 7, they are actually really difficult to tap on. Not because they are too small, it;s just the tapping doesn't seem 100% accurate.
Is there a straightforward way of being able to tap within a certain distance of the blocks (magnitude?) and still having them destroy?
I can't cheat the actor size, for example make it 34 pixels and have transparent image edges, as the blocks all need to collide as they are flying.
I also want to avoid (if possible) having the touchX and touchY game attributes constrained to mouse position X,Y etc, as that's probably going to kill the framerate.
Thanks in advance!
You have to tap them to destroy them, simple stuff.
However, when I test it on the Nexus 7, they are actually really difficult to tap on. Not because they are too small, it;s just the tapping doesn't seem 100% accurate.
Is there a straightforward way of being able to tap within a certain distance of the blocks (magnitude?) and still having them destroy?
I can't cheat the actor size, for example make it 34 pixels and have transparent image edges, as the blocks all need to collide as they are flying.
I also want to avoid (if possible) having the touchX and touchY game attributes constrained to mouse position X,Y etc, as that's probably going to kill the framerate.
Thanks in advance!
Comments
I was going to do something similar with my last game as it was hard to hit the bouncing ball because of it's size and speed.
hmm, am I right thinking to get that to work I would need to define an area where the player can tap (with an invisible actor), add a boolean attribute to game for either tap or not tap, then for the invisible destroying actor have rule,
if tap=true
constrain attribute positionX to mouse position X
constrain attribute positionY to mouse position Y
or am I over complicating this?
Constrain Attribute: self.distanceToMouse To: magnitude (game.mousePosition.x - self.Position.X,game.mousePosition.Y - self.Position.Y)
When mouse is down
--(and) distanceToMouse < 100
----Destroy self
I don't follow you 100%, I can't find a self attribute distanceToMouse?
Am I misreading this?
EDIT, oh wait, am I being an idiot? I need to create the attribute myself... d'uh...
Thanks!
if actor touched
move (or constrain) invisible actor to mouse.x and mouse.y
otherwise
move (or constrain) invisible actor to -100, -100
But you're right you would probably need an extra invisible actor over the top that would detect presses with that rule on
Try @RThurman's one instead.
Although RThurman's method is nice and accurate, it looks like the distanceToMouse constraint is killing the FPS, the blocks become very jerky.
The invisible actor worked just by :
If Mouse Button down
Constrain to Mouse Pos X and Y
Else change attribute X and Y to -100
Unfortunately... (haha) I also have other, blue coloured blocks that you need to avoid tapping on, which so far so good, either method still works, BUT, if you tap on these blue blocks, they spawn more red blocks (which you are trying to get rid of) (it really isn't as complicated as I am making it sound )
But because the mouse is down and the invisible actor is in place, it's immediately destroying the newly spawned red blocks.
Hmmm, I guess I could put a timer on the spawned blocks that makes them unclickable for a fraction of a second... the plot thickens!!