How would I be able to use my mouse to shoot - game-maker

So far I've created an object called obj_mouse. And my plan is whenever the player left clicks, it spawns a bullet from him toward where ever the mouse is pointing. I've got the concept down, but I'm struggling getting it to work.
Extra bits of code I'm messing around with to try to get it to work:
bullet=instance_create(x,y,obj_bullet)
with (bullet) {
move_towards_point(mouse_x,mouse_y,5)
image_angle=direction
}
point_direction(obj_mouse,obj_mouse,obj_mouse,obj_mouse)
image_angle=direction
(In the above code, I have not attempted to specify to the program that I want the bullet to go in the direction of obj_mouse, or rather, just the mouse. The above code works, and bullets do shoot, however the player must have the mouse on the players sprite for it to work.)
Thank you in advance for any advice given.

The fix was applying the piece of code to a global mouse click event, so that it does not call the code from the object being left clicked rather it calls the code when left click is clicked.

Related

How to pause game running in background during asynchronous event?

I am creating a game in GMS2. I am using "show_message_async()" in my code. I know that when it is run, a message pops up on the screen and the game still runs in the background. However, I want the game to freeze in the background while the message pops up. Is it possible to do this? And if so how.
You should try looking up instance_deactivate_all(notme) and instance_activatie_all(notme)
https://docs.yoyogames.com/source/dadiospice/002_reference/objects%20and%20instances/instances/deactivating%20instances/index.html
This will disable all objects in a room except the object that's calling it (which should be the menu object that shows the message)
The only tricky part of it, it that it also disables drawing the objects. resulting in an empty screen. For this, you could either use a black screen, or draw a screenshot of the scene before they're disabled.
I agree with Steven's answer. To add on his answer about taking the screenshot of the game, you probably need to make a new surface, then use surface_copy from application_surface before deactivating the object.

How to receive hover events on QGraphicsItems during drop?

I use two different QGraphicView's and do drag'n'drop between them. The dragdrop does work very well so far. In one of my QGraphicView's I have items that receive hover events so that they are lighted when the mouse moves on them. The problem is that during drops and also during moves on items, the hover events won't get called. Is it possible to overcome this behaviour somehow? The hover events mark the places the drop can occur in my view and the items then have to be dropped at the right places accordingly (they can only be inserted at specific places and the user should get some feedback).
I hope I could describe my problem...I posted no code for now, because I do not know if this is even possible.
Thanks!
I'm not too familiar with the graphics view framework yet, but you'll probably need to subclass QGraphicsView (if you haven't already) and override QWidget::DragEnterEvent. Depending on how you coded your objects, they might also have a DragEnterEvent that you can use.
In either case you'd accept the QDragEnterEvent and have it trigger the hover event. Hope that points you in the right direction.

Panning QScrollArea with a mouse

I have a QScrollArea. I would like to make the context pannable with a mouse - such that, a hand cursor is shown over the area and click-and-hold gets us into dragging mode.
This would be similar to what QGraphicsView can do easily with QGraphicsView::ScrollHandDrag dragging mode, only that I need it for QScrollArea.
Any idea on how to have it out of the box? Or perhaps a piece of code to do it manually? I am certainly not the first one who wants it..
Should not be difficult, especially using event filter. Take a look at my old blog post on Flick list or kinetic scrolling (the code has been moved to http://qt.gitorious.org/qt-labs/graphics-dojo). As a bonus, you can get the momentum effect easily!
Okay. At the end I changed it to QGraphicsView and it was easy to do, worked great out of the box.

Flex detect when mouse leaves a Canvas

I am trying to detect when the mouse leaves a canvas. I know about the MOUSE_LEAVE, but this seems to only be valid for the stage, not Canvas objects.
take care,
lee
P.S. I have tried the mous-out, but, for some reason, that event keeps getting triggered everytime I move the mouse.
I should probably point out that I have used the Mouse.hide() and replaced the cursor with a custom cursor.
You could use either the MouseEvent.ROLL_OUT event or MouseEvent.MOUSE_OUT.
To see what is the difference and what you should use, read this article.
Try to use mouseOut event.
Thanks everyone. The trick was to set the custom cursor's parent to mouseChildren = false. Not a practical solution for most situations, but good for this.
The problem was coming from the fact that the mouse is still on the stage and moves slightly faster than the code move the custom mouse. So if the mouse was moved too quickly, it actually moved off the custom cursor.
take care,
lee

Qt - In QGraphicsScene how to put a picture dynamically

Hai,
I am trying to create a chess board. Here I want to do a operation like when ever a coin is clicked and dragged, at that time that picture should be copied and be placed in that old position. I don't know in which function I have to do it. When I made it on mouse pressed, then tyhe copy is coming above the original(layer wise). So somebody please help me
When I made it on mouse pressed, then tyhe copy is coming above the original(layer wise).
When you got this far, simply adding a call to myItemCopy->setZValue( -1 ) would place the copy "behind" the original item.
A different approach, and possibly "cleaner", would be to use QDrag and tell Qt how to paint your item during the Drag operation. See Qt's "Drag and Drop Robot" example for reference: http://doc.qt.io/qt-5/qtwidgets-graphicsview-dragdroprobot-example.html
Happy coding!
Robin
Simplest way to do this will be to put 2 identical QGraphicsItems for each coin/piece at the same location. The top one will be dragged and moved while the bottom one will stay for the visual cue you want.
Once the top one is dropped to the new location, move the bottom one there too.

Resources