Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411487 Posts in 69377 Topics- by 58433 Members - Latest Member: graysonsolis

April 29, 2024, 11:29:38 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[Game Maker] Sprites, bounding boxes and masks?!
Pages: [1]
Print
Author Topic: [Game Maker] Sprites, bounding boxes and masks?!  (Read 9224 times)
Hedenius
Level 0
**



View Profile
« on: April 01, 2009, 04:56:33 PM »

I got a HUGE problem with setting up my sprites in Game Maker. It just won't work properly!

I got these sprites of my main character.

A 16x16 mask
Idle right
Idle left
Attacking left
Attacking right


These are the masks and sprite combinations i've tried:

Masks

Sprites


I've centered every sprite using the "Center" button and i use automatic bounding box.

First i tried to do #1, this would give me plenty of room for animation. But as soon as i launched the game the player bounces of the ground indefinetly. Since i don't need any space below the sprite, i cut the canvas to #2. This fixed the problem with ground collisions, but when i jump onto the ceiling the sprite will move (jerk/lag) a few pixels without a reason!

#3 works fine, but i have no room for my animation!

I guess i could use sprites of different sizes and then adjust the y-offsett with some code, but i still want to get this to work properly! When i do "sprite_index = attack_left" or "sprite_index = walk_right" there should be NO offset and NO collision errors.

My collision code is taken from "The Novice & Intermediate F A Q" from the GMC.

STEP
Code:
//check if on the ground
var block_below, block_standon, plat_below, plat_standon, on_ground;
block_below = collision_line(bbox_left+2,bbox_bottom+1,bbox_right-2,bbox_bottom+1,o_parent_block,true,true);       
block_standon = (block_below >= 0) && !place_meeting(x,y,block_below);                                     
on_ground = (vspeed == 0) && (block_standon);     

Collision with block
Code:
if (bbox_bottom-vspeed <= other.bbox_top)                                           
{
  y = other.bbox_top-sprite_get_height(mask_index)+sprite_get_yoffset(mask_index); 
  vspeed = 0;                                                                       
}
else if (bbox_top-vspeed >= other.bbox_bottom)                                     
{
  y = other.bbox_bottom+sprite_get_yoffset(mask_index)+1;                             
  vspeed = 0;                                                                       
}

I just can't see what i'm doing wrong. Everything is positioned the same in the center, the mask is always the same.

IT SHOULD WORK, I'M LOOSING MY MIND AND I SHOULD HAVE GONE TO BED 3HOURS AGO Beg

(By the way, i know about the xscale command, but as soon as i used it my side collsions did not work properly! I could sometimes move 1px into the wall, but when i use two sprites it works perfectly)
« Last Edit: April 02, 2009, 09:59:34 PM by Derek » Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #1 on: April 01, 2009, 05:09:30 PM »

One thing I'd try is not using masks at all, and just using the bounding box as the mask.

I'm also not sure you're explaining the problem correctly. I don't know exactly what you're doing or exactly what is the behavior you desire.
Logged

Glyph
Level 10
*****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #2 on: April 01, 2009, 05:10:08 PM »

Collision with block
Code:
if (bbox_bottom-vspeed <= other.bbox_top)                                           
{
  y = other.bbox_top-sprite_get_height(mask_index)+sprite_get_yoffset(mask_index); 
  vspeed = 0;                                                                       
}
else if (bbox_top-vspeed >= other.bbox_bottom)                                     
{
  y = other.bbox_bottom+sprite_get_yoffset(mask_index)+1;                             
  vspeed = 0;                                                                       
}
This tutorial uses complicated stuff just to use the user-friendly simplicity that is vspeed. I would not recommend vspeed.
Regardless, this definitely has to do with the sprite_get_yoffset bit, with the mask_index thrown in there. Calculate what those values will be and then see what your y is being put to through that. I can't do it because this code is foreign. If you can't figure it out, upload the gmk.
Logged


Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic