Windows [SOLVED] Using draw_sprite_stretched - odd issue?

W

warbo

Guest
So i have been working on a way to get my "shop" to scale with the rooms camera/view and scroll and its all working great except for my images.

The first image works fine, its scaled and positioned correctly but when i cycle to the next few the image scales and positions funny, i have added a video to show this.

https://streamable.com/qgh2u

This is the code that is in the image object where the image gets drawn.
Code:
/// @description Insert description here
// You can write your code in this editor
draw_self();

draw_sprite_stretched(spr_ShopItems, global.itemImageNumber[global.currentItem], x - 130 * global.zoom, y - 130 * global.zoom, sprite_get_width(global.itemImageNumber[global.currentItem]) /2 * global.zoom, sprite_get_height(global.itemImageNumber[global.currentItem]) /2 * global.zoom)
The create event where i store the needed things
Code:
global.itemName[1] = "Yellow Cables";
global.itemPrice[1] = "$35.00";
global.itemImageNumber[1] = 0;
global.itemDescription[1] = "These cables are used with the\nmobie power generator.\n\nYou would use these to\nconnect upto Hog Pan.";

global.itemName[2] = "Mobile Generator";
global.itemPrice[2] = "$150";
global.itemImageNumber[2] = 1;
global.itemDescription[2] = "The mobile generator runs on\ngasoline and is a great runner!";
All the images are the same size.

Basically there are 4 of the above and all of them are in one sprite so that is where the "global.itemImageNumber[1] = 0;" as this changes the image.

I cant work out why after the first image they all mess up after that.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The variable:

global.itemImageNumber[n]

Holds an image index, which is simply an integer value that signifies the frame of the animation, but you are using it in the get width/height function as if it was a sprite index... You want to change the code to:

sprite_get_width/height(spr_ShopItems);

If each image index is a seperate size, and what you want is to have each one stretch to fit the size of the menu box, then you have two options:

1) Create a sprite for each index instead of having them all in one sprite, and then store the sprite_index instead of the image_index in the item array to draw and get the width/height of, or....

2) Store the width/height for each image_index as part of the global item array and then use those hard-coded values for the width/height

Hope that helps!

:)
 
W

warbo

Guest
The variable:

global.itemImageNumber[n]

Holds an image index, which is simply an integer value that signifies the frame of the animation, but you are using it in the get width/height function as if it was a sprite index... You want to change the code to:

sprite_get_width/height(spr_ShopItems);

If each image index is a seperate size, and what you want is to have each one stretch to fit the size of the menu box, then you have two options:

1) Create a sprite for each index instead of having them all in one sprite, and then store the sprite_index instead of the image_index in the item array to draw and get the width/height of, or....

2) Store the width/height for each image_index as part of the global item array and then use those hard-coded values for the width/height

Hope that helps!

:)

Ah i see the mistake. The images are all the same size in the sprite so using "sprite_get_width(spr_ShopItems)" and height works, just needed to re-position them and its perfect. Thanks for the swift reply.
 
Top