Jump to content


Photo

Transforming Sprites


  • Please log in to reply
7 replies to this topic

#1 GraphicGamer

GraphicGamer

    GMC Member

  • New Member
  • 309 posts
  • Version:GM8

Posted 04 May 2011 - 04:16 PM

Hey GMC, How would I take a sprite (drawn) and transform the corners. see images,

So go from This:
Posted Image

To this:
Posted Image
In the draw event (also, my sprit is scale using imagey_scale). Is it possible?

Edited by GraphicGamer, 04 May 2011 - 04:18 PM.

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 04 May 2011 - 04:32 PM

You would have to use a primitive and then texture it with the sprite. Once that is done you can manipulate the corners of the primitives to create the effect you desire. Check out the draw_primitive(), and sprite_get_texture() codes for more information (hint : with two triangles you can do this).

Edited by Nocturne, 04 May 2011 - 04:32 PM.

  • 0

#3 GraphicGamer

GraphicGamer

    GMC Member

  • New Member
  • 309 posts
  • Version:GM8

Posted 04 May 2011 - 04:39 PM

You would have to use a primitive and then texture it with the sprite. Once that is done you can manipulate the corners of the primitives to create the effect you desire. Check out the draw_primitive(), and sprite_get_texture() codes for more information (hint : with two triangles you can do this).


I read the manuel on primitives but it didn't help at all. Could you help me a little more?
  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 04 May 2011 - 04:48 PM

Okay, but I´m in a bit of a hurry so I´ll briefly explain and hope you get it! In the create event

tex = sprite_get_texture(sprite, ind); //get the sprite as a texture
tex_h = texture_get_height(tex);
tex_w = texture_get_width(tex);

Then in the draw event...

draw_primitive_begin_texture(pr_trianglestrip, tex); //start the primitive...[b]
[/b]draw_vertex_texture(0, 0, 0, 0); First corner - upper left
draw_vertex_texture(32, 0, tex_w, 0); upper right
draw_vertex_texture(0, 32, 0, tex_h); bottom left
draw_vertex_texture(32, 32, tex_w, tex_h); bottom right
draw_primitive_end(); //draw the primitive...

Now the codes above should draw a square textured primitive... to change how its drawn change the coords for the corners.

I hope that helps!
  • 0

#5 GraphicGamer

GraphicGamer

    GMC Member

  • New Member
  • 309 posts
  • Version:GM8

Posted 04 May 2011 - 05:27 PM

Okay, but I´m in a bit of a hurry so I´ll briefly explain and hope you get it! In the create event

tex = sprite_get_texture(sprite, ind); //get the sprite as a texture
tex_h = texture_get_height(tex);
tex_w = texture_get_width(tex);

Then in the draw event...

draw_primitive_begin_texture(pr_trianglestrip, tex); //start the primitive...[b]
[/b]draw_vertex_texture(0, 0, 0, 0); First corner - upper left
draw_vertex_texture(32, 0, tex_w, 0); upper right
draw_vertex_texture(0, 32, 0, tex_h); bottom left
draw_vertex_texture(32, 32, tex_w, tex_h); bottom right
draw_primitive_end(); //draw the primitive...

Now the codes above should draw a square textured primitive... to change how its drawn change the coords for the corners.

I hope that helps!

draw_set_color(c_white)
draw_primitive_begin_texture(pr_trianglestrip, tex); //start the primitive...[b]
draw_vertex_texture(x-((tex_w/2)-24),room_height/2,0,0)
draw_vertex_texture(x+((tex_w/2)-24),room_height/2,tex_w,0)
draw_vertex_texture(x-67,room_height, 0, tex_h)
draw_vertex_texture(x+67,room_height,tex_w,tex_h);
draw_primitive_end(); //draw the primitive...
draw_set_color(c_black)

now that SHOULD give me the desired shape, but it doesnt :( it looks twisted. Also can I use image_blend with these primitives?
  • 0

#6 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 04 May 2011 - 05:57 PM

Okay, you have to understand that the width and height of a texture are based on values from 0 to 1... so by adding the tex_w to the x you are only adding 1 onto the coord! Instead you would do...

draw_set_color(c_white);//Not neccessary as we are using a texture...

draw_primitive_begin_texture(pr_trianglestrip, tex); //start the primitive...
draw_vertex_texture(x-(sprite_width/2)-24, room_height/2, 0, 0); //this may not be what you want but you get the idea! 
draw_vertex_texture(x+(sprite_width/2)-24, room_height/2, tex_w, 0);
draw_vertex_texture(x-67, room_height, 0, tex_h);
draw_vertex_texture(x+67,room_height,tex_w,tex_h);
draw_primitive_end(); //draw the primitive...

draw_set_color(c_black) //again, not necessary..

Hopefully that should work!

PS: as for image_blend use draw_vertex_texture_colour() and set the colour argument to image_blend or the colour you wish...

Edited by Nocturne, 04 May 2011 - 05:58 PM.

  • 0

#7 GraphicGamer

GraphicGamer

    GMC Member

  • New Member
  • 309 posts
  • Version:GM8

Posted 04 May 2011 - 06:24 PM

Okay, you have to understand that the width and height of a texture are based on values from 0 to 1... so by adding the tex_w to the x you are only adding 1 onto the coord! Instead you would do...
Hopefully that should work!

PS: as for image_blend use draw_vertex_texture_colour() and set the colour argument to image_blend or the colour you wish...



I used Draw_set_color because it turned out black when i did it normally. Thanks, I figured it out and then I saw your post, but draw_vertex_texture_color() should do it :)


PS Your name will go in the credits
  • 0

#8 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 04 May 2011 - 07:43 PM

Good to know that I got it right! Thanks for the credit...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users