この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
wiki:ue4:tips:500 [2015/03/28 05:20] step |
— (現在) | ||
|---|---|---|---|
| ライン 1: | ライン 1: | ||
| - | ====== C++/Actorクラスの作成 ====== | ||
| - | - 「コンテンツブラウザ」の「新規追加」から「新規C++ Class...」を選択。 | ||
| - | - 親クラスに「Actor」を選択して次へ。 | ||
| - | - 名前を「MyActor」として「クラスを作成」する。 | ||
| - | |||
| - | ===== コードの記述とコンパイル ===== | ||
| - | - 自動でVisualStudioが開くので、MyActor.h/cppを編集する。 | ||
| - | <code csharp> | ||
| - | // MyActor.h | ||
| - | class STDPROJECT_API AMyActor : public AActor | ||
| - | { | ||
| - | GENERATED_BODY() | ||
| - | private: | ||
| - | // 追加 | ||
| - | float m_fRunningTime; | ||
| - | } | ||
| - | </code> | ||
| - | |||
| - | |||
| - | <code csharp> | ||
| - | // MyActor.cpp | ||
| - | |||
| - | // 生成された時に一度だけ呼ばれる。 | ||
| - | void AMyActor::BeginPlay() | ||
| - | { | ||
| - | Super::BeginPlay(); | ||
| - | | ||
| - | } | ||
| - | |||
| - | // 毎フレーム呼ばれる。 | ||
| - | void AMyActor::Tick( float DeltaTime ) | ||
| - | { | ||
| - | Super::Tick( DeltaTime ); | ||
| - | |||
| - | FVector NewLocation = GetActorLocation(); | ||
| - | float DeltaHeight = (FMath::Sin(m_fRunningTime + DeltaTime) - FMath::Sin(m_fRunningTime)); | ||
| - | NewLocation.Z += DeltaHeight * 20.0f; | ||
| - | m_fRunningTime += DeltaTime; | ||
| - | SetActorLocation(NewLocation); | ||
| - | } | ||
| - | |||
| - | |||
| - | </code> | ||