cocos3d billboard paning with gestures - gestures

I want to pan the billboard using using gestures how can i do that, i have modified the DemoMashUp like this:
- (void)dragBy: (CGPoint) aMovement atVelocity: (CGPoint) aVelocity
{
if (selectedNode == dieCube || selectedNode == texCubeSpinner) {
[self rotate: ((SpinningNode*)selectedNode) fromSwipeVelocity: aVelocity];
}
if (selectedNode==marker) {
[self moveSelectedNode:marker fromSwipeMovement:aMovement];
}
}
- (void)stopDragging
{
selectedNode = nil;
}
- (void)moveSelectedNode:(CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement
{
aNode.location=cc3v(swipeMovement.x, swipeMovement.y, aNode.location.z);
}
but its not working and when i touch the billboard it disapears

i made a new method moveSelectedNode "DemoMashUpScene" like this :
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {
NSLog(#"\n\n*******************TOUCH EVEN CALLED************************\n\n");
switch (touchType) {
case kCCTouchBegan:
[self pickNodeFromTouchEvent: touchType at: touchPoint];
break;
case kCCTouchMoved:
if (selectedNode==marker||selectedNode==marker1||selectedNode==marker2||selectedNode==marker3||selectedNode==marker4||selectedNode==marker5)
{
[self moveSelectedNode:marker1 fromSwipeMovement:touchPoint];
}
break;
case kCCTouchEnded:
selectedNode = nil;
break;
default:
break;
}
lastTouchEventPoint = touchPoint;
lastTouchEventTime = now;
}
-(void) moveSelectedNode: (CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement {
CC3Vector vector= CC3VectorMake(swipeMovement.x * 3, swipeMovement.y * 3, 0);
aNode.location=cc3v(aNode.location.x, aNode.location.y, 0.0);
aNode.location=CC3VectorAdd(aNode.location,vector);
CCLOG(#"%#",aNode.name);
// NSLog(#"\n\n ******MOVING****%f_____%f*****____%f",vector.x,vector.y,vector.z);
}

Related

CAShapeLayer custom property is nil when drawInContext

I denfined a custom layer,and declare a custom property,but it's not work when animation in -(void)drawInContext:(CGContextRef)ctx method
here is some code:
#interface ZBBProgressLayer : CAShapeLayer
#property (nonatomic, assign) CGFloat progress;
#property(nullable) CGColorRef progressColor;
#end
#implementation ZBBProgressLayer
+ (BOOL)needsDisplayForKey:(NSString *)key{
if ([key isEqualToString:#"progress"]/*progress 属性变化时,重绘*/) {
return YES;
}
return [super needsDisplayForKey:key];
}
-(void)dealloc{
[self removeAllAnimations];
}
#end
// ZBBRectProgressLayer
#interface ZBBRectProgressLayer : ZBBProgressLayer
#end
#implementation ZBBRectProgressLayer
-(void)drawInContext:(CGContextRef)ctx{
CGSize boundsSize = self.bounds.size;
CGFloat width = boundsSize.width * self.progress;
UIBezierPath *cutoutPath =[UIBezierPath bezierPathWithRect:CGRectMake(0,
0,
width,
boundsSize.height)];
CGContextSetFillColorWithColor(ctx,self.progressColor);
CGContextAddPath(ctx, cutoutPath.CGPath);
CGContextFillPath(ctx);
// NSLog(#"%# = %#\n",[self class],self);
}
#end
I use the layer like this:
-(void)setProgress:(CGFloat)progress animated:(BOOL)animated{
_progress = MIN(progress, 1);
if (animated) {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:#"progress"];
animation.duration = kAnimationDurationTime;
animation.fromValue = #(_maskLayer.progress);
animation.toValue = #(_progress);
[_maskLayer addAnimation:animation forKey:#"progress"];
_maskLayer.progress = _progress;
}else{
_maskLayer.progress = _progress;
[_maskLayer performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
}
}
but animated == true,custom layer.progressColor is nil,
animated == false,custom layer.progressColor is right.
source code : https://github.com/zhangbinbin5335/ZBBProgressView.git

How to make jump animation in Game Maker?

for some reason when I run the game the sprite is in its jump animation and not its idle at the start even when moving left and right the sprite is still the jump animation. i followed a tutorial on youtube i know that the right and left animations work any help would be appreciated thanks.
///platform "physics"
var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check_pressed(vk_up);
//Check for ground
if (place_meeting(x, y+1, obj_solid))
{
airjump = 1;
vspd = 0;
//Jumping
if (jkey)
{
vspd = -jspd;
}
}
else
{
//Gravity
if (vspd < 10 )
{
vspd += grav;
}
//Check For airjump
if(airjump > 0)
{
if(jkey)
{
vspd = -jspd;
airjump -= 1;
}
}
}
//Moving Right
if(rkey)
{
hspd = spd;
//Left Wall-Jump
if(place_meeting(x-1, y, obj_solid) && !place_meeting(x, y+1, obj_solid)
&& !lkey)
{
vspd = -jspd;
}
}
//Moving Left
if(lkey)
{
hspd = -spd;
//Right Wall-Jump
if(place_meeting(x+1, y, obj_solid) && !place_meeting(x, y+1, obj_solid)
&& !rkey)
{
vspd = -jspd;
}
}
//Check for not moving
if((!rkey && !lkey) || (rkey & lkey))
{
hspd = 0 ;
}
//Horizontal Collisions
if(place_meeting(x + hspd, y, obj_solid))
{
while(!place_meeting(x+sign(hspd), y,obj_solid))
{
x += sign(hspd);
}
hspd = 0;
}
//Move Horizontally
x += hspd;
//Vertical Collisions
if(place_meeting(x, y+vspd, obj_solid))
{
while(!place_meeting(x, y+sign(vspd),obj_solid))
{
y += sign(vspd);
}
vspd = 0;
}
//Move Vertically
y += vspd;
//Control The Sprites
if(vspd != 0)
{
sprite_index = spr_player_jump;
image_speed = 1;
//use the next line if you have a falling animation as well but the
falling animation should be the second one
//image_index = y>yprevious;
}
else
{
if(hspd != 0)
{
sprite_index = spr_player_walk;
image_speed = .15;
}
else if(hspd = 0)
{
sprite_index = spr_player_stand;
}
}
if (!place_meeting(x,y+1, obj_solid))
{
sprite_index=spr_player_jump;
}
//Control the direction that the player is facing
if(hspd > 0)
{
image_xscale = 1;
}
else if (hspd < 0)
{
image_xscale = -1;
}
First, in the create event, set image_speed = 0; Then you have to play the animation once.
Then once you're in the step event, when the player jumps:
`while (image_index != image_number)
{
image_index++;
}
//Or you can replace image_number with the end
//value of your jump animation, if you also have other animations like
//walking then set image index to the start value before running the loop`
Also, a check to make sure the player is on the ground too (so pressing the space bar in the air doesn't make the animation play. Unless you want that.)

GridView of photos and zoom on tap of any image

I wish to create a grid-like photo gallery, where there are 3 photos in each row which has same frame size. When user taps on any photo, it has to zoom as given in the attached image & other photos has to get aligned accordingly.
I am new to UICollectionView. However I have managed to display 3 cells in a single row as given in the below screenshot.
I have done this similar to the display of UITableview. I have created a new UICollectionviewCell Class in which the frame of a single cell is declared.
bigBoxIndex is the indexpath.row in which the cell has to be expanded.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (bigBoxIndex == indexPath.row) {
return CGSizeMake(bigBoxWidth, bigBoxHeight);
}
else {
return CGSizeMake(boxWidth, boxHeight);
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DealListCVCell *cell = (DealListCVCell*)[collectionView cellForItemAtIndexPath:indexPath];
DealListCVCell *expandedCell = (DealListCVCell*)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:bigBoxIndex inSection:0]];
if (bigBoxIndex == indexPath.row) {
bigBoxIndex = -1;
}
else {
bigBoxIndex = indexPath.row;
}
if (bigBoxIndex == -1) {
[collectionView performBatchUpdates:^{
for (NSInteger i = 0; i < NUMBER_OF_ITEMS; i++) {
NSIndexPath *fromIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
NSInteger j = i;
NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:j inSection:0];
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
}
} completion:^(BOOL finished) {}];
[UIView beginAnimations:#"Zoom" context:NULL];
[UIView setAnimationDuration:0.3];
[expandedCell.dealImg setFrame:CGRectMake(2.0f, 2.0f, boxWidth-4.0f, boxHeight-4.0f)];
[UIView commitAnimations];
}
else {
[UIView beginAnimations:#"Zoom" context:NULL];
[UIView setAnimationDuration:0.3];
[cell.dealImg setFrame:CGRectMake(2.0f, 2.0f, (2 * boxWidth)-4.0f, (2 * boxHeight)-4.0f)];
[UIView commitAnimations];
[collectionView performBatchUpdates:^{
[expandedCell.dealImg setFrame:CGRectMake(2.0f, 2.0f, boxWidth-4.0f, boxHeight-4.0f)];
for (NSInteger i = 0; i < [[self.entries objectAtIndex:0] count]; i++) {
NSIndexPath *fromIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
NSInteger j = i;
NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:j inSection:0];
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
}
} completion:^(BOOL finished) {}];
}
}
As per my code, when user taps on an image, it gets enlarged as given in the below screenshot.
How can I manage the layout of a single row?

Annotation not dragging

MapPin.h :
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MapPin : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic,readwrite,assign)CLLocationCoordinate2D coordinate;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description;
-(void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;
#end
and here's the MapPin.m
#import "MapPin.h"
#implementation MapPin
#synthesize coordinate;
-(NSString *)subtitle{
return nil;
}
-(NSString *)title{
return nil;
}
-(id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description{
coordinate=location;
return self;
}
-(CLLocationCoordinate2D)location{
return coordinate;
}
-(void)setCoordinate:(CLLocationCoordinate2D)newCoordinate{
coordinate=newCoordinate;
}
#end
In the ViewController.h i've adopted the MKMapViewDelegate protocol.
and here's the ViewController.m :
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pin = (MKPinAnnotationView *)[self.MyMap dequeueReusableAnnotationViewWithIdentifier:#"myPin"];
if(pin == nil){
pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"myPin"];
}
else{
pin.annotation=annotation;
}
pin.draggable=YES;
return pin;
}
//Add Location button
- (IBAction)AddPin:(id)sender {
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;
MKCoordinateRegion region;
region.center=center;
region.span.latitudeDelta=0.2f;
region.span.longitudeDelta=0.2f;
MapPin *myPin = [[MapPin alloc]initWithCoordinates:self.MyMap.centerCoordinate placeName:#"LoMinder!" description:#"Set Location for LoMinder!"];
[_MyMap addAnnotation:myPin];
}
//Dropping the pin:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState
{
//Region
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
if (newState == MKAnnotationViewDragStateStarting)
{
[_MyMap setRegion:myRegion animated:YES];
}
if(newState == MKAnnotationViewDragStateDragging)
{
myRegion.center=annotationView.annotation.coordinate;
myRegion.span.latitudeDelta=0.2f;
myRegion.span.longitudeDelta=0.2f;
[_MyMap setRegion:myRegion animated:YES];
}
if(newState==MKAnnotationViewDragStateEnding)
{
arrived=self.MyMap.centerCoordinate;
center=annotationView.annotation.coordinate;
myRegion.center=center;
myRegion.span.latitudeDelta=0.2f;
myRegion.span.longitudeDelta=0.2f;
[_MyMap setRegion:myRegion animated:YES];
}
}
/////
I've also imported the MapPin.h into the ViewController.
When I run my app, I should press the Add Location button in ord er to get the annotation pin, I press the button, the annotation pin appears on the map, but the problem is that when i try to drag it, it seems to be un-draggable.
Please people some help.
Thank you :)
Solved by changing the title method in the MapPin.m
Make it return anything but nil.

AVAudioPlayer Notification issue

So I'm almost done with my app and I've hit a wall and cannot get around this final problem.
I basically have 2 view's. A main page and the game play screen.
On the first play the game works fine, but when i leave the main screen and then return to the game screen all the sounds are duplicating and firing the the playerItemDidReachEnd early (because I'm guessing there are 2 instances of it, but it cannot seem to get the player to stop this. Here is the basic code causing this. Any help would go a long way, thanks. I'm not sure if my issue is i'm creating multiple instances of View2 in View1 or if I'm creating multiple player objects in view2 thus duplicating the notification.
I know there is a lot going on in my - (void)playerItemDidReachEnd:(NSNotification *)notification, but it works fine on the first load of the page, its only when I click "go back to view1" and then go back in to View2 that the issue happens.
View1ViewController.h
----------------------
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h>
#import "ApplicationViewController.h"
#interface MonsterSpellViewController : UIViewController {
}
-(IBAction)showView1;
View2ViewController.m
----------------------
-(IBAction)showView2{
ApplicationViewController *view2 = [[ApplicationViewController alloc]initWithNibName:#"ApplicationViewController" bundle:nil];
view2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:view2 animated:YES];
}
View2ViewController.h
------------------------
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h>
#import "(i know here are arrows here, but can't make them show)AVFoundation/AVFoundation.h>
#class AVAudioPlayer;
#interface ApplicationViewController : UIViewController{
AVAudioPlayer *avPlayer;
}
View2ViewController.m
-------------------------
#import "View2ViewController.h"
#synthesize avPlayer;
-(AVAudioPlayer *)avPlayer {
if(!avPlayer) avPlayer = [[AVAudioPlayer alloc]init];
return avPlayer;
}
-(void) viewDidLoad
{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:avPlayer];
}
-(IBAction)playSoundTest
{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/monster3.mp3", [[NSBundle mainBundle] resourcePath]]];
self.avPlayer = [AVPlayer playerWithURL:url];
[self.avPlayer play];
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
//[player seekToTime:kCMTimeZero];
if (playEscape == YES) {
[self btnEscapeSound];
playEscape = NO;
}
if ((startButton.hidden == NO) && (letterCount != -1) && (playFinal == YES))
{
[self btnFinalSound];
playFinal = NO;
playEscape = YES;
}
NSLog(#"Player Check accessed");
if (letterCount == 3) {
if (Winner == letterCount) {
//moveNextSound = YES;
if (intLoopCount < 104)
{
if (intLoopCount<104) {
[self btnStartOver:intLoopCount];
playFinal = NO;
//intLoopCount++;
}
if (intLoopCount==104) {
startButton.hidden=NO;
playFinal = YES;
}
}
}
}
if (letterCount == 4) {
if (Winner == letterCount) {
//moveNextSound = YES;
if (intLoopCount < 105)
{
[self btnStartOver:intLoopCount];
//intLoopCount++;
if (intLoopCount==105) {
startButton.hidden=NO;
playFinal = YES;
}
}
}
}
}
}
-(IBAction)goBack:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
Try adding [view2 release]; after [self presentModalViewController:view2 animated:YES];

Resources