Loadsprite Code Help

Aerisetta

Active member
Hi,

I have a feature I want to add to CRxTRDude's Story System. I want to make the image load 10 pixels to the left (or right, doesn't matter) to create a screen shake effect.

This might be very complex, but I'm hoping it may be easier than I thought:

_back is the command that makes it load an image.
Code:
    else if(name=="_back"){
        if (dir){
            if(message != NULL()){
                setindexedvar(story_back, loadsprite("data/story/bgs/"+message));
                setindexedvar(story_backfile, back);
            }else shutdown(1,"STORY: _back 1 is empty. Check your dialog file.\n\n"); 
        }else{
            setindexedvar(story_back, "_");
            setindexedvar(story_backfile, "_");
        }
        filestreamnextline(filenumber);
        updateframe(self,0);                 
    }

I created this _back1 to load the image to the side, it successfully loads the image when I enter the _back1 command. However, I don't know how to write the code to tell the image to move 10 pixels to the side. ^_^;;;

Any help would be greatly appreciated.

Code:
    else if(name=="_back1"){
        if (dir){
            if(message != NULL()){
                setindexedvar(story_back, loadsprite("data/story/bgs/"+message));
                setindexedvar(story_backfile, back);
            }else shutdown(1,"STORY: _back 1 is empty. Check your dialog file.\n\n"); 
        }else{
            setindexedvar(story_back, "_");
            setindexedvar(story_backfile, "_");
        }
        filestreamnextline(filenumber);
        updateframe(self,0);                 
    }
 
Last edited:
@Aerisetta

Usually the function "loadsprite" works in conjunction with the "drawsprite", in which you can freely adjust the position where the loaded sprite will be drawn.

You need to put it in some events like ondraw / updated.c / level update in order to draw the sprite consistently. Other events like "entity update" events may cause the image to blink sometimes, I suggest to avoid them.

C:
if(getlocalvar("image") == NULL()) //First, load a image and save into a variable if NULL()
{
    setlocalvar("image", loadsprite("data/sprites/image.png"));
}
else //And then, draw the previously saved image if not NULL()
{
    drawsprite(getlocalvar("image", x_position, y_position, z_layer);
}
 
Back
Top Bottom