プレイ日記
Kenny klyons04
Can someone tell how to select things with a moving cursor I made?
1そうだね
プレイ済み
返信[1]
親投稿
*J.P.* DEV NEWPICY3
*ive never done this but im assuming you can do like*, if y=100 (lets say 100) and X=100 and button pressed() #a then (whatever you want it to do) this is just my assumption so i might be totally wrong, or use sprite collision, if the mouse sprite is touching whatever button sprite and button is pressed then do whatever.
1そうだね
未プレイ
返信[2]
親投稿
MathPRG MathProgrammer
Yeah, if it only would allow you to use one coordinate it would be very difficult to press a button. If your buttons are sprites, then you should use TOUCH OUT TT, TX, TY to get the X and Y coordinates of the cursor, and TT will store how long it's been held. Make sure this is in a loop.
1そうだね
プレイ済み
返信[3]
親投稿
MathPRG MathProgrammer
Then use SPCOL X, Y, W, H, 1 - X and Y are the offset for the top left corner of the collision box, and W and H are the width and height of it. The 1 at the end enables scale adjustment. Ideally you'll want to replace X and Y with half the width of the sprite in X, and half the height for Y, however they both should be NEGATIVE values.
1そうだね
プレイ済み
返信[4]
親投稿
MathPRG MathProgrammer
Then set W and H to the width and height of the sprite, don't change these values. This will be centered around the sprite as long as you call SPHOME CN, W, H as well. For W and H here you should put half the width and height of the sprite. I forgot CN in the previous commands, that's the sprite control number so don't forget it!
1そうだね
プレイ済み
返信[5]
親投稿
MathPRG MathProgrammer
Not done yet! Next you'll need to use SPHITSP(Cursor CN, F, L) within your loop, to where F and L are the first and last control numbers of the sprites you are using as buttons. HITC=SPHITSP(control numbers from before) will assign the control number of whatever sprite the cursor hits to HITC.
1そうだね
プレイ済み
返信[6]
親投稿
MathPRG MathProgrammer
Lastly, if you want the buttons to activate only if they are tapped IMMEDIATELY (so you can't tap, then slide the stylus over them to activate) you'll use the value stored in TT - the touch time gained from TOUCH OUT. IF TT<2 AND HITC>-1 THEN should do the trick.
1そうだね
プレイ済み
返信[7]
親投稿
MathPRG MathProgrammer
Sample of a code that would work, if I overcomplicated it: @LOOP TOUCH OUT TT, TX, TY HITC=SPHITSP(0, 1, 5) IF TT<2 AND HITC>-1 THEN ON HITC-1 GOTO @Label for first button, label for second, etc. ENDIF (insert any other code you want in the loop here) VSYNC 1:GOTO @LOOP Replace the 1 and 5 in SPHITSP with the control numbers of your first and last button sprites.
1そうだね
プレイ済み
返信[8]
親投稿
MathPRG MathProgrammer
Also make sure that you replace the 1 in ON HITC-1 with the control number of the first button sprite (if that's 5, put ON HITC-5 for example). Button and cursor definition: SPSET CN,U,V,W,H:SPHOME CN,W/2,H/2 SPCOL CN,-(W/2),-(H/2),W,H
1そうだね
プレイ済み
返信[9]
親投稿
MathPRG MathProgrammer
Sorry, I've posted a lot just here, but I forgot that to make the cursor move to the touch coordinates, you can just put SPOFS cursor CN, TX, TY somewhere in the loop.
1そうだね
プレイ済み
返信[10]
親投稿
Kenny klyons04
Thanks for all that! But what do you mean by "button sprites"?
0そうだね
プレイ済み
返信[11]
親投稿
MathPRG MathProgrammer
Well, it all depends on what you are using the cursor for. What I mean is, if you want to have it interact with a button that would activate once pressed and released, for example a 'confirm' button that may say OK and is supposed to close a menu when pressed, you could use a sprite that you create that appears to be said button, which makes the whole collision process a ton easier.
1そうだね
プレイ済み
返信[12]
親投稿
MathPRG MathProgrammer
It's much more simple to use collision once you've figured it out - without them, all you could really do is use a whole ton of IF statements that test whether the cursor is in a particular range. With sprites, you can even make the button move and it will bring the collision range with it, meaning you could have the cursor interact with a moving button.
1そうだね
プレイ済み
返信[13]
親投稿
MathPRG MathProgrammer
It basically works the same way sprites in a game would - in my game, POLYGON, the player is normally controlled with the stylus, and follows where the touch screen is being touched. Then it checks for collision with your enemies throughout the main game loop.
1そうだね
プレイ済み