殭屍移動效果

2021-07-06 08:01:41 字數 2055 閱讀 3329

從本文開始,將以「植物大戰殭屍」遊戲為參考,練習uiview的使用。

首先從殭屍的移動效果開始。殭屍如下所示:

「殭屍」作為乙個特殊的種類,我們需要先幫它們建立「模型」。把殭屍們的共有特徵封裝起來,編寫乙個介面:

#import @inte***ce trzomb : uiimageview //繼承自uiimageview控制項

@property (nonatomic)int count;//殭屍的序號,用於選擇中的殭屍(由8只殭屍連成的圖)

@property (nonatomic, strong)uiimage *zombimage;//殭屍

@property (nonatomic)float speed;//殭屍速度

@end

#import "trzomb.h"

@implementation trzomb

/* * 初始化方法

*/- (id)initwithframe:(cgrect)frame

return self;

}-(void)animation:(nstimer *)timer}/*

// only override drawrect: if you perform custom drawing.

// an empty implementation adversely affects performance during animation.

- (void)drawrect:(cgrect)rect

*/- (void)dealloc

@end

「殭屍」先生的介面已經完成了,下面可以開發第一台機器來製造最弱的殭屍雜兵了(也就是第一幅圖的殭屍),炮灰製造者

#import "trzomb.h"

@inte***ce trzomba : trzomb //毫無疑問的繼承殭屍特徵

@end

#import "trzomba.h"

@implementation trzomba

/* * 初始化方法

*/- (id)initwithframe:(cgrect)frame

return self;}/*

// only override drawrect: if you perform custom drawing.

// an empty implementation adversely affects performance during animation.

- (void)drawrect:(cgrect)rect

*/@end

ok,其餘的殭屍也是用類似的製造機器。殭屍大軍準備集結了

#import "trviewcontroller.h"

#import "trzomba.h"

#import "trzombb.h"

#import "trzombc.h"

#import "trzombd.h"

@inte***ce trviewcontroller ()

@property (nonatomic)int count;

@end

@implementation trviewcontroller

- (void)viewdidload

/* * 製造殭屍流水線

*/-(void)addzomb

//量產殭屍寬60,高120,從座標x:568,y:0~259處發起攻擊

zomb.frame = cgrectmake(568,arc4random()%260, 60, 120);

[self.view addsubview:zomb];//把殭屍投入戰場

}- (void)didreceivememorywarning

@end

背景移動視差效果

我們在遊戲中有時會遇到 兩層背景的情況,要離我們遠的背景移動比較慢,近的比較快,如果不想自己寫寫兩層背景,我們可以利用引擎自帶的視差節點來做 auto sprite3 sprite create helloworld.png sprite3 setanchorpoint point 0,0 auto...

移動端彈性效果

布局一 定義頁面整體高度為100 然後使用 position absolute 布局可解決 header 彈性滾動區域 footer html,body wrap header,footer header footer main 布局二 定義頁面整體高度為100 然後使用 display flex ...

移動端輪播效果

一 涉及知識點 1.touchstart touchmove touchend 2.觸控引數,事件e e.touches 螢幕中所有手勢列表 e.touches 0 獲取第乙個手勢,是乙個json物件 屬性有pagex,pagey.用於touchstart,touchmove事件中 e.change...