I built a custom calendar control with many navegability features, the only issue im facing now is the month jump on shift+scrollwheel.
mainb.setOnScroll(e->{
mainb.requestFocus();
System.out.println(e.getDeltaY());
if(e.isShiftDown()){
if(e.getDeltaY()>0)
prev.fire();
else
next.fire();
}else if(e.isControlDown()){
System.out.println(e.getDeltaY());
if(e.getDeltaY()>0)
prevDay();
else
nextDay();
}else{
if(e.getDeltaY()>0)
prevWeek();
else
nextWeek();
}
});
code + component + console results
if(e.isShiftDown()){
if(e.getDeltaY()>0)//always 0.0
prev.fire();//never fired
else
next.fire();//always fired
}
It seems as if the shift key is used to switch from
vertical to horizontal scrolling (see: bugs).
Therefore, e.getDeltaY() will return 0 when the shift key is pressed.
Use e.getDeltaX() in this case.
Related
I need help with GameMaker Studio 2 v2.3.2.556 project.
My clicking & dragging mechanism has two objects: an object called obj_iron that is being dragged, and an object called obj_cursor that is invisible and always follows the mouse. When I use the cursor to drag the iron, nothing happens. How do I make it so I can drag the iron using the cursor?
Code in obj_cursor in the Step Event
//Making the cursor move toward the mouse
global.picked_up_iron = 0
x = mouse_x
y = mouse_y
//Making the cursor small
image_xscale = 0.1
image_yscale = 0.1
//Checking if the cursor collided with obj_iron
if place_meeting(x,y,obj_iron)
{
//Checking if the mouse is held and the cursor is not collided with another obj_iron
if mouse_check_button(mb_left) and (global.picked_up_iron == 0 or global.picked_up_iron == other)
{
//Moving the dragged piece of obj_ironto the obj_cursor's location
var picked_up_iron = other
picked_up_iron.x = x - picked_up_iron.sprite_width / 2
picked_up_iron.y = y - picked_up_iron.sprite_height / 2
//Telling every the object what the dragged piece of obj_iron is
global.picked_up_iron = picked_up_iron
}
}
else if !mouse_check_button(mb_left)
{
//Resetting the value of the current piece of obj_iron
global.picked_up_iron = 0
}
If there are multiple of the same object in the same room, then place_meeting() does not know which kind of object is selected.
Maybe you can try out Instance_Place
var iron = instance_place(x, y, obj_iron);
This way, the iron returns the object the cursor is currently colliding with.
Okay so I am making one of those scrolling shooter Galaga-type game using Game Maker Studio. I created the first enemy and set up a spawner for them. They are supposed to just fly downwards towards your ship. That worked fine. But when I made the 2nd enemy, I wanted to make it move more slowly and side-to-side. I also wanted to make them bounce off the edges of the screen. But it just won't work. I can't figure what the hell the problem is and it it driving me insane. If anyone has any ideas, please, share them with me. If you need any more info on the game i can provide it. Here is the code for the step event of the 2nd enemy:
// Control the enemy
if (y > room_height+16)
{
instance_destroy();
}
// Die code
if (armor <= 0)
{
instance_create(x, y, o_explosion_center);
instance_destroy();
}
// Bounce off edges
if (x >= room_width-16)
{
hspeed = -1;
}
if (x < 16)
{
hspeed = 1;
}
First of all, you didn't say what wasn't working. The code you posted is correct, everything depends on the expected result.
One issue I can see id if this code is used by the two enemies. You want them to have different speeds, but once they bounce, their horizontal speeds will be 1 because you set hspeed to 1 and -1. When you create them, you should set a move_speed variable, and for the bouncing, write in the step event :
hspeed = -1*move_speed //instead of hspeed = -1
and
hspeed = move_speed //instead of hspeed = 1
This way, they will keep their initial speeds.
For more help, could you please explain what doesn't work and post the creation code ?
I am creating an application, where "Left Arrow + Down Arrow" press has different behavior ( It is not same as first left arrow and then left arrow ), currently in keyPressEvent event I am getting them one by one in two separate calls.
Is there any way by which I can get multiple keypress in one keyboard event?
Thanks for this. I am posting code for the Python (PyQt) equivalent so that someone else might find it useful.
def keyPressEvent(self, event):
self.firstrelease = True
astr = "pressed: " + str(event.key())
self.keylist.append(astr)
def keyReleaseEvent(self, event):
if self.firstrelease == True:
self.processmultikeys(self.keylist)
self.firstrelease = False
del self.keylist[-1]
def processmultikeys(self,keyspressed):
print keyspressed
I solved the problem by below code.
QSet<Qt::Key> keysPressed;
void Widget::keyPressEvent(QKeyEvent * event) {
m_bFirstRelease = true;
keysPressed+= event->key();
}
void Widget::keyReleaseEvent(QKeyEvent *) {
if(m_bFirstRelease) {
processMultiKeys(keysPressed);
}
m_bFirstRelease = false;
keysPressed-= event->key();
}
Nothing is "at the same time" and I believe in Qt you can't have that type of behaviour (except for modifier keys like shift, alt, etc).
Approach the problem in a different way. When you receive one of the keys, check to see if you received the other in a short while back, say 20ms before.
in Flex I have something like that:
var dg:DataGrid = new DataGrid();
if (something) dg = dg1 else if (something_2) dg = dg2;
dg.dataProvider.getItemAt(3).id;
and dg is ALWAYS pointing at DataGrid (even if dg1 has name DataGrid_test and dg2 = DataGrid_test2) and finally action is made on my first DataGrid (DataGrid_test).
Why?
How can I pass dg1 or dg2 to dg?
Here is pasted almost full code of this part of application. I edited it to make that more clear.
var dg:DataGrid = null;
if ( currentState == "state1" ) { //if this condition is true then app. go into if and
dg = dataGrid_first; // make dg = DataGrid (1)
test.text = "inco"; // shows "inco" in "test" label
} else if ( currentState == "state2" ) { // if this is true then app. go..
dg = dataGrid_second; //here and set dg as DataGrid (exactly!) (2)
test.text = "outgo"; // and change test label into blank text (earlier text disapears)
}
search(dg);
It is modified with advice of '#splash'
Still not working.
EDIT:
I made this sceond edit to answer for all You who are helping me with that :) I think that it will be the best way. In codeblock above I added comments. (please read now comments and after that come back here :) )
Now I will explain exactly what happens.
I debug it many times and here are results:
dg is pointing at DataGrid (as component in flex, not as my dataGrid_first), I needed to extend DataGrid so now it is ColorColumn component (I don't know if I called it properly), not DataGrid. And dg is pointing at ColorColumn not at dataGrid_first or dataGrid_second. I even tried today the same thing what suggest #splash:
if ( currentState == "state1" ) {
test.text = "inco";
search(dataGrid_first);
} else if ( currentState == "state2" ) {
test.text = "outgo";
search(dataGrid_second);
}
and search still points at ColorColumn :/ My problem is really easy- I just want to pass to search different dataGrid on each state. If You have other ideas how I can do that in right way then I will pleased to hear about it. :)
But still I don't understand why it doesn't work. My search function uses algorhitm Boyer-Moor for searching through dataGrid.dataProvider for some text. If it find something then it is pushed into new array and after passing whole dataProvider I colorize rows with searched word.
If dg is never pointing to dg1 and dg2 then your (something) expressions may be evaluate to false. Check the value of your if-conditions - this should be easy to debug.
This should work:
var dg:DataGrid = null;
if (something)
dg = dg1;
else if (something_2)
dg = dg2;
if (dg)
{
// do something with dg
}
[Update]
I still can't see why your code isn't working, but you could simplify it like this:
if ( currentState == "state1" ) {
test.text = "inco";
search(dataGrid_first);
} else if ( currentState == "state2" ) {
test.text = "outgo";
search(dataGrid_second);
}
I'd propose to write this - since I guess either dg1 or dg2 should be assigned:
if (something) {
dg = dg1;
} else {
dg = dg2;
}
There may be cases, where if () {} else () {} neither executes the first or the second conditional block.
Finally a small hint, which structurally eliminates unwanted assignments in if conditions: Always write the literal left of the comparison operation: if ( "state1" == currentState ). If you accidentally typed = instead of ==, the flex compiler emits an error. The other notation silently assigns a value.
Additionally: Did you single-stepped through your code and watched the variables dg1, dg2 and dg? If not, set a breakpoint a few line before the if-statement and run the code step by step from there on. What do you see?
Here's a another tip: Use assertions to check for inconistencies:
package my.company.utilities {
public function assert(expression:Boolean):void {
// probably conditionally compile this statement
if (!expression) {
throw new Error("Assertion failed!");
}
} // assert
}
Use it e.g. at the beginning of a method like this:
public function doTransaction( fromAccount:int, toAccount:int ) {
assert( 0 < fromAccount );
assert( 0 < toAccount );
}
A typically good use of assert is to check variables regarding their range. As of the above example, fromAccount and toAccount should always be positive. Due to a bug, bad values might get passed to doTransaction(). In this case, the assertion fires an error.
I am facing a strange problem with the combobox in Flex. In the following code :
public function rollCombo(cmb:ComboBox,value:String):void
{
if(value=='') return;
var i:int=0;
cmb.selectedIndex = 0;
var dp1:XMLListCollection = (XMLListCollection(cmb.dataProvider);
trace(value);
while(dp1[i]!=value && i<dp1.length)
cmb.selectedIndex = ++i;
cmb.validateNow();
cmb.validateDisplayList();
trace(cmb.selectedLabel);
}
in an example case, at the end of the execution of the function, i is 7, and
cmb.selectedLabel is "xyz"(according to the trace output), but the label displayed
in the combobox is a different one.
Also, this is rather unpredictable. It happens sometimes and not always.
The last selectedIndex is out of range, because you use pre-incrementation. Which means i becomes dp1.length before the test, and it's assigned to selectedIndex too. That might explain the weird behavior. You'll probably want to use post-incrementation.
Also. The only thing that gets executed in that while looks to be
cmb.selectedIndex = ++i;
I don't know if that's what you wanted, but you might need some "{}" there.