views:

550

answers:

2

Can anyone help convert this this actionscript to Objective-c?

if(mcMain.y >= stage.stageHeight - mcMain.height)
{
    mainJumping = false;
    mcMain.y = stage.stageHeight - mcMain.height;
}

Specifically the stage.stageHeight and mcMain.height?

+2  A: 

Without knowing what mcMain and stage are, no, not easily. I assume that stage refers to the main drawing area; assuming that you are drawing within a UIView subclass, you can find the dimensions of the view by calling bounds upon the view:

CGRect bounds = self.bounds;

This will return a CGRect, which in itself is comprised of a CGPoint, called origin, and a CGSize called size; these are C-structs:

struct CGPoint {
    CGFloat x;
    CGFloat y;
};

struct CGSize {
    CGFloat width;
    CGFloat height;
};

To find the height of the UIView, you can do so quite simply:

CGFloat height = self.bounds.size.height;

Assuming that you are trying to find out the height of the view from within the view class itself.

I'm guessing that mcMain refers to some kind of image or object, so implementation of that is dependent on what it is. However, most co-ordinates rely on CGRect, CGPoint and CGSize in some way or another.

Perspx
A: 

If you're coming from the Flash world(like I did), then I highly recommend looking into the open source Cocos2D-iPhone framework: http://www.cocos2d-iphone.org/

I've rewritten your code in approximate Objective-C, just to give you an idea of what it might look like.

float stageHeight = [UIScreen mainScreen].bounds.size.height;
float guyHeight = mainGuy.contentSize.height;

if(mainGuy.position.y >= stageHeight - guyHeight)
{
    mainJumping = NO;
    mainGuy.position = ccp(mainguy.position.x, stageHeight-guyHeight);
}
Matt Rix