Jump to content


Photo

How To Load External Sprites?


  • Please log in to reply
9 replies to this topic

#1 alex769

alex769

    GMC Member

  • New Member
  • 31 posts

Posted 20 May 2008 - 05:28 AM

i been trying to load external sprites

ive been trying with something like :

sprite_add(working_directory +"/data/monsters/monsterdamage.gif");

but it keeps telling me an error
can someone help me with this?

thanks :(
  • 0

#2 x-death

x-death

    Flash Developer

  • GMC Member
  • 3402 posts

Posted 20 May 2008 - 05:30 AM

i been trying to load external sprites

ive been trying with something like :

sprite_add(working_directory +"/data/monsters/monsterdamage.gif");

but it keeps telling me an error
can someone help me with this?

thanks :(

look at my example in my sig it shows how to do this.
  • 0

#3 Cypras

Cypras

    Kiwi

  • New Member
  • 773 posts

Posted 20 May 2008 - 05:34 AM

What is the error.
  • 0

#4 alex769

alex769

    GMC Member

  • New Member
  • 31 posts

Posted 20 May 2008 - 05:47 AM

the error is wrong argument or script, somethig like that, help =D
  • 0

#5 Cypras

Cypras

    Kiwi

  • New Member
  • 773 posts

Posted 20 May 2008 - 06:00 AM

You cannot just say sprite_add();

you must assign sprite_add() to a variable

newSprite = sprite_add();

  • 0

#6 x-death

x-death

    Flash Developer

  • GMC Member
  • 3402 posts

Posted 21 May 2008 - 03:42 AM

You cannot just say sprite_add();

you must assign sprite_add() to a variable

newSprite = sprite_add();

well thats a load of bull in my perspective i never had to do that to get it to work, but in perfect respect if you dont use a variable use should replace it with sprite_index

his problem is that you can't just say sprite_add and tell it the directory you must tell it the rest of the info as well.
this is from gm help file:

sprite_add(fname,imgnumb,precise,transparent,smoot
h,preload,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 (animated) gif images, this argument is not used; the number of images in the gif file is used. precise indicates whether precise collision checking should be used. transparent indicates whether the image is partially transparent. smooth indicates whether to smooth the edges. preload indicates whether to preload the image into texture memory. 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.


an example of it in use would be:
sprite_add("/data/monsters/monsterdamage.gif",0,1,1,0,0,0,0)

Edited by x-death, 21 May 2008 - 04:10 AM.

  • 0

#7 LuzTeTT

LuzTeTT

    GMC Member

  • New Member
  • 300 posts

Posted 21 May 2008 - 03:53 AM

You cannot just say sprite_add();

you must assign sprite_add() to a variable

newSprite = sprite_add();

well thats a load of bull in my perspective i never had to do that to get it to work, but in perfect respect if you dont use a variable use should replace it with sprite_index


Well I suppose you can say that... but it's better to assign everything to a variable so you can get what it RETURNS.
Like a script, a function returns the usage (or answer) of the function. If you want to control everything you add to the game externally then you need to at least give it a variable. A constant variable.
This is why you can control your sprites and objects, rooms and etc, all from different objects/scripts, because their names automatically become constant variables.
You don't HAVE to use a variable, but it's the smartest thing to do in any case of controlling an external object or giving an object a sprite simply because you can use the variable to refer to it.
  • 0

#8 x-death

x-death

    Flash Developer

  • GMC Member
  • 3402 posts

Posted 21 May 2008 - 04:08 AM

You cannot just say sprite_add();

you must assign sprite_add() to a variable

newSprite = sprite_add();

well thats a load of bull in my perspective i never had to do that to get it to work, but in perfect respect if you dont use a variable use should replace it with sprite_index


Well I suppose you can say that... but it's better to assign everything to a variable so you can get what it RETURNS.
Like a script, a function returns the usage (or answer) of the function. If you want to control everything you add to the game externally then you need to at least give it a variable. A constant variable.
This is why you can control your sprites and objects, rooms and etc, all from different objects/scripts, because their names automatically become constant variables.
You don't HAVE to use a variable, but it's the smartest thing to do in any case of controlling an external object or giving an object a sprite simply because you can use the variable to refer to it.

i only put it as harsh as i did because he/she said you MUST use a variable. yes its better you do, but you don't have to and thats what i was rebeling against. but the rest of post solves the problem, it was a very simple answer and i'm surprised didn't get found sooner but all well.
  • 0

#9 LuzTeTT

LuzTeTT

    GMC Member

  • New Member
  • 300 posts

Posted 21 May 2008 - 04:14 AM

i only put it as harsh as i did because he/she said you MUST use a variable. yes its better you do, but you don't have to and thats what i was rebeling against. but the rest of post solves the problem, it was a very simple answer and i'm surprised didn't get found sooner but all well.


I wasn't calling on you or anything. You were right; I was just adding detail.
  • 0

#10 x-death

x-death

    Flash Developer

  • GMC Member
  • 3402 posts

Posted 21 May 2008 - 04:26 AM

i only put it as harsh as i did because he/she said you MUST use a variable. yes its better you do, but you don't have to and thats what i was rebeling against. but the rest of post solves the problem, it was a very simple answer and i'm surprised didn't get found sooner but all well.


I wasn't calling on you or anything. You were right; I was just adding detail.

i know you were adding info which could help which was the aim of the topic to help alex769 so i don't mind but if you had of said it really mean then i would have felt like that but its all good.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users