Jump to content


Photo

Externally Loading Files


  • Please log in to reply
9 replies to this topic

#1 john_light

john_light

    GMC Member

  • New Member
  • 25 posts

Posted 12 October 2011 - 02:09 PM

Hi, I found this feature in GM8 to load my sprites,backgrounds,sound externally on the manual. I'm gonna rebuild my game again using this feature because of the fact that i will use large size of background and sprites because its seems that the game maker has a limited amount memory on storing your files internally. First of all i need to find out how do i make the "gmspr" and use it on GM8. And also set its x and y position. I use GM8 pro.
  • 0

#2 amiel

amiel

    GMC Member

  • GMC Member
  • 1117 posts
  • Version:Unknown

Posted 12 October 2011 - 02:24 PM

Good for you cause you have Pro,
why not try to use this codes

sprite_replace(spr_player,'player.png',image_number,removeback,smooth,xorigin,yorigin)
background_replace(bck_floor,'floor.png',removeback,smooth)

Note:the files should be at the same directory where the game is...
:whistle:
  • 0

#3 faissialoo

faissialoo

    I get high on orange

  • GMC Member
  • 1024 posts
  • Version:GM8

Posted 12 October 2011 - 03:01 PM

Good for you cause you have Pro,
why not try to use this codes

sprite_replace(spr_player,'player.png',image_number,removeback,smooth,xorigin,yorigin)
background_replace(bck_floor,'floor.png',removeback,smooth)

Note:the files should be at the same directory where the game is...
:whistle:

No they do not have to be in the same folder as the game it can be anywhere on the PC
  • 0

#4 GraphicGamer

GraphicGamer

    GMC Member

  • New Member
  • 309 posts
  • Version:GM8

Posted 12 October 2011 - 03:26 PM


Good for you cause you have Pro,
why not try to use this codes

sprite_replace(spr_player,'player.png',image_number,removeback,smooth,xorigin,yorigin)
background_replace(bck_floor,'floor.png',removeback,smooth)

Note:the files should be at the same directory where the game is...
:whistle:

No they do not have to be in the same folder as the game it can be anywhere on the PC


Edited by GraphicGamer, 12 October 2011 - 03:28 PM.

  • 0

#5 Logfan200

Logfan200

    GMC Member

  • GMC Member
  • 177 posts
  • Version:GM5

Posted 12 October 2011 - 03:30 PM


Good for you cause you have Pro,
why not try to use this codes

sprite_replace(spr_player,'player.png',image_number,removeback,smooth,xorigin,yorigin)
background_replace(bck_floor,'floor.png',removeback,smooth)

Note:the files should be at the same directory where the game is...
:whistle:

No they do not have to be in the same folder as the game it can be anywhere on the PC

...

They have to be in the same folder. But you can do something like this "/data/sprite.png"; If you want it to be in another folder.
  • 0

#6 LOS.A

LOS.A

    GMC Member

  • GMC Member
  • 597 posts
  • Version:GM8

Posted 12 October 2011 - 04:02 PM

They have to be in the same folder.

No, they don't. You actually said so yourself.
The directory it is in doesn't even have to be in the working directory or program directory. You just have to provide the whole path.

Edit: I recommend not having them in the same folder as the .exe, as it will make everything look messy. I usually go with subdirectories within the working one, named with something relevant to their function:
file = working_directory+"\Resources\Sprites\spr_player.png"

Edited by LOS.A, 12 October 2011 - 04:07 PM.

  • 0

#7 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1606 posts
  • Version:GM8

Posted 12 October 2011 - 05:03 PM

The files don't have to be in the same directory as the game.

Now back to the topic:

sprite_add(fname,imgnumb,removeback,smooth,xorig,yorig) Adds the image stored in the file fname to the set of sprite resources. Many different image file types can be dealt with. When the image is not a gif image it can be a strip containing a number of subimages for the sprite next to each other. Use imgnumb to indicate their number (1 for a single image). For gif images, this argument is not used; the number of images in the gif file is used instead. removeback indicates whether to make all pixels with the background color (left-bottom pixel) transparent. smooth indicates whether to smooth the edges. xorig and yorig indicate the position of the origin in the sprite. The function returns the index of the new sprite that you can then use to draw it or to assign it to the variable sprite_index of an instance. When an error occurs -1 is returned.

sprite_add_sprite(fname) Adds the sprite stored the file fname to the set of sprite resources. The file must be a .gmspr file that is saved in the sprite property form in GameMaker. As this file contains all sprite settings, no further arguments are required. The function returns the index of the new sprite that you can then use to draw it or to assign it to the variable sprite_index of an instance. When an error occurs -1 is returned.


There are functions like these for backgrounds and sounds. You can look them up in the game maker manual.
It is better to load the files externally and the main reason is that the game loads much faster.

Hope this was helpful : )
  • 0

#8 LOS.A

LOS.A

    GMC Member

  • GMC Member
  • 597 posts
  • Version:GM8

Posted 12 October 2011 - 05:52 PM

Note that loading everything externally when the game starts won't cut the loading time... It just won't show up on the bar.
  • 0

#9 john_light

john_light

    GMC Member

  • New Member
  • 25 posts

Posted 13 October 2011 - 01:43 PM

thanks for all the reply guy's i figure out how to use sprites externally using the new feature in Gm8 the gmspr.
Here's my code at the create event that fit's perfectly.

john_stand=sprite_add_sprite("spr_john_stand.gmspr")
john_walk=sprite_add_sprite("spr_john_walk.gmspr")
john_punch=sprite_add_sprite("spr_john_punch.gmspr")


floorjump=floor(sprite_height/2)+15 ;
image_speed= 0.3;
gravity=1;
standsprite=john_stand ;
walksprite= john_walk;
swordsprite=john_punch;

But i wonder if i can use the sprite_replace_sprite(ind,fname) in my code to be more efficient in my memmory. how to i use index to change the ind in the sprite_replace_sprite.
  • 0

#10 amiel

amiel

    GMC Member

  • GMC Member
  • 1117 posts
  • Version:Unknown

Posted 15 October 2011 - 03:58 AM

I know they can be anywhere except inside the recycle bin...
Of course teach him the basic and let him found out and learn the rest for himself and gain knowledge...
:whistle:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users