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

2015/2/2

Snap to

KiwiMC1482 KiwiMC1482

2015/2/2

#
Okay so I have this idea for the project I am currently doing for my school coursework where a music note can be dragged by the mouse onto the stave and if it's within a certain set of coordinates it will automatic snap to the wanted line, What I need help with is checking if the music note is within the set of coordinates and then setting it to the coordinates of the nearest line, which for right now there is only 1 line as I have taken this aspect out of my main project and working on it in a seperate project to get it right before implementing it into my main program.
danpost danpost

2015/2/2

#
I do not see how using just one line will help in creating the appropriate code for this. It does not give you any type of reference between the lines. It is the distance between each line that is important and you need at least two lines to produce that. The lines are horizontal and the distance between them is measured vertically; therefore, only the y-coordinate is important as far as finding the correct line. At the point of the mouse releasing the note, you should first determine the y-offset from the top line of the stave. Next, add one less than half the distance between the lines and divide by the distance between the lines. This gives you the index of the line to snap to (starting at zero). Multiplying this by the distance between the lines will give you the offset from the top line of the stave that the note is to snap to.
davmac davmac

2015/2/2

#
danpost wrote...
I do not see how using just one line will help in creating the appropriate code for this.
I can see how it would help. It is a classic example of "breaking a problem into smaller pieces" which is quite often a good way to go about a challenging task. In this case the problem is to snap an object to a line if it is within a certain range of co-ordinates.
KiwiMC1482 wrote...
... a music note can be dragged by the mouse onto the stave and if it's within a certain set of coordinates it will automatic snap to the wanted line, What I need help with is checking if the music note is within the set of coordinates and then setting it to the coordinates of the nearest line, ...
Can you be clear about your requirement here. Does each line have its own set of co-ordinates that determine when the note snaps to that line, or is there one set of co-ordinates for the stave, and any note dragged within those co-ordinates will snap to the nearest line? In any case, you can check co-ordinates of an actor using the getX() and getY() methods, and compare them to values using 'if' statements. This is quite basic stuff, are you unfamiliar with using those methods and/or if statements? Perhaps you should go through the tutorials and videos. At least have a go at writing some code, and post it. Then we can help you to get it working.
Ben&Sam Ben&Sam

2015/2/2

#
what if grenfoot was not moosecliked
danpost danpost

2015/2/2

#
Ben&Sam wrote...
what if grenfoot was not moosecliked
What kind of question is that?!! Do you have an issue with your mouse?? Then ... use keyboard commands.
Ben&Sam Ben&Sam

2015/2/2

#
it was a joke..
Ben&Sam Ben&Sam

2015/2/2

#
3sp0oky5me
Ben&Sam Ben&Sam

2015/2/2

#
DANPOST PLEASE FOLLOW ME I'M UR NO.1 FANGIRL #Grenfot == danpot class compeeled
danpost danpost

2015/2/2

#
Ben&Sam wrote...
it was a joke..
Please refrain from creating non-constructive posts. davmac might reply with something like this:
what if Ben&Sam was banned
You need to login to post a reply.