Author Topic: Help with Error [SOLVED]  (Read 1074 times)

Gaim Master

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Help with Error [SOLVED]
« on: Tue, Jun 21, 2011 »
Hi there, this is my first post here so please forgive any excessive newbishness  ;D

It's been a while since I programmed anything and am just diving into using flixel and it's great so far!

I have been frankensteining various tutorials and snippets to get a game demo going and came across this error when integrating the tutorial on mouse aiming here:
http://flashgamedojo.com/wiki/index.php?title=Mouse-Aim_Tutorial_(Flixel)

the error is "Implicit coercion of a value of type Number to an unrelated type org.flixel:FlxPoint" comes up in this line of code used to calculate the angle:

Code: [Select]
this.aimAngle = FlxU.getAngle((FlxG.mouse.x - (x + (width/2))), (FlxG.mouse.y - (y + (height/2))));
I have a feeling it's an easy fix and may have to do with a version discrepancy. The tutorial was written using v2.35 and I am using v2.5.

thanx for any tips,
Brad
« Last Edit: Thu, Jun 23, 2011 by Gaim Master »

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: Help with Error
« Reply #1 on: Tue, Jun 21, 2011 »
From the docs for FlxU.getAngle: public static function getAngle(Point1:FlxPoint, Point2:FlxPoint):Number

So it's expecting two FlxPoints, one for each you're comparing.  You have the X and Y points of the center point there, and you'll need to compare it against FlxG.mouse.x and FlxG.mouse.y.

I would suggest updating a FlxPoint every time rather than creating a new one, as it'd be much faster, too.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Help with Error
« Reply #2 on: Wed, Jun 22, 2011 »
You could also use FlxVelocity inside my power tools, it has lots of methods for calculating point to mouse, point from object, object to object, etc :)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Gaim Master

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Help with Error
« Reply #3 on: Thu, Jun 23, 2011 »
Hey, thanx for the help Cai. Solved that error.

@Photonstorm: I have your power tools downloaded and they look awesome. I just haven't integrated them yet because I'm learning as I go and trying to keep it simple by adding 1 thing at a time. I am sure I will get into it soon though.

thanx again