Fix a scale bug (default should be 1.0), add tilemap release function
This commit is contained in:
@@ -20,6 +20,7 @@ akerr_ErrorContext *akgl_actor_initialize(akgl_Actor *obj, char *name)
|
||||
memset(obj, 0x00, sizeof(akgl_Actor));
|
||||
strncpy((char *)obj->name, name, AKGL_ACTOR_MAX_NAME_LENGTH);
|
||||
obj->curSpriteReversing = false;
|
||||
obj->scale = 1.0;
|
||||
obj->movement_controls_face = true;
|
||||
|
||||
obj->updatefunc = &akgl_actor_update;
|
||||
|
||||
@@ -198,5 +198,6 @@ akerr_ErrorContext *akgl_character_load_json(char *filename)
|
||||
}
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
SDL_Log("Character %s loaded from %s", obj->name, filename);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ akerr_ErrorContext *akgl_tilemap_load(char *fname, akgl_Tilemap *dest)
|
||||
// How much bigger is the foreground vs the vanishing point?
|
||||
// if vanishing is height 16, and foreground is height 32, that is a 2x scale difference
|
||||
dest->p_scale = (dest->p_foreground_h / dest->p_vanishing_h);
|
||||
SDL_Log("Map perspective scale is (%f/%f) = %f", dest->p_foreground_h, dest->p_vanishing_h, dest->p_scale);
|
||||
SDL_Log("Map perspective scale is (%d/%d) = %f", dest->p_foreground_h, dest->p_vanishing_h, dest->p_scale);
|
||||
// Sprites are always size 1.0 at the foreground, so how much do we need to
|
||||
// scale them for every pixel above foreground_y before they reach vanishing_y?
|
||||
// If vanishing is at 320 and foreground is at 640, that is a 320 line difference
|
||||
@@ -646,11 +646,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, a
|
||||
FAIL_ZERO_RETURN(e, map, AKERR_NULLPOINTER, "NULL map");
|
||||
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "NULL actor");
|
||||
|
||||
SDL_Log("Map foreground is at %d, vanishes at %d, actor %p is at %f",
|
||||
map->p_foreground_y,
|
||||
map->p_vanishing_y,
|
||||
actor,
|
||||
actor->y);
|
||||
if ( actor->y <= map->p_vanishing_y ) {
|
||||
actor->scale = 1.0 / map->p_scale;
|
||||
} else if ( actor->y >= map->p_foreground_y ) {
|
||||
@@ -658,5 +653,26 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, a
|
||||
} else {
|
||||
actor->scale = 1.0 - (map->p_rate * (map->p_foreground_y - actor->y));
|
||||
}
|
||||
SDL_Log("Actor %p scaled to %f", actor, actor->scale);
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_release(akgl_Tilemap *dest)
|
||||
{
|
||||
// Release all tileset textures
|
||||
// Release all image layer textures
|
||||
// Memset to zero
|
||||
PREPARE_ERROR(e);
|
||||
FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "NULL map");
|
||||
int i = 0;
|
||||
for ( i = 0; i < AKGL_TILEMAP_MAX_TILESETS; i++ ) {
|
||||
if ( dest->tilesets[i].texture != NULL ) {
|
||||
SDL_DestroyTexture(dest->tilesets[i].texture);
|
||||
}
|
||||
}
|
||||
for ( i = 0; i < AKGL_TILEMAP_MAX_LAYERS; i++ ) {
|
||||
if ( dest->layers[i].texture != NULL ) {
|
||||
SDL_DestroyTexture(dest->tilesets[i].texture);
|
||||
}
|
||||
}
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user