0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ストワで始めるLua 第11回 まっぷ

Posted at

タッチしたらそこにマップが移動するやつ

map

isTouching=false
centerPosition={}
touchPosition={}
function onTick()
	local rangeScale,height,width,touchX,touchY,isTouch
	
	rangeScale=input.getNumber(8)
	zoom=rangeScale/1000 --display range
	gpsPosition={x=input.getNumber(9),y=input.getNumber(10)} --position of vehicle
	
	--touch screen
	isTouch=input.getBool(1) 
	if isTouch and not(isTouching) then
		width=input.getNumber(1)
		height=input.getNumber(2)
		touchX=input.getNumber(3)
		touchY=input.getNumber(4)
		isTouching=true
		touchPosition.x,touchPosition.y=map.screenToMap(centerPosition.x, centerPosition.y, zoom, width, height, touchX, touchY) --world position of touch
	end

	--Center coordinates
	if next(touchPosition) then
		centerPosition=touchPosition
	else
		centerPosition=gpsPosition
	end

	--flag
	if not(isTouch) and isTouching then
		isTouching=false
	end

	isReset=input.getBool(2)
	if isReset then
		touchPosition={}
	end
end

function onDraw()
    --position = World XY , pixel = Display XY
	local width,height
	local gpsPixel={}

	width=screen.getWidth()
	height=screen.getHeight()
	screen.drawMap(centerPosition.x, centerPosition.y, zoom) --drawring map

	gpsPixel.x,gpsPixel.y=map.mapToScreen(centerPosition.x, centerPosition.y, zoom, width, height, gpsPosition.x, gpsPosition.y) --Location of the vehicle
	screen.drawCircle(gpsPixel.x,gpsPixel.y,5)
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?