Menu Button in Cocos2d - ios6

Im trying to make the play button on the main menu of my game in Cocos2d which is an image file. I set up the sprite as playButton with the image Play Button.png. When I ran the app it gave me an error that the "itemFromNormalSprite:selectedSprite:target:selector." is deprecated. Anybody have a solution to this problem? Here is my code:
CCMenuItem *playGameButton = [CCMenuItemSprite itemFromNormalSprite:playButton selectedSprite:playButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];

CCMenuItem *playGameButton = [CCMenuItemImage itemFromNormalImage:playButton selectedImage:playButton disabledImage:disabledPlayButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];

Related

clipped image not visible on Tablet EaselJS + sourceRect used

i am working on a Mobile project (iPad with iOS 8.0.2);
I want to make clipping of my immage in order to display less from it.
When displaying on PC it works perfectly well, while we test it on the tablet the clipped image is not displayed at all.
Do you have any suggestions
this.background = new createjs.Bitmap('some_image.png');
//create a clipping of drawn image!
var dims = this.background.getBounds();
this.background.sourceRect = new createjs.Rectangle(0, 15, dims.width, dims.height);
this.background.x = 248;
this.background.y = 86;
this.stage.addChild(this.background);
I met the same trouble like this.I have given up using Bitmap to clipping the image. I have found another solution ,here is "
easeljs splitting an image into pieces
".Good luck.
I am working out, the code like this:
var img, stage;
function init() {
//wait for the image to load
img = new Image();
img.onload = handleImageLoad;
img.src = "./res/image.png";
}
function handleImageLoad(evt) {
// create a new stage and point it at our canvas:
stage = new createjs.Stage("canvas");
// create a new Bitmap, and slice out one image from the sprite sheet:
var bmp = new createjs.Bitmap(evt.target).set({x:200, y:200});
bmp.sourceRect = new createjs.Rectangle(916, 101, 84, 84);
//x,y,width,height
stage.addChild(bmp);
stage.update();
}
This is the example:
https://github.com/CreateJS/EaselJS/blob/master/examples/Filters_animated.html

ios : UIScrollView with UITableView

I want to implement one page with vertical scroll view which contains some Images, Labels and one table view in bottom.
Table may have any number of rows. When user scroll to the top other elements such as images, labels should be hide but table should be visible at the top of screen and only table items should be scrolled.
I have tried by setting the currentoffset of scrollview in method scrollViewDidEndDecelerating but its not such smooth.
Scroll view first goes above, comes down and then set the table at top.
Can you please suggest me what should i implement here?
Thanks.
Try this....
// Add image in scrollView
serviceImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"row.png"]];
[serviceImage setBackgroundColor:[UIColor clearColor]];
serviceImage.frame = CGRectMake(10, 10, 300, 100);
[myScrollView addSubview:serviceImage];
[serviceImage release];
// Add label in scrollView
UILabel *rateLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 300, 20)];
rateLbl.text = #"Rates";
rateLbl.font = [UIFont boldSystemFontOfSize:17.0];
rateLbl.textColor = [UIColor colorWithRed:244/255.0 green:29/255.0 blue:94/255.0 alpha:1.0];
rateLbl.textAlignment = UITextAlignmentLeft;
rateLbl.backgroundColor = [UIColor clearColor];
[myScrollView addSubview:rateLbl];
[rateLbl release];
// Add table in scrollView
int heightRateTbl;
heightRateTbl = [productType count] * 44;
rateTableView.frame =CGRectMake(10, expectedLabelSize.height + expectedDecLblSize.height + heightDayTbl + 555, 300, heightRateTbl);
rateTableView.scrollEnabled = NO;
rateTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[rateTableView reloadData];
You can enable or disable scroll according your choice.
// Set scrollView height
myScrollView.contentSize = CGSizeMake(320, 125 + heightRateTbl);
Do not forget to set delegates and declare all things(in .h file and in .xib file).
Hope i helped.

