Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Detect Sprite being clicked

    Beginners
    3
    5
    384
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      templer81 last edited by

      Hi ,I am trying to make my first game.
      It consists of a sprite that bounces along the screen.
      When it is clicked,it would move faster and would shrink.
      My question is
      how would I detect the clicking of the sprite (using the joy controller) ?

      Thanks in advance,
      Simon

      1 Reply Last reply Reply Quote 1
      • pianofire
        pianofire Fuze Team last edited by

        Well as always there are a number of ways you could do this. Probably the simplest is to have the joypad move a cursor around the screen. If you make the cursor also a sprite you can then use the sprite collision detection functions to work out whether it is over the sprite when clicked.

        1 Reply Last reply Reply Quote 4
        • T
          templer81 last edited by

          I implemented this using a circle (as shown in the tutorials).I wanted to ask :is there a way to get in which screen coordinates the joypad (right stick) is pointing ? I can only find whether the joystick is shifted to left or right or up or down ,but nothing on actual screen coordinates. Is again the solution to move a sprite or a circle and get the coordinates from there ? Thanks for the reply,Simon

          1 Reply Last reply Reply Quote 0
          • pianofire
            pianofire Fuze Team last edited by

            The joypad doesn't point at a screen coordinate it just registers user inputs. It is up to you how you interpret those inputs. So yes that is the solution

            1 Reply Last reply Reply Quote 0
            • Dave
              Dave Fuze Team last edited by Dave

              The joystick values only tell you where the joystick is being pushed relative to the centre. What you want is a separate set of variables for the cursor position - these will then be used to keep track of the the screen position of the cursor:

              // Create some variables to store cursor position - let's begin in the centre of the screen
              cursor_x = gwidth() / 2
              cursor_y = gheight() / 2
              
              // Main loop
              loop
                  clear()
                  c = controls(0)
              
                  // Apply the left stick values to the cursor position variables with a movement speed multiplier (change the * 2 for faster/slower movement)
                  cursor_x += c.lx * 2
                  cursor_y -= c.ly * 2
              
                  // Draw the circle at cursor positions
                  circle(cursor_x, cursor_y, 32, 32, white, false)
              
                  update()
              repeat
              

              To check collision with an area of the screen, we must use if statements to check the cursor_x and cursor_y values. For example:

              if cursor_x > 100 and cursor_x < 200 and cursor_y > 50 and cursor_y < 150 then
                  // We know that the cursor is in a particular screen region here
              endif
              

              To achieve this same thing with sprites would be a bit easier in terms of collision, but it would mean all of the objects that the cursor interacts with would also have to be sprites in order to use the collision functions like detectSpriteCollision() with them. It definitely takes some more set up, but it will be worth it for ease of use. The thing to remember however is that Sprites use Game World co-ordinates rather than screen co-ordinates.

              In Game World coords, (0, 0) is the centre of the screen, and the limits of the x and y axes on screen are determined by sprite camera position. Check out Help -> Command Reference -> Sprite System in FUZE for a detailed document about how sprites differ to normal drawing.

              1 Reply Last reply Reply Quote 3
              • First post
                Last post