Jump to content


Photo

Sprite Change With Direction Issues


  • Please log in to reply
12 replies to this topic

#1 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 12:42 AM

Alright so, I'm designing a top-view RPG style game. As of now, I have a wizard class, and am working on the attacking system. My dilemma is that I can get a fireball to shoot (in the direction of the mouse) but I can't get the sprite to change depending on the direction it's going. Allow me to explain a bit more. I want the sprite to change according to the direction the fireball is shot in. Such as if I shoot the fire backwards, it still has the forward animation. Which I need to change. Also, I would like my wizards direction t change based on the area of the mouse pointer. Such as if I bring my mouse to the left side of the screen, my wizard changes to the left facing sprite. I'll put a few pics to explain the fire ball situation a bit more.

FIRST ISSUE
http://i44.tinypic.com/1es02a.png

SECOND ISSUE
http://i39.tinypic.com/muk6kp.png

Any help would be appreciated, thanks guys c:
  • 0

#2 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 02:26 AM

If anyone knows of another site where I could ask for help, could they link me to it? I've checked all over the interwebs, and can't find the fix..Thanks!
  • 0

#3 kelson

kelson

    GMC Member

  • GMC Member
  • 304 posts

Posted 11 March 2012 - 02:34 AM

with the fireball just put

image_angle = direction
  • 0

#4 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 11 March 2012 - 02:36 AM

direction = point_direction(x,y,mouse_x,mouse_y);

  • 0

#5 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 02:44 AM

direction = point_direction(x,y,mouse_x,mouse_y);


That's what I have coded so that is shoots where the mouse is positioned, but no matter where I click, the sprite is always the same one, when like I said, I want it to change based on which direction it's going in. If you follow.
  • 0

#6 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 02:47 AM

with the fireball just put

image_angle = direction


Alright, I'll give it a try, but what exactly do I put in for the "direction" part. could you elaborate the code a bit more? Another note; I want the sprite to shoot diagonally if that's where the mouse is. Any help on that would also be appreciated.
  • 0

#7 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 02:58 AM

with the fireball just put

image_angle = direction


after adding in that code, this is my result...

http://i39.tinypic.com/2m6mlut.png
  • 0

#8 RaptureMachine

RaptureMachine

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 11 March 2012 - 04:21 PM

I'm still having the issue.. If anyone knows anything, I would be grateful.
  • 0

#9 yardenleitner

yardenleitner

    GMC Member

  • New Member
  • 1 posts
  • Version:Unknown

Posted 20 March 2013 - 06:56 AM

image_angle=direction;

You need to have the sprite facing right.

Hope I helped.


  • 0

#10 Criminon

Criminon

    Final Element

  • GMC Member
  • 155 posts
  • Version:GM:Studio

Posted 20 March 2013 - 09:47 AM

I'm not very familiar with using the mouse, but I would say it should be something like:

 

 

create an array. Basically set up 4 different ones based off of what the wizard is doing. This array should go into the wizard's create. Or you can make it a global variable and put it into a controller.

then you need to make a variable like skin =0.

 

for up:

skinup[0]=spr_wizard_stand_up

skinup[1]=spr_wizard_run_up

 

then you do the same for the other 3

skindown[0]=spr_wizard_stand_down

 

 

Once you complete that, put a code in the step that is like

 

if mouse's x is greater than the wizard's x {

sprite_index=skinright[skin]}

if mouse's x is less than wizard's x{

sprite_index=skinleft[skin]}

 

then when you do things like shoot or move, you change the skin variable while that is happening to match the number in the array. That way it automatically goes to that array.

 

Hopefully that makes sense.

 

--------------------------------------------------------------

 

edit:

you could also use a double array.

 

dir=0

state=0

 

skin[0,0]=spr_wizard_stand_up

skin[0,1]=spr_wizard_walk_up

 

skin[1,0]=spr_wizard_stand_down

skin[1,0]=spr_wizard_walk_down

 

sprite_index=skin[dir,state]

 

that would start the wizard off standing facing up.

 

you would then need to change the state variable any time you wanted the wizard to walk etc. whenever he moved you would change state to 1

 

then you would change the dir variable to match the 0-4 that the directions would be.


Edited by Criminon, 20 March 2013 - 12:53 PM.

  • 0

#11 Zei33

Zei33

    GMC Member

  • New Member
  • 7 posts

Posted 20 March 2013 - 11:50 AM

Easy, already been stated but I'll restate. 

 

On the step event simply put

 

 

image_angle = direction
 

The fireball sprite must be facing directly right. I repeat, in the sprite it must be facing right for the angles to work.


  • 0

#12 GameDevDan

GameDevDan

    Procrastinator

  • Reviewer
  • 972 posts
  • Version:GM:Studio

Posted 20 March 2013 - 01:44 PM

For changing the wizard's sprite do something like this:

 

STEP EVENT:

mydir = point_direction( oPlayer.x, oPlayer.y, mouse_x, mouse_y)

if ( mydir > 45 ){

  if (mydir < 135 ) {

   sprite_index = UP_SPRITE

  } else {
     if (mydir < 225) {
     sprite_index = LEFT_SPRITE
     } else {
     if (mydir < 315) {
     sprite_index = DOWN_SPRITE
     } else {
     sprite_index = RIGHT_SPRITE
     }
     }
  }
}
else {
     sprite_index = RIGHT_SPRITE
}

 

That should work but I only scribbled it quickly.


  • 0

#13 Criminon

Criminon

    Final Element

  • GMC Member
  • 155 posts
  • Version:GM:Studio

Posted 20 March 2013 - 05:28 PM

For changing the wizard's sprite do something like this:

 

STEP EVENT:

mydir = point_direction( oPlayer.x, oPlayer.y, mouse_x, mouse_y)

if ( mydir > 45 ){

  if (mydir < 135 ) {

   sprite_index = UP_SPRITE

  } else {
     if (mydir < 225) {
     sprite_index = LEFT_SPRITE
     } else {
     if (mydir < 315) {
     sprite_index = DOWN_SPRITE
     } else {
     sprite_index = RIGHT_SPRITE
     }
     }
  }
}
else {
     sprite_index = RIGHT_SPRITE
}

 

That should work but I only scribbled it quickly.

 

I think both of our methods would produce the best result. The wizard wouldn't be animated, unless he's cool with that.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users