Monday, June 14, 2021

【GAMEMAKER】8 directions all in 1 sprite

 Information about object: obj_direction

Sprite: dirSprite
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

xp = x
yp = y

dir = 0
image = 0
im_sp = .1
Step Event:
execute code:

if keyboard_check(vk_right) { x += 4 }
if keyboard_check(vk_up) { y -= 4 }
if keyboard_check(vk_left) { x -= 4 }
if keyboard_check(vk_down) { y += 4 }

if xp != x || yp != y { dir = point_direction(xp,yp,x,y) }

xp = x
yp = y

image += im_sp
if image >= 2 /*# of subimages*/ then image = 0

image_index = floor(dir / 45)*2 + floor(image)

No comments:

Post a Comment