SpriteKit is reporting contact where none exists. I set a breakpoint in didBeginContact and found this:
(lldb) po contact.bodyA <SKPhysicsBody> type:<Rectangle> representedObject:[<SKSpriteNode> name:'5' texture:[<SKTexture> 'Brick_3.png' (60 x 60)] position:{600, 120} size:{60, 60} rotation:0.00]
(lldb) po contact.bodyB <SKPhysicsBody> type:<Rectangle> representedObject:[<SKSpriteNode> name:'bullet' texture:['nil'] position:{568.67426, 86.000015} size:{15, 8} rotation:0.00]
(lldb) p bodyB.usesPreciseCollisionDetection (BOOL) $10 = YES
BodyA is not moving.
BodyB is running an action that moves it in the positive X direction. Its y value is not changing.
Can anybody tell why it would think these 2 bodies are in contact?
Related
Has anyone seen something like this before?
(lldb) po self.constraintsAffectingLayout(for: .horizontal)
▿ 5 elements
- 0 : <NSLayoutConstraint:0x60000243f2f0 H:|-(NSSpace(20))-[MyApp.MyCustomButton:0x7fe67e83b000'Some Label'] (active, names: '|':MyApp.MySuperView:0x7fe68d7073f0 )>
- 1 : <NSLayoutConstraint:0x60000243e1c0 H:[MyApp.MyCustomButton:0x7fe67e83b000'Some Other Label']-(NSSpace(20))-| (active, names: '|':MyApp.MySuperView:0x7fe68d7073f0 )>
- 2 : <NSAutoresizingMaskLayoutConstraint:0x6000024046e0 h=-&- v=-&- MyApp.MySuperView:0x7fe68d7073f0.minX == 0 (active, names: '|':NSThemeFrame:0x7fe68d735be0 )>
- 3 : <NSAutoresizingMaskLayoutConstraint:0x600002404730 h=-&- v=-&- H:[MyApp.MySuperView:0x7fe68d7073f0]-(0)-| (active, names: '|':NSThemeFrame:0x7fe68d735be0 )>
- 4 : <NSLayoutConstraint:0x600002426a80 'NSWindow-current-width' NSThemeFrame:0x7fe68d735be0.width == 465 priority:500 (active)>
(lldb) p self.frame
(NSRect) $R1 = (origin = (x = 19.5, y = 19.5), size = (width = 426, height = 81))
It appears that per the constraints, this should be 20 pixels from the edge of the screen, but instead it's 19.5. As you may expect, this is causing the button to draw all blurry on non-Retina displays.
Anyone seen anything like this before and/or know what sort of thing could cause something like this? Is there anything I should look for to debug this?
Turned out that the custom class I was using was fine, but the custom class that was its superclass contained an override of alignmentRectInsets which was causing the issue. Leaving this here in case someone else runs into the same issue. Apologies for the noise.
There is a script that for some reason does not work.
I explain the situation: There is a mini game in which there are green rings and they change their position (not random) every time the white ring stops using the space bar on them.
I wrote a little script to find the green color, but for some reason it does not work.
F5::
loop {
PixelGetColor, color1, 957, 672, RGB
PixelGetColor, color2, 957, 672, RGB
if(color1 != 0x10A04B){
Sleep, 80
} else {
Soundbeep
Sleep, 80
}
if(color2 != 0xFDFFFE){
Sleep, 80
} else {
Send, {space}
}
}
return
To help you fully understand the mini game, I'm sending you a link to the video: https://youtu.be/b4y1aiQNea4
Please help me understand the implementation. Thank you!
Use a timer instead of the loop
Try using Alt or Slow mode
For finding the green ring coordinates try using PixelSearch, then you will be able to specify variation of the color (it's necessary due to it being partially transparent)
colorchange(x,y){
PixelGetColor,color,x,y
if (color=0xffffffffff){
Return 1}Else{
Return 0}
}
if colorchange(X,Y){
Send,{Space}
}
I cooked up a script that lets me map my keyboard's media shortcuts to my mouse LRM buttons when they are pressed while the mouse coordinate is leftmost or rightmost of the screen. While it does work, I'm having having strange side effects:
When I have caps lock on, ever few strokes the letter comes out lowercase.
When I use shift to type capital letters for an extended period of time, this will turn on caps lock
Using the keyboard history, I see that my script is constantly sending the "Alt Up" key, I did this so that it release the "Alt Down" state, but something is off.
My goal is to send an modifier key when a mouse is over a certain coordinate, so that when I click with that mouse button, it launches another ahk-programmed shortcut. But can't figure out where the logic error is in my code or thinking process.
Here's the script:
; ------------------------
; Global Initializers
#InstallKeybdHook
#MaxThreadsPerHotkey 1
; ---------------------
; Control Spotify; position your mouse top-most edge and use L/M/R-mouse keys.
SetTimer, WatchCursorx, 1000
return
WatchCursorx:
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
;Based on location of the mouse simulate shortcut activation
If (xpos == 2559 || xpos == 0)
{
Send {Alt Down}
}
Else
{
Send {Alt Up}
}
return
;Define shortcuts mentioned above
!RButton::
Send {Media_Next}
return
!LButton::
Send {Media_Prev}
return
!MButton::
send {Media_Play_Pause}
return
#If(docs) is meant for this.
You could use it for example like this:
CoordMode, Mouse, Screen
#If, MouseOnTheRight()
LButton::SendInput, {Media_Prev}
RButton::SendInput, {Media_Next}
MButton::SendInput, {Media_Play_Pause}
#If
MouseOnTheRight()
{
MouseGetPos, x
return x == A_ScreenWidth - 1
}
Per my comments, try it like this:
CoordMode, Mouse, Screen
~RButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
{
Send {Media_Next}
sleep, 500
Send {esc} ' this gets rid of right context menu
}
return
~LButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
Send {Media_Prev}
return
~MButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
Send {Media_Play_Pause}
return
Note, the preceding ~ lets the original mouse click go through so ordinarily the context menu will come up on right click. I add a Sleep and Send Escape key to dismiss . . . Ymmv
I am looking for a script that will click and hold the right mouse button down and drag in a given direction 1 pixel every "x" or 2 seconds. Something I can either tell to move in given direction by hitting the corresponding direction key or by adjusting the script manually.
Thank you!
Not entirely sure what you want, but try this:
CoordMode, Pixel, Screen
direction = left
secondsBetweenMoves = 0.1
F1:: ;F1 to start it
SendInput, {LButton Down}
SetTimer, Move, %secondsBetweenMoves%
Return
F2:: ;F2 to end it
SendInput, {LButton Up}
SetTimer, Move, Off
Return
Move:
MouseGetPos, mouseX, mouseY
If (direction = "left") {
MouseMove, mouseX-1, mouseY
}
Else If (direction = "right") {
MouseMove, mouseX+1, mouseY
}
Else If (direction = "up") {
MouseMove, mouseX, mouseY-1
}
Else If (direction = "down") {
MouseMove, mouseX, mouseY+1
}
Return
The send event command might make your life a whole lot easier. For example, what you're trying to do in a simplistic infinite loop:
coordmode, mouse, screen
setmousedelay, 0 # This makes the mouse move extremely fast
loop {
mousegetpos, mx, my
mx := mx+1
sendevent {click, r, down}
sendevent {click, %mx%, %my%, r, up}
sleep 2000
}
This loop will hold down the right button and move one pixel to the right every two seconds. If you want it to move to the left, change
mx := mx+1
to
mx := mx-1
Making it move up or down is the same mechanism, but adding or subtracting to the variable "my" instead.
This loop can be made into a timer, with hotkeys to enable or disable it.
I am trying to make a maze in Qbasic but when the pointer touches the maze lines then the program is not ending. I want that when the circle (which is the pointer ) touches the ends of the maze then the program should go to an end.The Program is this:-
cls
screen 12
DIM p AS STRING
DIM A1 AS STRING
15 print"What do you want to do?"
print"A:Draw AN IMAGE"," B:PLAY A MAZE GAME";
PRINT
PRINT"TYPE 'A' OR 'B'IN CAPITAL FORM"
GOTO 102
99 print "rules to play the maze game:"
print
print "1 use 'W' to move the ball foward"
print "2 use 'S' to move the ball backward"
print "3 use 'A' to move the ball leftward"
print "4 use 'D' to move the ball rightward"
INPUT A1
CLS
goto 10
102 INPUT P
if p="A"then
cls
goto 20
elseif p="B" then
cls
goto 99
elseif p<>"A" AND p<>"B" then
print "Choose between A and B"
GOTO 70
end if
10 pset(120,120)
draw "r100"
pset (120,140)
draw"r80"
pset (200,140)
draw "d100"
pset (220,120)
draw"d140"
pset (220,260)
draw "l90"
pset (200,240)
draw "l50"
pset (130,260)
draw"u50l120u90r60u40l50u60r300d90l35d260l60d30l80
h20l20h20u30r40u5l70d60f40r250u90h40u45r40u40r50u130h40r225d65l50d60l15
d130l40d50l20d15r45d40r20u45r10u10r10u90r100"
pset(150,240)
draw"u50l120u50r60u80l50u20r260d50l35d260l60d30l40h20l20h10r
40u50l120d98f50r290u115h40u20r40u40r50u160h10r140d20l50d60l15
d130h40d90l20d60r45d45r70u45r10u10r10u90r75"
20 dim k as string
x = 110
y = 105
do
k = ucase$(inkey$)
if k="W"then
y = y - 2
elseif k= "S" then
y = y + 8
elseif k="A"then
x = x - 8
elseif k="D" then
x = x + 5
end if
circle (x,y),7,10
loop until k ="Q"
GOTO 45
70 CLS
GOTO 15
if x=120 and y=120 then goto 45
40 cls
45 END
Pls Help
Thanks in Advance....
Ok, let's take a peak at your game loop presented below and reformated a bit for readability:
do
k = ucase$(inkey$)
if k="W"then
y = y - 2
elseif k= "S" then
y = y + 8
elseif k="A"then
x = x - 8
elseif k="D" then
x = x + 5
end if
circle (x,y),7,10
loop until k ="Q"
Your win case (if x=120 and y=120 then goto 45) doesn't actually occur within the loop but outside it.
With do loops, only the code between the do and loop statement will execute unless the "until" statement returns true. In order words:
do
'This code will execute
loop until k = "Q"
'This code will only execute after k=Q
Put the win case in the do loop and it should work.
If I recall correctly, QBasic allows whitespace in the beginning of a line. I recommend using whitespace to organize your code visually so you can see what's going on. Look at how I formatted your main loop. Everything that the do loop controls is tabbed to the right of the do and loop statement. This way you can easily see what the do loop is doing. Everything in the if statement gets the same treatment for similar reasons.
If you get in the habit of indenting your code, you can start to see the code's logic laid out cleanly.
Edit: It seems you're new to programming. If you enjoy it, I recommend learning Python through codecademy rather than QBasic. QBasic encourages some very bad habits, like goto statements.