[SOLVED] Weird behavior in my collision detection


(meganmorgangames) #1

So. A little bit of weirdness, which has to be something that I’ve done horribly wrong. I have created a combobox for a game that I’m working on, and the section of code that is giving me trouble is pasted below. Basically, if you are hovering over the combobox it changes the graphic, and changes it back if you are not hovering over the box. It works fine in some of my instances, but not in others. In the instances that it is not working it flickers between HOVER and CLOSED.

I put a trace into the code, and it is returning that collidepoint(x,y,world.mouseX,world.mouseY) is true, which means it shouldn’t be running anything in that block. Nothing in the class is static. I’m really at my whit’s end here. Has anyone ever run into a similar problem? I can put the whole class on my GitHub if necessary.

[Edit] Hasn’t helped me solve the problem, but it seems that this only happens with comboboxes that are on the same row, and the state doesn’t change from HOVER if I move away from the entity on the X-Axis, only on the Y-Axis. The first box on each row is the one that behaves properly.

[Fixed] Not really sure why it worked, but when I made the collidePoint check first and then checked the state after it fixed the problem.

	super.update();
	if (_state != DISABLED) {
		if (_state == CLOSED) {
			if (collidePoint(x, y, world.mouseX, world.mouseY)) {
				changeState(HOVER);
			}
		} else if (_state == HOVER) {
			if (!collidePoint(x, y, world.mouseY, world.mouseY)) {
				trace("Making Closed", x, y, world.mouseX, world.mouseY, collidePoint(x,y,world.mouseX, world.mouseY));
				changeState(CLOSED);
				_clicked = false;
			}
			else {
				if (Input.mousePressed) _clicked = true;
				if (Input.mouseReleased && _clicked) {
					_clicked = false;
					changeState(OPEN);
				}
			}
		}

(HeraldR) #2

You had a typo in your second collidePoint check. You put world.mouseY where you should have put world.mouseX. I’ve done that a lot so I check for it now.


(Ultima2876) #3

This topic was automatically closed after 2 days. New replies are no longer allowed.