- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Android 游戏中,子弹出现的速度太快而且彼此距离太近!我怎样才能调整他们的行为?这是 a picture of it
动画对象类
package game.objects.animation;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
abstract class AnimatedObject {
protected Bitmap bitmap; // the animation sequence
protected Rect sourceRect; // the rectangle to be drawn from the animation bitmap
private int frameNr; // number of frames in animation
private int currentFrame; // the current frame
private long frameTicker; // the time of the last frame update
private int framePeriod; // milliseconds between each frame (1000/fps)
protected int spriteWidth; // the width of the sprite to calculate the cut out rectangle
protected int spriteHeight; // the height of the sprite
private int x; // the X coordinate of the object (top left of the image)
private int y; // the Y coordinate of the object (top left of the image)
public boolean exist;
public AnimatedObject(Bitmap bitmap, int x, int y, int width, int height, int fps, int frameCount) {
this.bitmap = bitmap;
this.x = x;
this.y = y;
currentFrame = 0;
frameNr = frameCount;
spriteWidth = bitmap.getWidth()/frameCount;
spriteHeight = bitmap.getHeight();
sourceRect = new Rect(0, 0, spriteWidth, spriteHeight);
framePeriod = 1000/ fps;
frameTicker = 0l;
exist = true;
}
private void update(long gameTime) {
//if (gameTime > frameTicker + framePeriod) {
//frameTicker = gameTime;
// increment the frame
currentFrame++;
if (currentFrame >= frameNr) {
currentFrame = 0;
}
//}
// define the rectangle to cut out sprite
this.sourceRect.left = currentFrame * spriteWidth;
this.sourceRect.right = this.sourceRect.left + spriteWidth;
}
public void animate(){
if (currentFrame <= frameNr){
update(0);
}
}
public void draw(Canvas canvas) {
// where to draw the sprite
Rect destRect = new Rect(getX(), getY(), getX() + spriteWidth, getY() + spriteHeight);
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
}
public boolean checkCollisons(Rect another)
{
return Rect.intersects(new Rect(getX(), getY(), getX() + spriteWidth, getY() + spriteHeight), another);
}
public void destroy()
{
exist = false;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public Rect getSourceRect() {
return sourceRect;
}
public void setSourceRect(Rect sourceRect) {
this.sourceRect = sourceRect;
}
public int getFrameNr() {
return frameNr;
}
public void setFrameNr(int frameNr) {
this.frameNr = frameNr;
}
public int getCurrentFrame() {
return currentFrame;
}
public void setCurrentFrame(int currentFrame) {
this.currentFrame = currentFrame;
}
public int getFramePeriod() {
return framePeriod;
}
public void setFramePeriod(int framePeriod) {
this.framePeriod = framePeriod;
}
public int getSpriteWidth() {
return spriteWidth;
}
public void setSpriteWidth(int spriteWidth) {
this.spriteWidth = spriteWidth;
}
public int getSpriteHeight() {
return spriteHeight;
}
public void setSpriteHeight(int spriteHeight) {
this.spriteHeight = spriteHeight;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
子弹类
package game.objects.animation;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
public class Bullet extends AnimatedObject{
private int mSpeedY;
public Bullet(Bitmap bitmap, int x, int y, int width, int height, int fps,
int frameCount) {
super(bitmap, x, y, width, height, fps, frameCount);
// TODO Auto-generated constructor stub
mSpeedY = 10;
setFramePeriod(5000/ fps);
}
public void draw(Canvas canvas) {
// where to draw the sprite
setY(getY() - mSpeedY);
Rect destRect = new Rect(getX(), getY(), getX() + spriteWidth, getY() + spriteHeight);
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
}
public void animate()//анимация движения
{
super.animate();
setY(getY() - mSpeedY);
// checkBorders(rect);
}
}
主游戏循环的类或它如何用英语调用(我不是母语人士,抱歉)
package game.view;
import game.main.R;
import game.objects.animation.Bullet;
import game.objects.animation.Explosion;
import game.objects.animation.ScrollingElement;
import game.objectsmain.Player;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
public class ViewManager extends Thread
{
private static final int FIELD_WIDTH = 480;
private static final int FIELD_HEIGHT = 800;
private static final int dist = 100;
public int touchedX, touchedY;
/** Область, на которой будем рисовать */
private SurfaceHolder mSurfaceHolder;
/** Состояние потока (выполняется или нет. Нужно, чтобы было удобнее прибивать поток, когда потребуется) */
private boolean mRunning;
/** Стили рисования */
private Paint mPaint;
/** The drawable to use as the background of the animation canvas */
private Bitmap mBackgroundImage;
private Bitmap mLinesImage;
private Bitmap mExplosionImage;
private Bitmap mBulletImage;
private Drawable mPlayerImage;
private ArrayList<ScrollingElement> mScrollEls = new ArrayList<ScrollingElement>();
private ArrayList<Bullet> mBullets = new ArrayList<Bullet>();
private ArrayList<Explosion> mBang = new ArrayList<Explosion>();
private Player mHero;
// desired fps
private final static int MAX_FPS = 50;
// maximum number of frames to be skipped
private final static int MAX_FRAME_SKIPS = 5;
// the frame period
private final static int FRAME_PERIOD = 1000 / MAX_FPS;
private Explosion mBoom;//объект класса взрыв
public ViewManager(SurfaceHolder surfaceHolder, Context context)
{
mSurfaceHolder = surfaceHolder;
mRunning = false;
Resources res = context.getResources();
mExplosionImage = BitmapFactory.decodeResource(res, R.drawable.explosion);
mBackgroundImage = BitmapFactory.decodeResource(res, R.drawable.bckgr1);
mLinesImage = BitmapFactory.decodeResource(res, R.drawable.lines3);
mPlayerImage = res.getDrawable(android.R.drawable.star_big_on);
mBulletImage = BitmapFactory.decodeResource(res, R.drawable.bullet3);
InitElements(res);
mHero = new Player(mPlayerImage, 240, 400);
mBoom = new Explosion(mExplosionImage, 200, 500, 64, 64, 7, 7);
}
/**
* Задание состояния потока
* @param running
*/
public void setRunning(boolean running)
{
mRunning = running;
}
public void run()
{
while (mRunning)
{
Canvas canvas = null;
try
{
// подготовка Canvas-а
canvas = mSurfaceHolder.lockCanvas();
synchronized (mSurfaceHolder)
{
mHero.update();
// собственно рисование
addBullets();
doDraw(canvas);
//mImage.draw(canvas);
synchronized (mBullets) {
for (Bullet bullet: mBullets) {
//explosion if collides
if(bullet.checkCollisons(mHero.getRect()))
{
mBang.add(new Explosion(mExplosionImage, mHero.getXCoord(), mHero.getYCoord(), 64, 64, 7, 7));
mBang.get(0).draw(canvas);
mBang.get(0).animate();
};
//bullet.animate();
}
}
}
}
catch (Exception e) { }
finally
{
if (canvas != null)
{
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
public boolean gettouch = false;//in class with surface golder there are touchlistener works with this variable
private void doDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(mBackgroundImage, 0, 0, null);
//отрисовка анимации
synchronized (mScrollEls) {
for (ScrollingElement element: mScrollEls) {
element.doDraw(canvas, mLinesImage);
element.animate(mLinesImage);
}
}
mHero.draw(canvas);
//mBoom.draw(canvas);
/*if(gettouch == true){
mBoom.draw(canvas);
mBoom.getCurrentFrame();
mBoom.animate();
}*/
synchronized (mBullets) {
for (Bullet bullet: mBullets) {
bullet.animate();
bullet.draw(canvas);
//bullet.animate();
}
}
}
private void addBullets()//элементы для анимации заднего плана
{
if(gettouch)
{
mBullets.add(new Bullet(mBulletImage, touchedX, touchedY, 22, 52, 3, 3));
}
}
public boolean touched(boolean x)
{
return x;
}
}
最佳答案
您每帧都在添加项目符号。相反,仅每隔几帧或每隔一段时间添加一次。例如,如果您想按时间间隔执行此操作,请在添加项目符号之前检查当前时间是否与上次添加项目符号加上时间间隔相同。
// fire every 500 ms
private static long INTERVAL = 500;
private long mLastFiredTime;
private void addBullets()//элементы для анимации заднего плана
{
if(gettouch)
{
long now = System.currentTimeMillis();
if (now > mLastFiredTime + INTERVAL) {
mBullets.add(new Bullet(mBulletImage, touchedX, touchedY, 22, 52, 3, 3));
mLastFiredTime = now;
}
}
}
关于java - 子弹太多(ver 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8249238/
我有一个使用 PHP 和 MariaDB 10.3 的小型大型数据库应用程序。 我有大约 100 个表,大约有 3,000 个 View 。 当超过 1,000 个 View 时,数据库架构就会崩溃并
parsing "\(|.*?)|)" - Too many )'s. 写这个的时候我收到这个错误... private static Regex resourceTextsREGEX = new
我有一个Powershell脚本,它会生成一个包含数据的JSON文件。 我对此文件有问题。它产生两倍的“\”! 你知道我该怎么解决吗? 这是我的生成JSON文件的代码: [ordered]@{ pcn
我不确定为什么会收到此错误,我在不同点使用 str.join() 和 os.path.join()在脚本中,这是原因吗? 使用os.path.join: from os.path import get
一段时间后,在我的应用程序中,似乎出现了一个大问题。有一个来自 Box2D 的 b2Bodys 的构建。我确实在我的应用程序中使用了一些 b2Body 来进行碰撞,但我会说屏幕上一次最多有 10 个。
我正在创建一个包含 6 种不同问题类型的简单数学程序。我想让程序随机显示6种类型中的一种,但有些问题应该出现得比较频繁。我使用加权数组,但从加权数组中选择问题类型后,如果不在 if 语句中使用 10
我想构建一个包含大约 400 个单元的 Controller ,4 列,每列 100 个单元。每个单元格都必须被绘制并响应鼠标事件。这个会不会太重了?我应该为每个单元使用另一种方法,如 CALayer
我是 Haskell 的新手,在编写小程序时,我通常会使用太多的 where 子句来检查函数中的许多内容,因此编写 where 子句是一种很好的做法,或者还有其他好的替代方法吗? 例如,在下面的代码中
我有一个 index.js,其中包含一些导出,每个导出仅包含一个函数。我尝试一次部署其中的几个,CLI 给我以下错误; Error: Too many arguments. Run firebase
我在正则表达式上挣扎了几个小时,似乎没有找到最后一点解决方案。我基本上是逐行解析 C 头文件以查找变量。 以下是我可能遇到的需要传递正则表达式的行的情况: //#define variable_nam
我有一个 html 表单,大约有 1500 个输入字段*(文本或隐藏)。form.action 是 POST 并且每个输入字段都有一个唯一的名称(没有 name=foo[])。 每当我在提交表单后尝试
我很困惑 一劳永逸 VS 添加引用(/net 选项卡)说 dll 的 gac 在这里: 我发现这个包含 GAC 的文件夹:(附注:为什么有 3 个 Gac 类型?) 还有这个包含 GAC 的文件夹:
我有一个实现Comparable的对象列表。 我想对此列表进行排序,这就是我使用Comparable的原因。 每个对象都有一个字段 weight,它由另外 3 个成员 int 变量组成。 对于具有最大
在我们的系统中,有多个“站点”通过 WCF 相互通信。每个站点通过 NetTCP 绑定(bind)公开约 20 个接口(interface)。 当一个站点使用对等站点的接口(interface)时,它
我已经从 http://boost.teeks99.com/ 下载了 boost 1.58.0(预编译,x86,VC 12.0)并安装到C:\local\boost_1_58_0(我也试过自己用msv
所以...我有一个查询,该查询返回在我的网站上使用相同的电子邮件地址、密码和其他信息创建的用户帐户(是的,实现不好,不要问)。它通过从另一个程序获取用户 ID 来实现这一点。 我的 SQL 是 SEL
我知道这是一个有点菜鸟的问题,但我只是想问一下,如果我有太多 Controller ,这是好事还是坏事。假设我有一个网络应用程序,它有大约 12 个 View 。每个 View 都有自己的 Contr
我认为我的项目做了一些可笑的错误。我正在制作一个项目,基本上是一组 View Controller ,其中一些 Controller 上有视频,其他 Controller 上有图像。我创建了一个模型,
嘿,我正在创建一个电子商店并显示类别树和所有产品及其多种价格变化,我制作了 150 多个 mysql_query("SELECT ..."); 在一页上查询。 (如果我计算“while”循环)。 是不
我在 JS 方面遇到了问题。我正在尝试制作按类型排序的三个成分列表(用于酿造药水),所有这些都是标签内的复选框。 您应该选择(选中)三个列表中每一个的一个元素才能酿造一剂药水。如果您选择正确的成分并按
我是一名优秀的程序员,十分优秀!