Guest User

Untitled

a guest
Oct 20th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *
  3. * File intestazione
  4. *
  5. */
  6.  
  7. @interface HelloWorldLayer : CCLayer
  8. {
  9.     CGSize screenSize;
  10.     CGSize size;
  11.  
  12.     float halfScreens; // calcolo la metà dello schermo normale  
  13.     bool screenMoved;
  14. }
  15.  
  16. /**
  17. *
  18. * File metodi
  19. *
  20. */
  21.  
  22. // Dentro init
  23.  
  24.  
  25. // ask director the the window size
  26. screenSize = [[CCDirector sharedDirector] winSize];
  27. size = CGSizeMake(screenSize.width, screenSize.height * 2.0f); // dimensione doppia in altezza
  28. halfScreens = screenSize.height / 2; // metà schermo
  29.  
  30.  
  31. // Dentro update ccTime deltaTime
  32.  
  33.  
  34. // Se la posizione ( ASSE Y) della sprite supera la metà dello schermo
  35. // e la posizione del bg è maggiore a zero muovo il background
  36.  
  37. // N.B. il gioco è in landscape
  38.  
  39. // effetto ottico.. la sprite è ferma, il background in movimento
  40.  
  41. if((sprite.position.y > halfScreens) && (bg.position.y > 0)){
  42.     screenMoved = TRUE; // Setto screenMoved a true non ricordo il perché, forse mi serviva altrove
  43.         float newPosition = bg.position.y - velocity; // velocity è un int
  44.                    
  45.         [bg setPosition:ccp(bg.position.x, newPosition)]; // muovo il bg
  46.                    
  47. }else{
  48.                
  49.     // Altrimenti muovo la sprite
  50.         screenMoved = FALSE;
  51.         [sprite setPosition:ccp(sprite.position.x, sprite.position.y + velocity)];
  52.                          
  53. }
Add Comment
Please, Sign In to add comment