Point on object clicked

0 favourites
  • 5 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Hey guys :) Im new here and this is my first post :P

    Ok so im moving away from game maker 8.1 and trying construct 2 for a change and so far im loving the simplicity of it :)

    So im currently testing functions and events in construct, however i need help with this.

    Lets say i have a ball, and the ball's width is 50 pixels across. Now how can i find exactly where i clicked on this ball and save the x (which would be from 1 - 50) to a global varibale? So if lets say i clicked close to the middle it would record the x as being close to 25? and further to the left of the ball would be from 1-25.

    Sorry if its confusing but for the game i am thinking about creating i need to implement this.

    Thanks in advance!! :)

    Chris

  • You can calculate it with the difference between the Mouse and Sprite locations.

    +On clicked on Sprite

    -set x_on_sprite to Mouse.X-Sprite.X

    -set y_on_sprite to Mouse.Y-Sprite.Y

    This is dependent on the Sprite's hotspot. If the hotspot is centered then x_on_sprite and y_on_sprite will be -25 to 25, but if the hotspot is top_left then they will be from 0 to 50.

  • You can calculate it with the difference between the Mouse and Sprite locations.

    +On clicked on Sprite

    -set x_on_sprite to Mouse.X-Sprite.X

    -set y_on_sprite to Mouse.Y-Sprite.Y

    This is dependent on the Sprite's hotspot. If the hotspot is centered then x_on_sprite and y_on_sprite will be -25 to 25, but if the hotspot is top_left then they will be from 0 to 50.

    Thanks, i see where your coming from, however the ball will be constantly moving around the screen and not in a static position.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • See for example this kickups game. IT determines where you clicked on the ball and send it shooting in a specific direction depending on where you clicked.

    spikything.com/games/kickups

  • It will work on a moving object.

    Mouse.X-Sprite.X gives you the x position relative to the Sprite, same for the y.

    With the hotspot of the sprite set to "top left" you will get values between 0-50 for x and y.

    If all you want is the direction from the mouse to the center of the Sprite then you can use the angle() expression to get the angle:

    angle(Mouse.X, Mouse.Y, Sprite.X, Sprite.Y)

    With the physics behavior the angle expression isn't even needed as you can apply impulse toward a position.

    http://dl.dropbox.com/u/5426011/examples%208/kick.capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)