Getting the Tag Number of Touched Object

I have a button. Every time the user clicks on it, the application will instantiate the UIImageView (imageview), assigning a unique number to its tag.
- (IBAction)buttonClicked:(id)sender {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 240)];
NSUInteger currentag = [self UniqueNum]; // Assigning a unique number to the tag variable
[self.view addSubview:imageview];
imageview.backgroundColor = [UIColor blueColor];
imageview.userInteractionEnabled = YES;
imageview.tag = currentag;
}
My goal is to get the tag number of the UIImageView copy that the user touches. With the following code, what I actually get is the tag number of the UIImageView copy that the application last created. How can I improve it so that the application will point to the tag number of the touched object?
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == imageview) {
NSLog(#"Tag: %i",imageview.tag);
}
}
Thank you for your help.
I'd recommend using UIButtons with custom images here rather than UIImageViews if you need interaction.
Add this when you add the button:
[imageview addTarget:self action:#selector(someMethod:) forControlEvents:UIControlEventAllTouchEvents];
And then just cast the sender in someMethod (your declaration) to UIView to get its tag.
BTW, the method signature of someMethod goes something like this:
-(void) someMethod:(id)sender
You can optionally also add an event parameter, but that doesn't seem to be needed here.

custom right bar button item in ios6 is not transparent

i am creating a custom right bar button item for my navbar using the following code :
// create a toolbar
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 50, 44.01)];
// create the array to hold the button, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:1];
// create a toolbar item with image
NSString* pathToSettingsResourceFile = [[NSBundle mainBundle] pathForResource:#"19-gear" ofType:#"png"];
UIImage* settingsImage = [[[UIImage alloc] initWithContentsOfFile:pathToSettingsResourceFile] autorelease];
settings = [[UIBarButtonItem alloc]initWithImage:settingsImage style:UIBarButtonItemStylePlain target:self action:#selector(showSettings:)];
settings.enabled = FALSE;
// add button to toolbar
[buttons addObject:settings];
[tools setItems:buttons animated:NO];
[buttons release];
// add toolbar as a right bar button item
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:tools] autorelease];
[tools release];
until ios 6 this works as expected, from ios 6 i am getting this weird rectangle background
and adding
tools.opaque = NO;
tools.backgroundColor = [UIColor clearColor];
doesn't help,
please help me get rid of this background
Thanks in advance,
Amit
I know this is an old thread, but I had the same issue, and thought you might be interested in what I discovered.
A work-around is available in this thread (the answer by jd, not the "accepted" answer).
You should be able to get the behavior you want with this code:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[tools setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Although this works, I am not convinced that it is the correct way to do it, so I started a new thread here in case anyone knows the secret code for making a UIToolbar containing rectangle behave as a transparent object should.

UISplitViewController Detail View Drop shadow

I'm trying to set a shadow on my UISplitViewController's Detail View, that I want to be visible over the Master View, in iOS 6.
In my Detail ViewController:
self.view.layer.shadowColor = [[UIColor blackColor] CGColor];
self.view.layer.shadowOffset = CGSizeMake(-3.0f, 0.0f);
self.view.layer.shadowRadius = 3.0f;
self.view.layer.shadowOpacity = 1.0f;
self.view.layer.masksToBounds = NO;
self.view.clipsToBounds = NO;
However, the SplitVC automatically clips its sub-views, even when I set it to NO in the above code, and there is no shadow.
Can anyone let me know the correct way to achieve this?
The best way I found to do this is to add a 1px view to the master view controller and snap it to the right edge and apply a shadow to that view instead.
It seems that a superview some way down the hierarchy is performing the clipping.
Try this:
UIView *v = self.view;
do
{
v.clipsToBounds = NO;
v = v.superview;
}
while(v != nil);
Be aware that this will turn of clipping for all view in the hierarchy! - This might be more than you asked for:-).

Resources