• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Level Theme

B

Brett

Guest
I am creating a project that has themes for specific levels. These themes change the sprite of certain enemies and objects. I could code the theme into every enemy and object but that seems tedious. What I have been trying to do is have a theme object that when placed in a room will change every instance of a particular sprite into another. The problem with this is that it creates a ton of lag. If anyone has a good solution for this I would surely appreciate it.
 
M

Mahdarah

Guest
Could you show your code? Is it changing every single sprite every step?
 

TheouAegis

Member
Make a theme variable for each theme that is just a number. If it's easier for you, use enumerators.

For each object, put in its create event an array (maybe a 2d array) of all the sprites it will use in the same order as the themes. If you use a 2d array, make the left index the theme index.

Set the Sprites based on that array and the theme of the room.
 
B

Brett

Guest
@Mahdarah I used to have the code in a step event and here it is:
Code:
with obj_blockparent
{
    if collision_rectangle( view_xview, view_yview, view_xview + view_wview, view_yview + view_hview, id, 0, false)
    {
        if sprite_index == (spr_brick)
            sprite_index = spr_brick_und
        else if sprite_index == (spr_qblock)
            sprite_index = spr_qblock_und
        else if sprite_index == (spr_qblock_empty)
            sprite_index = spr_qblock_empty_und
        else if sprite_index == (spr_largeqblock)
            sprite_index = spr_largeqblock_und
    }
}
@TheouAegis I thought of doing something similar to that but since I have so many objects that need sprite changes I was wondering if a simpler solution was available.
 

TheouAegis

Member
Simpler: make all the arrays global so you only have as many arrays as sprite sets. Less memory load that way too.

You can get funky fresh by organizing the arrays the same order with same indices as the master sprites (easy to do in Studio), use the ids of the master sprites for the left index in the 2d arrays, so the themes are the subindexes, then replace the draw events with draw_sprite_ext passing the array as the sprite index.

draw_sprite_part(global.spr_themes[sprite_index, global.theme], -1, x, y, image_xscale,image_yscale, 0, -1, 1)

Or if you want an option that pisses off some of the people around here, organize all of your Sprites in order with the themes in order. You can either have all of your master sprites together and then all of a particular theme together and then all of the next theme together; how are you can have each Master Sprite followed by each themed Sprite with the order of the themes the same for each as her Sprite. Then you would set the Sprite index to some modification of the Sprite that you actually assigned.

100 master sprites Grouped:
sprite_index = spr_wolf + 100*theme

4 Themes grouped:
sprite_index = spr_wolf + theme

As you can see, keeping the themes close to the master Sprite is easier. This is easy to pull off in studio, but requires a bit of craftiness and older versions of game maker.

If you wanted to noob it, you could always just use the asset_get_index() function...
 
Top