質問編集履歴

1

Spriteの追加

2017/08/13 11:49

投稿

Alpa
Alpa

スコア80

test CHANGED
File without changes
test CHANGED
@@ -123,3 +123,93 @@
123
123
  (引数の不一致: BufferedImageをStringに変換できません:)
124
124
 
125
125
  ```
126
+
127
+
128
+
129
+ Spriteのコード↓
130
+
131
+
132
+
133
+ ```JAVA
134
+
135
+ package home.tugame;
136
+
137
+
138
+
139
+ import javax.swing.*;
140
+
141
+ import java.awt.*;
142
+
143
+ import java.awt.image.*;
144
+
145
+ import java.awt.event.*;
146
+
147
+ import java.io.*;
148
+
149
+ import javax.imageio.*;
150
+
151
+
152
+
153
+ public class Sprite
154
+
155
+ {
156
+
157
+ public BufferedImage m_bi;
158
+
159
+ public int m_x=0;
160
+
161
+ public int m_y=0;
162
+
163
+
164
+
165
+ public Sprite(BufferedImage bi)
166
+
167
+ {
168
+
169
+ m_bi=bi;
170
+
171
+ }
172
+
173
+
174
+
175
+ public Sprite(File file,int x,int y,int w,int h)throws IOException
176
+
177
+ {
178
+
179
+ BufferedImage bi=ImageIO.read(file);
180
+
181
+ m_bi=bi.getSubimage(x,y,w,h);
182
+
183
+ }
184
+
185
+
186
+
187
+ public Sprite(String fname,int x,int y,int w,int h)throws IOException
188
+
189
+ {
190
+
191
+
192
+
193
+ BufferedImage bi=ImageIO.read(new File (fname));
194
+
195
+ m_bi=bi.getSubimage(x,y,w,h);
196
+
197
+
198
+
199
+ }
200
+
201
+
202
+
203
+ public void draw(Graphics g)
204
+
205
+ {
206
+
207
+ g.drawImage(m_bi,m_x,m_y,null);
208
+
209
+ }
210
+
211
+
212
+
213
+ }
214
+
215
+ ```