ds_grid旋转函数
原文:How to Rotate / Mirror / Flip a ds_grid in GameMaker
镜像翻转
(replace new_grid and old_grid with the ds_grid's you want to change)
var size_h = ds_grid_width(old_grid)
var size_v = ds_grid_height(old_grid)
ds_grid_resize(new_grid,size_h,size_v)
for (var i = 0; i < size_h; ++i) {
for (var j = 0; j < size_v; ++j) {
new_grid[# i,j] = old_grid[# size_h-i-1, j]
}
}
垂直翻转
(replace new_grid and old_grid with the ds_grid's you want to change)
var size_h = ds_grid_width(old_grid)
var size_v = ds_grid_height(old_grid)
ds_grid_resize(new_grid,size_h,size_v)
for (var i = 0; i < size_h; ++i) {
for (var j = 0; j < size_v; ++j) {
new_grid[# i,j] = old_grid[# i, size_v-j-1]
}
}
顺时针 90 度旋转
(replace new_grid and old_grid with the ds_grid's you want to change)
var size_h = ds_grid_height(old_grid)
var size_v = ds_grid_width(old_grid)
ds_grid_resize(new_grid,size_h,size_v)
for (var i = 0; i < size_h; ++i) {
for (var j = 0; j < size_v; ++j) {
new_grid[# i,j] = old_grid[# j, size_h-i-1]
}
}
逆时针 90 度旋转
(replace new_grid and old_grid with the ds_grid's you want to change)
var size_h = ds_grid_height(old_grid)
var size_v = ds_grid_width(old_grid)
ds_grid_resize(new_grid,size_h,size_v)
for (var i = 0; i < size_h; ++i) {
for (var j = 0; j < size_v; ++j) {
new_grid[# i,j] = old_grid[# size_v-j-1, i]
}
}
180 度旋转
(replace new_grid and old_grid with the ds_grid's you want to change)
var size_h = ds_grid_width(old_grid)
var size_v = ds_grid_height(old_grid)
ds_grid_resize(new_grid,size_h,size_v)
for (var i = 0; i < size_h; ++i) {
for (var j = 0; j < size_v; ++j) {
new_grid[# i,j] = old_grid[# size_h-i-1, size_v-j-1]
}
}
Comments