Search Results

Search found 11 results on 1 pages for 'jbrennan'.

Page 1/1 | 1 

  • Getting 2D Platformer entity collision Response Correct (side-to-side + jumping/landing on heads)

    - by jbrennan
    I've been working on a 2D (tile based) 2D platformer for iOS and I've got basic entity collision detection working, but there's just something not right about it and I can't quite figure out how to solve it. There are 2 forms of collision between player entities as I can tell, either the two players (human controlled) are hitting each other side-to-side (i. e. pushing against one another), or one player has jumped on the head of the other player (naturally, if I wanted to expand this to player vs enemy, the effects would be different, but the types of collisions would be identical, just the reaction should be a little different). In my code I believe I've got the side-to-side code working: If two entities press against one another, then they are both moved back on either side of the intersection rectangle so that they are just pushing on each other. I also have the "landed on the other player's head" part working. The real problem is, if the two players are currently pushing up against each other, and one player jumps, then at one point as they're jumping, the height-difference threshold that counts as a "land on head" is passed and then it registers as a jump. As a life-long player of 2D Mario Bros style games, this feels incorrect to me, but I can't quite figure out how to solve it. My code: (it's really Objective-C but I've put it in pseudo C-style code just to be simpler for non ObjC readers) void checkCollisions() { // For each entity in the scene, compare it with all other entities (but not with one it's already compared against) for (int i = 0; i < _allGameObjects.count(); i++) { // GameObject is an Entity GEGameObject *firstGameObject = _allGameObjects.objectAtIndex(i); // Don't check against yourself or any previous entity for (int j = i+1; j < _allGameObjects.count(); j++) { GEGameObject *secondGameObject = _allGameObjects.objectAtIndex(j); // Get the collision bounds for both entities, then see if they intersect // CGRect is a C-struct with an origin Point (x, y) and a Size (w, h) CGRect firstRect = firstGameObject.collisionBounds(); CGRect secondRect = secondGameObject.collisionBounds(); // Collision of any sort if (CGRectIntersectsRect(firstRect, secondRect)) { //////////////////////////////// // // // Check for jumping first (???) // // //////////////////////////////// if (firstRect.origin.y > (secondRect.origin.y + (secondRect.size.height * 0.7))) { // the top entity could be pretty far down/in to the bottom entity.... firstGameObject.didLandOnEntity(secondGameObject); } else if (secondRect.origin.y > (firstRect.origin.y + (firstRect.size.height * 0.7))) { // second entity was actually on top.... secondGameObject.didLandOnEntity.(firstGameObject); } else if (firstRect.origin.x > secondRect.origin.x && firstRect.origin.x < (secondRect.origin.x + secondRect.size.width)) { // Hit from the RIGHT CGRect intersection = CGRectIntersection(firstRect, secondRect); // The NUDGE just offsets either object back to the left or right // After the nudging, they are exactly pressing against each other with no intersection firstGameObject.nudgeToRightOfIntersection(intersection); secondGameObject.nudgeToLeftOfIntersection(intersection); } else if ((firstRect.origin.x + firstRect.size.width) > secondRect.origin.x) { // hit from the LEFT CGRect intersection = CGRectIntersection(firstRect, secondRect); secondGameObject.nudgeToRightOfIntersection(intersection); firstGameObject.nudgeToLeftOfIntersection(intersection); } } } } } I think my collision detection code is pretty close, but obviously I'm doing something a little wrong. I really think it's to do with the way my jumps are checked (I wanted to make sure that a jump could happen from an angle (instead of if the falling player had been at a right angle to the player below). Can someone please help me here? I haven't been able to find many resources on how to do this properly (and thinking like a game developer is new for me). Thanks in advance!

    Read the article

  • UIScrollView with pages enabled and device rotation/orientation changes (MADNESS)

    - by jbrennan
    I'm having a hard time getting this right. I've got a UIScrollView, with paging enabled. It is managed by a view controller (MainViewController) and each page is managed by a PageViewController, its view added as a subview of the scrollView at the proper offset. Scrolling is left-right, for standard orientation iPhone app. Works well. Basically exactly like the sample provided by Apple and also like the Weather app provided with the iPhone. However, when I try to support other orientations, things don't work very well. I've supported every orientation in both MainViewController and PageViewController with this method: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } However, when I rotate the device, my pages become quite skewed, and there are lots of drawing glitches, especially if only some of the pages have been loaded, then I rotate, then scroll more, etc... Very messy. I've told my views to support auto-resizing with theView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; But to no avail. It seems to just stretch and distort my views. In my MainViewController, I added this line in an attempt to resize all my pages' views: - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * ([self.viewControllers count]), self.scrollView.frame.size.height); for (int i = 0; i < [self.viewControllers count]; i++) { PageViewController *controller = [self.viewControllers objectAtIndex:i]; if ((NSNull *)controller == [NSNull null]) continue; NSLog(@"Changing frame: %d", i); CGRect frame = self.scrollView.frame; frame.origin.x = frame.size.width * i; frame.origin.y = 0; controller.view.frame = frame; } } But it didn't help too much (because I lazily load the views, so not all of them are necessarily loaded when this executes). Is there any way to solve this problem?

    Read the article

  • Wrapping/warping a CALayer/UIView (or OpenGL) in 3D (iPhone)

    - by jbrennan
    I've got a UIView (and thus a CALayer) which I'm trying to warp or bend slightly in 3D space. That is, imagine my UIView is a flat label which I want to partially wrap around a beer bottle (not 360 degrees around, just on one "side"). I figured this would be possible by applying a transform to the view's layer, but as far as I can tell, this transform is limited to rotation, scale and translation of the layer uniformly. I could be wrong here, as my linear algebra is foggy at this point, to say the least. How can I achieve this?

    Read the article

  • [UIScreen applicationFrame] returning incorrect rectangle on landscape application launch (iPhone/iP

    - by jbrennan
    Having trouble getting the correct bounds for my iPad application when launching it in landscape mode. I have the proper keys set in my Info.plist file, and my view controllers launch properly in landscape (and portrait, natch). In my applicationDidFinishLaunching: method I'm calling a selector after a 3 second delay, and that method makes a call to [[UIScreen applicationFrame]`, but it's returning me a portrait frame (ie height width). Does anyone know how to fix this? It smells like a bug to me (if so I'll file a radar), but if it's intended behaviour, where is it documented?

    Read the article

  • Observing model changes with Cocoa Bindings and NSArrayController

    - by jbrennan
    I've got an NSArrayController bound to a mutable array in my controller, which manages an array of my model objects. The array controller is bound to my UI. It works well. Now I'm trying to manually observe when a value changes in my model in my controller class (basically I'm marking the changed model as "needsToSave" for later on, but there are a few other tasks I have when it changes). I've read up on KVO but I'm not entirely sure what I need to be observing... The NSArrayController? The array of objects? each model object itself? Confusion. Any pointers would be very helpful. Thanks in advance!

    Read the article

  • Rotate a CALayer when it reaches a certain position

    - by jbrennan
    I've got a CALayer with two CAKeyframeAnimations added to it. One is for @"transform" and the other is for @"position". I am rotating the layer and translating it with these two animations. I am wondering, is there a way I can set the keyframes to happen at the same time? I want to have a keyframe for rotation at the exact time my layer has reached a certain (x, y) position. How is this possible?

    Read the article

  • Calculating string sizes on iPhone on a background thread

    - by jbrennan
    I've got some somewhat hefty string size calculations happening in my app (each one takes close to 500ms, and happens when the user scrolls to a new "page" in my app (like the Weather app). The delay only happens once per page, as the calculation only needs to be run once (and can even be cached for subsequent launches with the same data). Anyway, I still like to not block the UI for this type of work, as to me it screams using threads, but I know UIKit is not meant to be used from other threads. (I know NSString is not part of UIKit, but the string sizing methods are part of the UIKitAdditions...) So how should I go about doing this? What's the best way to not block the UI and do so safely?

    Read the article

  • Prevent subview from scrolling in a UIScrollView

    - by jbrennan
    I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal). The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls. I can't seem to make my subview stay put! How can I accomplish this?

    Read the article

  • How does the momentum/inertial scroll work with the Magic Mouse on NSScrollView?

    - by jbrennan
    When you scroll with the newer Apple Magic Mouse (at least on 10.6, I can't confirm any previous Mac OS) you get inertial scroll like scrolling on iPhone (that is, after a flick of the finger to scroll, it doesn't abruptly stop, but instead gradually slows down). This behaviour is "for free" with all NSScrollViews, it would appear. There are exceptional cases, such as Tweetie for Mac (I've heard Tweetie was written with a custom Table View class that works akin to how UITableView works on iPhone). My question is, how do the scroll views know how to do this inertial scrolling? My guess is the mouse [driver] repeatedly sends scroll events with a dampening scroll magnitude (or something like that) over the scroll period. But I'm not really sure how it works. I am having some scrolling problems in my scrollview class and I'm trying to figure out why (obviously we don't have the source code to Tweetie to see why it doesn't get the proper scrolling), but just trying to better understand how it works in order to fix my own problems.

    Read the article

  • Sinatra application running on Dreamhost suddenly not working

    - by jbrennan
    My Sinatra application was running fine on Dreamhost until a few days ago (I'm not sure precisely when it went bad). Now when I visit my app I get this error: can't activate rack (~> 1.1, runtime) for ["sinatra-1.1.2"], already activated rack-1.2.1 for [] I have no idea how to fix this. I've tried updating all my gems, then touching the app/tmp/restart.txt file, but still no fix. I hadn't touched any files of my app, nor my Dreamhost account. It just busted on its own (my guess is DH changed something on their server which caused the bust). When I originally deployed my app, I had to go through some hoops to get it working, and I seem to think I was using gems in a custom location, but I can't remember exactly where or how. I don't know my way around Rack/Passenger very well. Here's my config.ru: (mostly grafted from around the web, I don't fully understand it) ENV['RACK_ENV'] = 'development' if ENV['RACK_ENV'].empty? #### Make sure my own gem path is included first ENV['GEM_HOME'] = "#{ENV['HOME']}/.gems" ENV['GEM_PATH'] = "#{ENV['HOME']}/.gems:" require 'rubygems' Gem.clear_paths ## NB! key part require 'sinatra' set :env, :production disable :run require 'MY_APP_NAME.rb' run Sinatra::Application

    Read the article

  • Best way to do interprocess communication on Mac OS X

    - by jbrennan
    I'm looking at building a Cocoa application on the Mac with a back-end daemon process (really just a mostly-headless Cocoa app, probably), along with 0 or more "client" applications running locally (although if possible I'd like to support remote clients as well; the remote clients would only ever be other Macs or iPhone OS devices). The data being communicated will be fairly trivial, mostly just text and commands (which I guess can be represented as text anyway), and maybe the occasional small file (an image possibly). I've looked at a few methods for doing this but I'm not sure which is "best" for the task at hand. Things I've considered: Reading and writing to a file (…yes), very basic but not very scalable. Pure sockets (I have no experience with sockets but I seem to think I can use them to send data locally and over a network. Though it seems cumbersome if doing everything in Cocoa Distributed Objects: seems rather inelegant for a task like this NSConnection: I can't really figure out what this class even does, but I've read of it in some IPC search results I'm sure there are things I'm missing, but I was surprised to find a lack of resources on this topic.

    Read the article

1