This site requires JavaScript, please enable it in your browser!
Greenfoot back
AlmostUselessPenguin
AlmostUselessPenguin wrote ...

2019/12/17

Clicking on transparent parts of actors.

AlmostUselessPenguin AlmostUselessPenguin

2019/12/17

#
I'm creating a project which uses buttons for the majority of inputs (objects which run a method if Greenfoot.mouseClicked(this) is true). I made all the buttons and they are placed on a large grid (80px each). To position buttons offset them from the centre of a grid space I added transparent areas to the buttons to shift the visual button to one side (e.g. a 2x2 button placed in position 1,1 could have a transparent area of 1 grid square on the right and bottom to position it in the top 2x2 spaces). I have just discovered that the transparent areas still register as clicked which meant that two buttons next to each other, taking up the same space but one offset left and one offset right cancel each other out (one increments a value and the other decrements it). Testing it on another button showed the same effect. The buttons I already have can be fixed to not overlap each other however I am concerned this could cause issues in the future since my project may involve multiple clickable objects in a single grid space. Is it possible to do either of these things: -Only register clicks within the visible area of the object (all the buttons are rectangular but not a whole number of grid spaces in size) -Offset an object's image by a fraction of a grid space in an alternative way I understand this probably isn't solvable in a convinient way and the alternative is to just reposition buttons so they don't overlap and change situations with multiple buttons in a grid space to open a menu with all the options in there instead.
danpost danpost

2019/12/17

#
AlmostUselessPenguin wrote...
Is it possible to do either of these things: -Only register clicks within the visible area of the object (all the buttons are rectangular but not a whole number of grid spaces in size) -Offset an object's image by a fraction of a grid space in an alternative way
The first way is possible by having each button retain where its visible range is. Then checking the position of the mouse with respect to that range. The second way can only be done by reducing the grid size. Best would probably be to use a non-grid world and create the appearance of a grid with your coding.
You need to login to post a reply.