有大神会写游戏虚拟摇杆吗?出个教程啊。自己绘制了一个,但是不
aide吧
全部回复
仅看楼主
level 6
有大神会写游戏虚拟摇杆吗?出个教程啊。自己绘制了一个,但是不会写逻辑啊。或者哪里有封装好的摇杆直接用吗?
2019年10月19日 16点10分 1
level 7
libgdx有
2019年10月19日 16点10分 2
level 8
2019年10月19日 22点10分 3
这个完全看不懂啊大哥。
2019年10月20日 02点10分
level 11
曾记得4年多前用js写过[滑稽],首先你需要实现可拖动按钮,另外,你看见的按钮和手指实际拖动的按钮不是同一个
2019年10月20日 03点10分 4
level 5
TouchPad类
2019年10月20日 14点10分 6
level 11
mport android.content.*;
import android.graphics.*;
import android.os.*;
import android.util.*;
import android.view.*;
public class MoveView extends View
{
public MoveView(Context c)
{
super(c);
p=new Paint();
p.setDither(true);
p.setAntiAlias(true);
}
int alpla=0;
boolean isdo=false;
double aa=0;
Paint p;
boolean cj=false;
float x,y;
onMoveListener o;
public MoveView(Context c,AttributeSet a)
{
super(c,a);
p=new Paint();
p.setDither(true);
p.setAntiAlias(true);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
// TODO: Implement this method
super.onSizeChanged(w, h, oldw, oldh);
x=getWidth()/2f;
y=getHeight()/2f;
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
isdo=true;
x=getWidth()/2f;
y=getHeight()/2f;
aa= Math.atan2( event.getX()-x,event.getY()-y)-Math.PI/2f;
if(o!=null)
o.start();
MoveView.this.invalidate();
if(alpla<250&!cj)
d(true);
else if(cj)
{
cj=false;
d(true);
}
break;
case MotionEvent.ACTION_MOVE:
isdo=true;
aa= Math.atan2( event.getX()-x,event.getY()-y)-Math.PI/2f;
if(o!=null)
o.move(aa);
MoveView.this.invalidate();
break;
case MotionEvent.ACTION_UP:
isdo=false;
x=getWidth()/2f;
y=getHeight()/2f;
MoveView.this.invalidate();
if(o!=null)
{
o.stop();
}
if(cj)
cj=false;
d(false);
break;
}
return true;
}
final Handler myHandler = new Handler() {
public void handleMessage(Message msg) {
MoveView.this.invalidate();
}
};
public void d(final boolean b)
{
new Thread(new Runnable(){
@Override
public void run()
{
try
{
Thread.sleep(80);
}
catch (Exception e)
{}
if(b)
{
cj=true;
while(alpla<240&cj)
{
try
{
Thread.sleep(40);
alpla+=20;
2019年10月20日 16点10分 10
level 11
myHandler.sendMessage(myHandler.obtainMessage(22,"消息内容"));
}
catch (Exception e)
{}
}
if(cj)
cj=false;
}
}
}).start();
}
public void setonMoveLisener(onMoveListener i)
{
o=i;
}
@Override
protected void onDraw(Canvas canvas)
{
p.setColor(Color.GRAY);
p.setAlpha(30+(int)(alpla*0.8f));
p.setStyle(Paint.Style.FILL);
canvas.drawCircle(getWidth()/2f,getHeight()/2f,getWidth()/2f,p);
p.setColor(Color.BLUE);
p.setAlpha(30+(int)(alpla*0.8f));
if(isdo)
canvas.drawCircle(getWidth()/2f
+3
*getWidth()/8f*(float)Math.cos(aa),getHeight()/2f-3*getWidth()/8f*(float)Math.sin(aa),getWidth()/8f,p);
}
public interface onMoveListener
{
public void start();
public void move(double a);
public void stop();
}
}
2019年10月20日 16点10分 11
level 11
我前几天随便写的一个游戏遥感
2019年10月20日 16点10分 12
谢谢,直接看代码不是很懂,因为涉及到三角函数等数学知识,我确实不知道如何实现逻辑。 另外请教一下:做游戏的地图,如果用SurfaceView如何实现按行走按钮地图开始滚动,松开按钮地图停止滚动呢?是通过控制线程的暂停和重启吗?
2019年10月21日 01点10分
额在绘画函数里面对canvas处理啊,canvas.translate(-x,-y),X和y是地图滚动的偏移位置
2019年10月21日 04点10分
要实现按下按扭滚动,放开按扭停止滚动,你可以在自定义surfaceview里面定义一个滚动速度 int VX=0,Vy=0; 在绘画函数里面设置地图的偏移位置x+=VX;y+=Vy;
2019年10月21日 04点10分
控制遥感的话可以用我上面发的那个Moveview实现
2019年10月21日 04点10分
level 11
2019年10月21日 04点10分 13
level 7
怪物猎人p3
2019年10月21日 10点10分 14
1