Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> [SOLVED] GML: sprite_width not working
Unspecified
exenefevex
Posted: Jul 3 2008, 05:20 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


[SOLVED]

Every time I try to use sprite_width, it returns zero.

Example:
CODE
x2+=spritename.sprite_width;
or
CODE
show_debug_message(string(spritename.sprite_width));
This always returns zero, which is obviously not what I'm looking for. The actual width of the sprite is 128 pixels; the subimage width (which I'd really like) is 8.

I've also tried using objectname.sprite_width which also returns 0.

How do I get this to work properly?

This post has been edited by xn--e5x on Jul 3 2008, 06:33 PM


--------------------
PM
Top
United States
Littlink
Posted: Jul 3 2008, 05:43 PM
Quote Post


hip 2b square
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 5146
Member No.: 2010
Joined: 11-April 06

Status: (0d) [--]


I dunno if you can use spritename.sprite_width with sprites that aren't currently being used by the active object.

I tried

draw_text(x,y-48,""+string(sprite_width));
draw_text(x,y-32,""+string(sprMarioSmall.sprite_width));

and it worked fine, both returned 16. But when I tried a sprite that wasn't being used by the object like

draw_text(x,y-48,""+string(sprite_width));
draw_text(x,y-32,""+string(spr8x8.sprite_width));

and it returned an error. The sprite of the object was sprMarioSmall and not spr8x8. Does that help? :S


--------------------
[████████░░] 80%

user posted image
PMUsers WebsiteMSN
Top
Unspecified
exenefevex
Posted: Jul 3 2008, 06:25 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


Turns out I was trying something I wasn't supposed to do with object-oriented programming.

I got it working by calling the script from an object and giving that object a sprite. Turns out that if you call a script from an object, the object's values carry over into the script. So I don't have to pass any sprite references to the script. smile.gif


--------------------
PM
Top
Unspecified
Draco Icebane
Posted: Jul 3 2008, 06:44 PM
Quote Post


Standard Member
[*][*][*][*][*]


Group Icon
Group: Banned
Posts: 52997
Member No.: 10
Joined: 13-October 03

Status: (71582612m) [XX]


QUOTE (xn--e5x @ Jul 3 2008, 04:25 PM)
Turns out that if you call a script from an object, the object's values carry over into the script.

Is this calling a script from a script in an object or in drag and drop?

I noticed that in drag and drop it lets you define which object -- if any -- calls a script, and that object will be considered the host of that script
PM
Top
United States
Littlink
Posted: Jul 3 2008, 06:56 PM
Quote Post


hip 2b square
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 5146
Member No.: 2010
Joined: 11-April 06

Status: (0d) [--]


QUOTE (Draco Icebane @ Jul 3 2008, 06:44 PM)
Is this calling a script from a script in an object or in drag and drop?

I noticed that in drag and drop it lets you define which object -- if any -- calls a script, and that object will be considered the host of that script

Both are possible. Like

other(sprite_index=spr_big);
objThing.sprite_index=spr_big;
102115.sprite_index=spr_big;

or just select the object in DnD.

You could also get the ID of an object and use that like

objID=(whatever object);
objID.sprite_index=spr_big;

Either way you catch the object's variables as long as you call what object you're using first (objID, the physical ID, other, or the actual object name).


--------------------
[████████░░] 80%

user posted image
PMUsers WebsiteMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0383 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 8.46 ]