[Beginner Question] Sticking a rectangle to my mouse?
in
Programming Questions
•
4 months ago
Hello everybody. First of all, i am from Austria, so please excuse any mistakes i might make.
Well, last week i applied to an university, and now i got an Email with a little "home-work" to do. I guess they will look over it and if they like my game that would help me a lot for sure.
Well, we should make a game where you have to collecte 10 Rectangles, and once you've collected all the rectangles, you should get a "you win!"-Message.
Well, i don't think that this is gonna get that hard, but to make my game "shine over the others" i dont just want boring rectangles, i want cow's which you can collect with an UFO. But I'm stuck with the UFO-Part. How do i fix the ufo to my mouse?
I tryed to set rectangle mode to center, and created a 40x40 (thats the size of the ufo.png) rectangle. Then i tryed to set the position-data to mouseX and mouseY, like this:
rectMode(CENTER);
rect(mouseX, mouseY, 40, 40);
I put all of that into the void draw()-function, but now it creates 60 rectangles per second, and i think thats not how its intended to work best?
It would be better to create the rectangle first and just update the position with the draw-function, but i have no clue how to do that. Can you guys help me?
And i got another question: When i try to put the background-image intro the draw-function, it overwrites every "Cow-Square"(the orange ones). But when i put it into the setup-function, then i get thousands of the mouse-squares. Where is my mistake?
I hope you can help me and excuse me if this were dumb questions, you would help me alot! Thank you in adavance!
Greeting from austria
Here is my Code:
Well, last week i applied to an university, and now i got an Email with a little "home-work" to do. I guess they will look over it and if they like my game that would help me a lot for sure.
Well, we should make a game where you have to collecte 10 Rectangles, and once you've collected all the rectangles, you should get a "you win!"-Message.
Well, i don't think that this is gonna get that hard, but to make my game "shine over the others" i dont just want boring rectangles, i want cow's which you can collect with an UFO. But I'm stuck with the UFO-Part. How do i fix the ufo to my mouse?
I tryed to set rectangle mode to center, and created a 40x40 (thats the size of the ufo.png) rectangle. Then i tryed to set the position-data to mouseX and mouseY, like this:
rectMode(CENTER);
rect(mouseX, mouseY, 40, 40);
I put all of that into the void draw()-function, but now it creates 60 rectangles per second, and i think thats not how its intended to work best?
It would be better to create the rectangle first and just update the position with the draw-function, but i have no clue how to do that. Can you guys help me?
And i got another question: When i try to put the background-image intro the draw-function, it overwrites every "Cow-Square"(the orange ones). But when i put it into the setup-function, then i get thousands of the mouse-squares. Where is my mistake?
I hope you can help me and excuse me if this were dumb questions, you would help me alot! Thank you in adavance!
Greeting from austria
Here is my Code:
- PImage bg;
//Set kords for the cow-rectangles:
int [] xkord={176, 114, 298, 402, 385, 245, 462, 382, 503, 544};
int [] ykord={424, 180, 308, 288, 410, 72, 122, 169, 200, 267};
void setup() {
size(684, 600);
//load background-image
bg = loadImage("asdfg.jpg");
background(bg);
//load the cow-rectangles(so far just orange rectangles)
fill(255, 95, 17);
for(int i=0; i<10; i++){
rect(xkord[i], ykord[i], 41, 39);
}
}
void draw() {
// start Ufo-rectangle(so far just a green rect.)
fill(0, 255, 0);
rectMode(CENTER);
rect(mouseX, mouseY, 40, 40);
}
1