Im making a scene for my game. Right now im working for IPhone 5-5s-5c screens. The scene is bigger than the normal IPhone 5-5s-5c`s screen widths so the simulated size is freeform.
Now, your supposed to move this image between obstacles. and the view/ camera is supposed to follow the uiimageview.
Here is some code on how i move the image
-(IBAction)left { goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(goLeft) userInfo:nil repeats:YES]; if (goLeft == nil) { goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(goLeft) userInfo:nil repeats:YES]; }
}
-(IBAction)stopLeft { [goLeft invalidate]; goLeft = nil;
}
-(void)goLeft { ball2.center = CGPointMake(ball2.center.x -3.5, ball2.center.y);{
// left is connected to touch down
// stopLeft is connected to Touch up inside
// Thanks for any help :)
#cilus-stian The previous version of your question was tagged as SpriteKit, so I'll suppose you use SpriteKit. If you don't use it, please let me know, and I'll delete my answer which becomes irrelevant.
So what you want is your camera to follow your image (ball2).
You can simply create a SKCameraNode which does exactly what you want (sorry I don't know the Objc syntax) :
// Declare your camera
var camera: SKCameraNode = SKCameraNode()
// Add it to your scene (didMoveToView or init)
self.camera = camera
// In the update() function
self.camera.position = ball2.position
More details about SKCameraNode
Also, not sure how/why you use UIImageView, but maybe you should consider using SKSpriteNode to display your ball
Related
I'm trying to create something that if I have a UIView with background of yellow, and this view is moving on the screen, and somewhere placed another UIView with background of red. How can I know if the yellow color touch the red color? - which mean's that the first view touches the another view.
During the animation you will have to periodically check for intersection like #AMI289 has said. e.g.
- (void)animate {
// Use an NSTimer to check for intersection 10 times per second
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(checkForCollision) userInfo:nil repeats:YES];
[UIView animateWithDuration:5 animations:^{
// Do the animation
} completion:^(BOOL complete) {
// Tell timer to stop calling checkForCollision
[timer invalidate];
}];
}
- (void)checkForCollision {
if (CGRectIntersectsRect([viewOne.layer.presentationLayer frame], [viewTwo.layer.presentationLayer frame])) {
// Handle collision
}
}
It is important to get the presentation layer of the views that are being animated otherwise you will not detect incremental changes to the views' positions on the screen. You also need to invalidate the timer once you are done with it otherwise your checkForCollision method will continue to run indefinitely.
I have created a scene where I would like to have the character image move throughout the circle that I have created.
the character is an image view and the box containing the circle is an image view.
as of right now I have the image moving but it is throughout the entire scene. How would I limit the movement to just within the circle?
here is the code that I have so far:
.h
#interface FinalProjectViewController : UIViewController {
IBOutlet UIImageView *romo;
CGPoint pos;
NSTimer *romoMove;
}
-(void)romoMoving;
.m
- (void)viewDidLoad {
romoMove = [NSTimer scheduledTimerWithTimeInterval:0.09 target:self
selector:#selector(romoMoving) userInfo:nil repeats:YES];
pos = CGPointMake(5.0, 4.0);
}
-(void)romoMoving
{
romo.center = CGPointMake(romo.center.x+pos.x, romo.center.y+pos.y);
if (romo.center.x>170||romo.center.x<0) {
pos.x = -pos.x;
}
if (romo.center.y>180||romo.center.y<0) {
pos.y = -pos.y;
}
}
I was thinking the best way to go about it was to find the points of the circle that I would like the character to hit then set those as the points as it should move to. I am not sure if that would be the best way to do this, nor was I very sure on how to accomplish this.
As always after a lot of searching I back here to get help
my app playing sounds from url, I track the sound playing in uislider by update slider value when start the streamer playing
progressUpdateTimer =
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:#selector(updateProgress:)
userInfo:nil
repeats:YES];
- (void)updateProgress:(NSTimer *)updatedTimer
{
[progressView setValue: progress / duration];
}
this is my action for change slider value ( forward / backward the track)
- (IBAction)sliderMoved:(UISlider *)aSlider
{
if (streamer.duration)
{
double newSeekTime = (aSlider.value) * streamer.duration;
[streamer seekToTime:newSeekTime];
}
}
What I want is when the user change the slider the value updates instantly without late of loading .. I mean change the slider value then load the sound
But what happened is by dragging the slider thumb to x position , it backs to its position and then move to x when sound loaded
How can I do that ? any help will be appreciated
I'm adding a background effect to my app by rotating an UIImageView using:
- (void) viewDidLoad {
rotateAngle = 0;
[NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:#selector(bgEffect) userInfo:nil repeats:YES];
}
- (void) bgEffect{
rotateAngle += .01;
CGAffineTransform rotate = CGAffineTransformMakeRotation( rotateAngle );
[_bgImage setTransform:rotate];
}
The weird problem with that is it affects some of my UI elements by shifting them. It doesn't affect all UI elements, just some. I tried to change the hierarchy, but no luck. I don't understand what the problem is. Can someone help me?
Try turning off Auto-Layout in your Storyboard.
I am making a driving game for the iOS, where a car (UIView) is put on top of the google maps ios api. I am having trouble detecting collisions with the car and the grey buildings that appear on the map.
I have been trying to do it by pixel color i.e. checking if the pixel color, just ahead of the car, is the color of a buildings roof (grey). There is no direct access to an iPhones pixel color, so I am using the google maps screenshot method to get an image and get the pixel color from that. The problem is, is that I can only take a screen shot of the screen I just left. I am using
mapImage = [GMSScreenshot screenshotOfMainScreen];. I have also tried getting the window and screen and calling mapImage = [GMSScreenshot screenshotOfScreen:topWindow.screen]; Both have the same effect.
What is a solution to this problem? Can you think of a better way of handling collisions for this situation? Does reverse geocoding have the ability to detect the tops of buildings vs streets?
Thanks for any and all help!
EDIT:
Images:
Interface Builder: Left is the main menu, right is the game. The Ui image view in the upper left corner is set as the current screen shot image for referencing purposes. This how I knew It was off
Game Play, As you can see, it is only presenting the previous menu.
My viewdidLoad function: Not much other than this thats related to getting the image.
- (void)viewDidLoad
{
[super viewDidLoad];
cameraPosition = CLLocationCoordinate2DMake(42.271291, -83.729918);
moveDistance = .00055;
cA = [UIColor colorWithRed:.937255 green:.921569 blue:.886275 alpha:1];
camera = [GMSCameraPosition cameraWithLatitude:cameraPosition.latitude
longitude:cameraPosition.longitude
zoom:19
bearing:0
viewingAngle:0];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 480, 300) camera:camera];
mapView_.myLocationEnabled = NO;
[self.view addSubview:mapView_];
car_ = [[Car alloc] initWithFrame:CGRectMake(240, 150, 13, 29) withImage:[UIImage imageNamed:#"carA-01.png"]];
[self.view addSubview:car_];
[self.view addSubview:controllerView];
updateClock = [NSTimer scheduledTimerWithTimeInterval:(1/20)
target:self
selector:#selector(update)
userInfo:nil
repeats:YES];
crashClock = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:#selector(checkCrash)
userInfo:nil
repeats:YES];
UIWindow *topWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
mapImage = [GMSScreenshot screenshotOfScreen:topWindow.screen];
// mapImage = [GMSScreenshot screenshotOfMainScreen];
}
Are you getting a new screenshot every frame (or on some interval), eg from your update callback?
The GMSMapView doesn't render immediately when you create or make changes to it - it renders later on its next update. Therefore when you take the screenshot in viewDidLoad you're probably getting what was on the screen at the time that the map view was added, ie the initial menu.