cgpoint

Overlapping Circular Buttons and Hit/Tap Testing

陌路散爱 提交于 2019-12-10 11:17:18
问题 I am trying to create a Tabla drum app (a Table is a pair of small hand drums attached together). To do this I want to use a button for each section of the drum by putting one on top of another. Like so: I've tried using a circular image for the button but the surrounding area are a rectangle. That means when the user would hit parts of the green circle it plays the sound for the orange circle (I hope that makes sense). How can I ensure the sound for the green pad is played when the user taps

Finding coordinates of gesture touch using locationOfTouch

你。 提交于 2019-12-10 10:25:00
问题 Hey, been trying to get the location of a users swipe so that I can have 3 swipe-able areas on screen and determine which section they react with based on the y coordinates of their swipe. This is the code CGPoint touchPoint = [recognizer locationOfTouch:0 inView:nil]; I have tried printing the touchPoint.y in a label and all i get is 0. How do I get the coordinates of the users swipe? Thanks. 回答1: Its strange but setting view as nil or self.view.window is returning 0. There is no mention of

Cocos2D: Passing a CGPoint through CCCallFuncND

僤鯓⒐⒋嵵緔 提交于 2019-12-08 11:43:02
问题 What is the appropriate way to call a method with an action, and what should the method itself look like for passing a CGPoint parameter? I've tried to look up examples online without much luck, so I've been pretty much guessing. What I have tried is this for calling it: CGPoint spriteCoord = saveStation.sprite.position; id a1=[CCMoveTo actionWithDuration:.4 position:ccp(saveStation.sprite.position.x,saveStation.sprite.position.y)]; id actionSaveStationReaction = [CCCallFuncND

If with CGPointEqualToPoint do not work

淺唱寂寞╮ 提交于 2019-12-07 11:54:03
问题 Im trying to figure out why this function do not execute theGameEnd function, when ball position is exactly the same as block position and when anchorpoints are the same. if (CGPointEqualToPoint(ball.position,block.position)) { if (CGPointEqualToPoint(ball.anchorPoint,monster1.anchorPoint)) { [self theGameEnd]; } } 回答1: The implementation of CGPointEqualToPoint is CG_INLINE bool __CGPointEqualToPoint(CGPoint point1, CGPoint point2) { return point1.x == point2.x && point1.y == point2.y; } ...

CGPointMake in Swift

假装没事ソ 提交于 2019-12-06 16:36:44
问题 How to use CGPointMake in Swift ? Is there an equivalent for it? I am getting an error: Use of unresolved identifier 'CGPointMake' Basically, I am trying to assign a position to a Sprite Kit node and cannot figure out how to do it in Swift. class PlayerSpaceship: Spaceship { func launchMissile() { var missile = Missile.playerMissile() // This line gives above mentioned error. missile.position = CGPointMake(0.0, 0.0) } } 回答1: Use CGPoint(x: Float, y: Float) 回答2: You call it a little

Distance between two rectangles

杀马特。学长 韩版系。学妹 提交于 2019-12-06 13:13:40
How can I find the distance between two rectangles? Intersects should return 0 in distance. Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin.x == mostRight.origin.x ? 0 : mostRight.origin.x - (mostLeft.origin.x + mostLeft.size.width); xDifference =

Overlapping Circular Buttons and Hit/Tap Testing

回眸只為那壹抹淺笑 提交于 2019-12-06 11:59:39
I am trying to create a Tabla drum app (a Table is a pair of small hand drums attached together). To do this I want to use a button for each section of the drum by putting one on top of another. Like so: I've tried using a circular image for the button but the surrounding area are a rectangle. That means when the user would hit parts of the green circle it plays the sound for the orange circle (I hope that makes sense). How can I ensure the sound for the green pad is played when the user taps in the green pad, and the sound for the orange pad is played when the user taps the orange pad? There

Get Color of point in a SKScene swift

你离开我真会死。 提交于 2019-12-06 07:27:51
问题 I need to get the color of a pixel/point for my game in Swift. So I tried to find a function that inputs a CGPoint and returns a Color, everything that I have found so far has only returned (0,0,0,0). I think that this is because I am doing this in my game scene class(which is an SKScene), and the scene is only being loaded by a view controller. Any Solutions? (If there is a better way to check if a sprite is touching a color that would work as well) Thanks in advance. 回答1: Add the below

CGPath adding a curve between points

只谈情不闲聊 提交于 2019-12-06 04:34:27
问题 So I have a function which randomly generates some CGPoints I then create a CGPath from these points. I use this path in a keyframe animation to animate a view around the screen. The path is generated using the code below: - (CGMutablePathRef)generatePathFromCoordinates:(NSArray *)coordinates { CGMutablePathRef path = CGPathCreateMutable(); CGPoint point = [(NSValue *)[coordinates objectAtIndex:0] CGPointValue]; CGPathMoveToPoint(path, nil, point.x, point.y); for (int i=1; i < coordinates

If with CGPointEqualToPoint do not work

≡放荡痞女 提交于 2019-12-06 03:57:16
Im trying to figure out why this function do not execute theGameEnd function, when ball position is exactly the same as block position and when anchorpoints are the same. if (CGPointEqualToPoint(ball.position,block.position)) { if (CGPointEqualToPoint(ball.anchorPoint,monster1.anchorPoint)) { [self theGameEnd]; } } The implementation of CGPointEqualToPoint is CG_INLINE bool __CGPointEqualToPoint(CGPoint point1, CGPoint point2) { return point1.x == point2.x && point1.y == point2.y; } ... so coordinates have to be absolutely equal to return true. This is not always the case with CGFloat types,