質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

677閲覧

dxlib アニメーションクリップをラップするイテレーターを作りたい

退会済みユーザー

退会済みユーザー

総合スコア0

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2019/08/11 13:21

編集2019/08/11 14:13

Animationクラスでアニメーションするための 走っている状態を表すイテレータをラップするといいと言われたのですが どのようにイテレーターを作りそれをどう使ったらいいか教えてくれますでしょうか?

1,2,3,1,2といった感じにサイクルさせたいのですが
ちなみに1,2,3の番号は走っているときのアニメーションです。

Player.cpp

1 2 3#include <iostream> 4#include <fstream> 5#include "Input.h" 6#include "Player.h" 7#include "DxLib.h" 8#include "Map.h" 9#include "Fps.h" 10 11#define MOVE_SPD 5 12 13/*コンストラクタ*/ 14Player::Player(const char* str, int xx, int yy) 15{ 16 LoadDivGraph(str,7,7,1,64,64,g_handle); 17 18 19 20} 21 22/*計算更新*/ 23void Player::Update() 24{ 25 frame.Update(); 26 input_key(); 27 //gravity(); 28 29 30} 31 32 33/*描画更新*/ 34void Player::Draw_Update() 35{ 36 37 38 39 if ( key == -1) 40 { 41 //DrawTurnGraph(gPos_x(), gPos_y(), g_handle[0], true); 42 DrawTurnGraph(pos->gPos_x(), pos->gPos_y(), g_handle[AnimeClip->setClip()], true); 43 44 } 45 /*右→*/ 46 if (key == 1) 47 { 48 DrawGraph(pos->gPos_x(), pos->gPos_y(), g_handle[AnimeClip->setClip()], true); 49 } 50 51 AnimeClip->Draw_Update(); 52 53 54 frame.Wait(); 55} 56 57/*キー入力*/ 58void Player::input_key() 59{ 60 if (keybord(KEY_INPUT_LEFT) > 0)//← 61 { 62 63 key = -1; 64 AnimeClip->Update_changeAnime(anime_s::ewalk,key); 65 pos->sPos_x(-MOVE_SPD); 66 67 68 }else if (keybord(KEY_INPUT_RIGHT) > 0)//→ 69 { 70 71 key = 1; 72 AnimeClip->Update_changeAnime(anime_s::ewalk,key); 73 74 pos->sPos_x(+MOVE_SPD); 75 76 }else if (keybord(KEY_INPUT_UP) > 0)//上 77 { 78 pos->sPos_y(+MOVE_SPD); 79 80 }else if (keybord(KEY_INPUT_DOWN) > 0)//下 81 { 82 pos->sPos_y(-MOVE_SPD); 83 } 84 85 else if (keybord(KEY_INPUT_SPACE) > 0)//ジャンプ 86 { 87 AnimeClip->Update_changeAnime(anime_s::ejump); 88 89 } 90 else//何も押していない時 91 { 92 AnimeClip->Update_changeAnime(anime_s::ewait); 93 94 } 95 96 97 98 jump_up(); 99 gravity(); 100 101} 102 103/*************************************描画 アニメーション管理**************************************/ 104 105void Player::Animation::Update() 106{ 107 f->Update(); 108#define ANI_SPD 15 109 110 if (f->gframe() % ANI_SPD == 0) 111 { 112 113 114 } 115 116 117 118 119#undef ANIME_SPD 120} 121 122void Player::Animation::Draw_Update() 123{ 124 f->Wait(); 125} 126 127void Player::Animation::Update_changeAnime(anime_s clip, int key)//keyは向き -1が左側 128{ 129 state = clip; 130 isReverse = key; 131} 132 133void Player::Animation::Update_changeAnime(anime_s clip)//keyは向き -1が左側 134{ 135 state = clip; 136} 137 138 139int Player::Animation::setClip() 140{ 141 return Clip; 142} 143 144 145 146/****************************************************************************************/ 147 148 149 150/*ジャンプ管理*/ 151void Player::jump_up() 152{ 153 154} 155 156 157/*重力効果*/ 158void Player::gravity()//ジャンプしてるかどうかと当たり判定を比較 159{ 160 if (Map::Collision::under_col(pos->refgPos_x(), pos->refgPos_y()) == false) 161 { 162 163 } 164 165 166} 167 168/*座標の取得と設定*/ 169void Player::Position::sPos_x(int &xx)//加算 170{ 171 x += xx; 172} 173 174void Player::Position::sPos_y(int &yy)//加算 175{ 176 y += -yy; 177} 178 179void Player::Position::sPos_x(int xx) 180{ 181 x += xx; 182 183} 184 185void Player::Position::sPos_y(int yy) 186{ 187 y += -yy; 188 189} 190 191int Player::Position::gPos_x() 192{ 193 return x; 194} 195 196int Player::Position::gPos_y() 197{ 198 return y; 199} 200 201int& Player::Position::refgPos_x() 202{ 203 return x; 204} 205int& Player::Position::refgPos_y() 206{ 207 return y; 208} 209

Player.h

1#ifndef ___PLAYER_H 2#define ___PLAYER_H 3#include <iostream> 4#include <fstream> 5using namespace std; 6//#include "Chr.h" 7#include "Map.h" 8#include "Fps.h" 9 10#define JUMP_RANGE 30 11class Player 12{ 13private: 14 15 class Position 16 { 17 int x; 18 int y; 19 public: 20 Position() :x(0), y(0) 21 { 22 23 } 24 25 26 /*座標の取得と設定 Y軸は反転処理が入っている。上がプラスに*/ 27 void sPos_x(int xx); 28 void sPos_y(int yy); 29 30 void sPos_x(int &xx); 31 void sPos_y(int &yy); 32 33 int gPos_x(); 34 int gPos_y(); 35 36 int& refgPos_x(); 37 int& refgPos_y(); 38 39 40 }; 41 42 43 enum class anime_s//アニメクリップ列挙体 44 { 45 ewait, 46 ewalk, 47 ejump, 48 egame_over, 49 50 }; 51 52 class Animation 53 { 54 private: 55 Fps *f = new Fps(); 56 anime_s state; 57 //unsigned int isReverse; 58 int isReverse;//向き管理 59 int Clip;//選択中のアニメ番号 60 61 62 public: 63 64 Animation(anime_s ani) 65 :state(ani),isReverse(1),Clip(0)//クリップの初期を設定 66 { 67 68 } 69 70 void Update();//アニメ切り替えキー入力監視 71 72 void Update_changeAnime(anime_s clip,int key);//keyは向き -1が左側 73 void Update_changeAnime(anime_s clip);//keyは向き -1が左側 74 75 int setClip(); 76 77 78 79 void Draw_Update(); 80 81 82 83 }; 84 85 86 87 int g_handle[8];//画像格納ハンドル 88 89 90 void input_key();//キー入力 91 void gravity();//重力落下 92 void jump_up();//ジャンプ上昇 93 94 95 Position *pos = new Position();//座標クラス 96 Animation *AnimeClip = new Animation(anime_s::ewait);//アニメーション管理クラス 97 98 99 100 101 102 int Nanime = 0; 103 int anime_f = 0; 104 105 106 107 int key = 1;//向き管理 108 109 //int Animation(); 110 111public: 112 Fps frame; 113 114 Player(const char* str,int xx,int yy); 115 116 117 void Update(); 118 void Draw_Update(); 119 120}; 121 122#endif

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

とらえず整数値で切り替えることにしました。
急な問題ではなおようなので締め切ります。

投稿2019/08/11 19:43

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問