I have added the UIScrollView into the COCOS2D game engine using
[[[CCDirector sharedDirector] openGLView] addSubview: tempScrollView];.
On that scroll view I have added a image view and a buttons. My problem is that the scroll view is scrolling vertically only. I want the UIScrollView to scroll horizontally only. Also I want the images to be rotate as well. I have tried the view transform property but its not working in my case.
Does any body know how to do this in cocos2d?
Horizontaly only ? try to change contentsize. e.g.:
ccp(5000,winsize.height)
Related
I have an app similar to most with a main view that scrolls vertically. On top of that, I have a horizontal drag gesture to pull out a side menu.
The issue I am running into when trying to drag the menu open is any vertical movement at all stops the horizontal gesture from working until the vertical movement has ended. So it is very difficult to get the horizontal gesture to activate.
I have tried using .highPriorityGesture and .simultaneousGesture but neither seem to help.
Adding a minimumDistance on the Vertical gesture should fix it
DragGesture(minimumDistance: 10)
The famo.us tutorials shows how to use a ScrollView which doesn't seem to provide a horizontal scrolling method.
So I was wondering how do I implement horizontal scrolling for my famo.us app (my personal website).
Yes. To enable Horizontal scrolling you simply pass the direction option to the Scrollview constructor..
var scrollview = new Scrollview({
direction: Utility.Direction.X
});
Utility.Direction.X actually is a pretty way of saying 0. So this will work as well..
var scrollview = new Scrollview({
direction: 0
});
Good Luck!
I am using a UISwitch in my cocos2d project like so:
//header file
UISwitch *musicCtrl;
//implementation file
musicCtrl = [[UISwitch alloc] initWithFrame:CGRectMake(100, 50, 0, 0)];
musicCtrl.on = YES;
[musicCtrl addTarget:self action:#selector(musicOnOff) forControlEvents:UIControlEventValueChanged];
[[[CCDirector sharedDirector]openGLView] addSubview:musicCtrl];
musicCtrl.transform = CGAffineTransformMakeRotation(M_PI/2);
[musicCtrl release];
I have attached the UISwitch to the openGLView but I need to be able to attach it to a certain CCLayer on the GLView. Is that possible? I can't seem to find a UISwitch alternative for cocos2d.
It's not possible.
You can only add UIKit views to the cocos2d view, or the main window. Either way, the UIKit view will be drawn above all of the cocos2d nodes. You can not add a UIKit view to a specific layer.
Specifically you can't add UIKit views to a cocos2d app in a way where some cocos2d nodes are drawn in front of and other nodes drawn behind the UIKit view. That is impossible.
So I added a UITextView to my OpenGL view in Cocos2D.
Did some rotation to fit my landscape view and all. But somehow when the whole scene rotates, the textview doesn't. I've tried
[[[CCDirector sharedDirector] openGLView] window].autoresizesSubviews = YES;
and including these functions but it still stays put..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
any ideas?
i've added it to my openGLView using:
[[[[CCDirector sharedDirector] openGLView] window] addSubview:self];
my class inherits from UITextView.
Open file GameConfig.h, define Autorotation type. Hope it will help.
I have a UIButton that moves around randomly on the screen. On clicking on the button, a new scene is loaded that, for now, contains a CCSprite. Here is the code:
//in init
CCSprite *a = [CCSprite spriteWithFile:#"a.png"];
[a setPosition:ccp(0,0)];
[self addChild:a];
Pretty straightforward, and it stumps me why after 'replaceScene' the UIButton of theHelloWorldScene.m is still visible, right on top of the Sprite. Where am I going wrong?
I'm assuming since you're adding a UIButton into a cocos2d Scene you're using the openGLView
something like:
[[[CCDirector sharedDirector] openGLView] addSubView:button];
If this is the case, then before you replace your HelloWorldScene you'll need call something similar to
[button removeFromSuperview]
Where button is the name of your UIButton (in both instances).
A suggestion though would be to use a CCMenu with a CCMenuItem on your HelloWorldScene as UIKit objects don't really mesh very well with Cocos2d.
You really aren't giving enough information. The simplest answer however is that if you do not want the button to be visible anymore then remove the child (the button). You can set a tag on the button and then use [layer getChildByTag:(NSInteger)].