Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Possible to tap near an actor to destroy it?

sniffy176sniffy176 Posts: 48Member, PRO
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!


  • KevinCrossKevinCross London, UKPosts: 1,893Member
    edited August 2013
    If you don't want to do all of the bits you said could you not move an invisible actor to where you click and if it collides with your flying blocks they're destroyed. The invisible block could be any size but you'd probably want it the same size or bigger than your flying blocks. Does that make sense? One invisible actor that instantly jumps to your mouse x and y position and your flying blocks will have a rule on them to destroy if they collide with the invisible block. You will need to move the block out of the scene when you're not touching the screen

    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.
  • sniffy176sniffy176 Posts: 48Member, PRO
    edited August 2013
    Hey Kevin, That sounds like a very promising solution, I'll give that a try, thank you so much. :)

  • sniffy176sniffy176 Posts: 48Member, PRO
    edited August 2013

    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?
  • RThurmanRThurman Posts: 2,836Member, Sous Chef, PRO
    You could put a rule in each destroyable actor that would check for magnitude and destroy itself. It might look something like 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

  • sniffy176sniffy176 Posts: 48Member, PRO
    edited August 2013

    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...

  • KevinCrossKevinCross London, UKPosts: 1,893Member
    edited August 2013
    I would have thought it would have just been:

    if actor touched
    move (or constrain) invisible actor to mouse.x and mouse.y
    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.
  • RThurmanRThurman Posts: 2,836Member, Sous Chef, PRO
    Oh sorry. I should have mentioned that you will need to make a self attribute called "distanceToMouse" (or whatever you want to call it). It probably should be a "real" attribute.
  • sniffy176sniffy176 Posts: 48Member, PRO
    Thanks guys, both methods worked great!

    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 :D)

    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!!

Sign In or Register to comment.