2 Replies - 191 Views - Last Post: 07 April 2013 - 08:21 PM Rate Topic: -----

#1 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Should I use multiple views?

Posted 07 April 2013 - 01:00 PM

Let's say I'm developing a "Risk" like game (I am) and I need to display not only the map and it's current state (already done) but also need some type of OHD to keep the player informed of the current turn phase and basically what he has and can do... should I create a new view for this menu/OHD or just stick it in as a layer in my main map view?
Is This A Good Question/Topic? 0
  • +

Replies To: Should I use multiple views?

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Should I use multiple views?

Posted 07 April 2013 - 07:50 PM

Show some code for what you have done so that we can see some context.
Was This Post Helpful? 0
  • +
  • -

#3 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Re: Should I use multiple views?

Posted 07 April 2013 - 08:21 PM

Well... I have lot's of code already but I'll stick with what I assume you want. First off some context:

I opened a new Cocos2D project which set up an AppDelegate a View (I changed the original name of it to GameView but it's more like a view controller), and also an IntroView. The intro view extends CCLayer. The AppDelegate pushes the IntroView to the CCDirector. The introView makes a transition from itself to the GameView.

My question is: should I create a new view (extends CCLayer) for my interactive heads up display that would display game info as well as clickable buttons and add it to my scene in GameView with a z of 1? Orrrr just add more sprites to the current CCLayer GameView?

I'm completely new to Objective-C so If you notice i'm making fundamental or mem management mistakes please point them out :)

// GameView.m
// Samuel Thibodeau


#import "GameView.h"
#import "AppDelegate.h"


@implementation GameView

@synthesize state;

+(CCScene *) scene
{
	CCScene *scene = [CCScene node];
	
	GameView *layer = [GameView node];

        // HERE IS WHERE I COULD POTTENTIALLY ADD A HUDView LAYER TO THE SCENE
	
	[scene addChild: layer];
	
	return scene;
}


-(id) init
{
	if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
        
        state = [[GameState alloc] init];
        
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
        CCSpriteBatchNode *territorySprites = [CCSpriteBatchNode batchNodeWithFile:@"territories.pvr.ccz"];
        [self addChild:territorySprites];
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"territories.plist"];

        [state createTerritoriesWithSpriteBatchNode:territorySprites];

        //THIS IS WHERE I COULD POTENTIALLY ADD SPRITES TO CREATE THE HUD

        //[self scheduleUpdate];
        
        [self setIsTouchEnabled:YES];
        
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_Default];
    }
    return self;
    
}


- (bool)isInPolyWithPoints:(NSArray *)points withTestingPoint:(CGPoint)testPoint
{
    int i, j;
    bool c = FALSE;
    for (i = 0, j = [points count] - 1; i < [points count]; j = i++) {
        if ( (([[points objectAtIndex:i] CGPointValue].y > testPoint.y) != ([[points objectAtIndex:j] CGPointValue].y > testPoint.y)) &&
            (testPoint.x < ([[points objectAtIndex:j] CGPointValue].x - [[points objectAtIndex:i] CGPointValue].x) * (testPoint.y - [[points objectAtIndex:i] CGPointValue].y) / ([[points objectAtIndex:j] CGPointValue].y - [[points objectAtIndex:i] CGPointValue].y) + [[points objectAtIndex:i] CGPointValue].x) )
            c = !c;
    }
    return c;
    
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    
    // Choose one of the touches to work with
    UITouch *touch = [touches anyObject];
    CGPoint location = [self convertTouchToNodeSpace:touch];
    
    for(int i = 0; i < [state.territories count]; i++)
    {   
        if([self isInPolyWithPoints:(NSArray*)[[state.territories objectAtIndex:i] points] withTestingPoint:ccp(location.x, location.y)])
        {
            // JUST A TEST TO ENSURE isInPoly works... it does!
            
            printf("Touching: %s\n", [[[state.territories objectAtIndex:i] name] UTF8String]);
        }
    }
}

- (void)update:(ccTime)dt {
    
    
    
}


// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}


@end



I have these following classes (.h and .m)... just ask if you want to see any of them

LocalMatch
Player
PlayerSelectionLayer <- This is a CCLayer that displays an entire scrren for adding players to the game (in progress)
XMLParser
GameState <- This is the Model
AppDelegate
GameView
IntroLayer

Cheers bud!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1