Author Topic: Rotating Sprites  (Read 9848 times)

0 Members and 1 Guest are viewing this topic.

Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Rotating Sprites
« on: October 02, 2014, 01:44:23 pm »
Hello,

I needed help in rotating sprites.I am trying to use SetRotationForPlayer( player, rotation ) but i get no errors and nothing happens.

I try to rotate it like this :

Code: [Select]
s <-CreateSprite( "spritename.png", 500, 600, 0, 0, 0,255 );
s.ShowForPlayer( FindPlayer( player ) );
s.SetRotationForPlayer(player, 150);
« Last Edit: October 02, 2014, 02:39:14 pm by Honey. »

Offline Flockshot

  • Street Thug
  • *
  • Posts: 29
    • View Profile
Re: Rotating Sprites
« Reply #1 on: October 02, 2014, 03:31:46 pm »
Hmm i also have this error but it shows error in console
Saying that cannot find member variable

Offline tђยภ๔єгรt๏г๓

  • Street Thug
  • *
  • Posts: 17
    • View Profile
Re: Rotating Sprites
« Reply #2 on: October 02, 2014, 03:54:18 pm »
Code: [Select]
s.RotateForPlayer(player, 150);

Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #3 on: October 02, 2014, 05:08:00 pm »
That function does rotate the sprite but doesn't rotate the sprite I want but instead makes a new sprite and rotates that!

Multiple Sprites was a bug of my script which i fixed later but now there is a new problem.The needle's position keeps changing on the screen while moving.If my car stays still it doesn't move but If my car is not still it dances on the screen.
« Last Edit: October 02, 2014, 05:21:34 pm by Honey. »

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Rotating Sprites
« Reply #4 on: October 02, 2014, 05:49:54 pm »
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #5 on: October 02, 2014, 05:59:14 pm »
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)

If you mean the position of the player is changed then you're right.The player position is contantly changing while  it is driving.
« Last Edit: October 03, 2014, 05:25:56 am by Honey. »

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Rotating Sprites
« Reply #6 on: October 02, 2014, 08:06:15 pm »
Post some more code. A sprite doesn't dance on your screen unless you tell it to.

Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #7 on: October 03, 2014, 05:33:15 am »
Post some more code. A sprite doesn't dance on your screen unless you tell it to.

Here you go :

Code: [Select]

function onScriptLoad()
{
// Other Functions
NewTimer( "Speedometer", 1500, 0 );
s <-CreateSprite( "needle.png", 500, 500, 0, 0, 0,255 );
// other functions
}

function Speedometer()
{
for ( local i = 0; i < GetMaxPlayers(); i++ )
{
                local p = FindPlayer( i );
                if ( p )
                {
                        if ( p.IsSpawned )
                        {
                                local vehicle = p.Vehicle;
                                if ( vehicle )
                                {
                          local Speed = sqrt(vehicle.Speed.x*vehicle.Speed.x + vehicle.Speed.y * vehicle.Speed.y + vehicle.Speed.z * vehicle.Speed.z) * 50 * 3.6;
                          local output = round(Speed, 0);
  s.RotateForPlayer( p, output );
                                }
                        }
                }
         }
}

function onPlayerEnterVehicle( player, veh, isPassenger )
{
s.ShowForPlayer( player );
}
function onPlayerExitVehicle( player, veh )
{
s.HideFromPlayer( player );
}

This is all of the code I have used.

Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #8 on: October 03, 2014, 09:11:08 am »
Here is a video ( sorry for the bad quality, I compressed the video too much  :-\ ) :




Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #9 on: October 03, 2014, 04:55:10 pm »
Bump!!

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Rotating Sprites
« Reply #10 on: October 03, 2014, 10:23:37 pm »
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.
Do not PM me for support.




Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #11 on: October 04, 2014, 07:36:20 am »
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.

Can you explain more? I didn't quite understand what you meant.

Secondly rotation problems is a different case why does the sprite move in random positions?

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Rotating Sprites
« Reply #12 on: October 04, 2014, 07:44:30 am »
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.

Can you explain more? I didn't quite understand what you meant.

I don't know how to explain this any further without having to teach trigonometry.

Quote
Secondly rotation problems is a different case why does the sprite move in random positions?

I'm going to say because you didn't remove whitespace/transparency around the speedometer sprite.
Do not PM me for support.




Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Rotating Sprites
« Reply #13 on: October 04, 2014, 08:02:11 am »
Is whitespace created when we enter in the vehicle by pressing the enter button? I read that  :

Quote
Vertical white space is a bit more varied as to how it is encoded,but the most obvious in typing is the ↵ Enter result which creates a 'newline' code sequence in applications programs

Where is the whitespace created and how do I remove it?
Sorry for being a noob here  ;)

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Rotating Sprites
« Reply #14 on: October 04, 2014, 09:17:23 am »
Whitespace is created when you have a PNG with transparency around the image.
Do not PM me for support.