Scaling character sprite questions (beginner)

I

id07

Guest
Looking for some help with the coding of a game. I have a sprite for a small rpg test im working on, and what I'd like to do, is, make the sprite grow when the player pushes the down (simulating as if they are coming at the camera) and get small when the play presses up (simulating when the player moves away. I thought I understood scaling...I clearly do not.

Appreciate any help!
 

Rob

Member
Code:
//create event
xscale = 1;
yscale = 1;

//step event
if (PRESSED_DOWN){
   xscale += 0.1;
   yscale += 0.1;
}

if (PRESSED_UP){
   xscale -= 0.1;
   yscale -= 0.1;
}
You can then use draw_sprite_ext in the draw event to draw the sprite. I hope that's what you're after?
 
D

Dennis Ross Tudor Jr

Guest
The origin of the sprite will play a big factor in your scaling. Since the image will scale around the origin, you will get different scaler visuals depending where the origin is. If the origin is at the top left corner then the image will scale down and to the right. If the origin is in the center then the image will scale evenly around each edge.

negative values of scale will 'flip/mirror' the sprite. If image_xscale == -1 then the image would be mirrored horizontally. if the value was -2 then it would mirror the image and scale it to twice it's size.
 
I

id07

Guest
Would it look like this in the step event?

//step event
if (keyboard_check_pressed(vk_down){
xscale += 0.1;
yscale += 0.1;
}

if keyboard_check_pressed(vk_up){
xscale -= 0.1;
yscale -= 0.1;
}

I tried your code and then this code, and errors all over. Thank you for the help
 
I

id07

Guest
I was after something like this, but just using sprites. Perhaps just I have a long way to go (12:30 in video)

 
If you want to get something similar, make sure the origin of the sprite is at the center, then put this in your step event:
Code:
/// STEP EVENT
var scaling_amount = 0.1;    // Scaling increment/decrement amount
var max_scaling = 4;            // Max scaling value
var min_scaling = 1;              // Min scaling value

if (keyboard_check(vk_down)) {
    image_xscale = min(image_xscale + scaling_amount, max_scaling);
    image_yscale = min(image_yscale + scaling_amount, max_scaling);
}

if (keyboard_check(vk_up)) {
    image_xscale = max(image_xscale - scaling_amount, min_scaling);
    image_yscale = max(image_yscale - scaling_amount, min_scaling);
}
Feel free to change the values until you get the result you want.
 
I

id07

Guest
Wow, that works awesomely! Thank you, and everyone else for the help. One more question regarding this, if and when I push both the up and down key at the same time, it glitches: How do I cancel out the down key when pressing up and vice versa to not get weird effects?
 
Just put an else statement :

Code:
if (keyboard_check(vk_down)) {
    image_xscale = min(image_xscale + scaling_amount, max_scaling);
    image_yscale = min(image_yscale + scaling_amount, max_scaling);
} else if (keyboard_check(vk_up)) {
    image_xscale = max(image_xscale - scaling_amount, min_scaling);
    image_yscale = max(image_yscale - scaling_amount, min_scaling);
}
 
I

id07

Guest
I added this:

if keyboard_check(vk_up) and keyboard_check(vk_down){
speed = 0
}

Seems to be working!

Thank you!
 
Top