Flashpunk does not recognize its functions [SOLVED]


(Massimo) #1

Hi! As i writed on the title of this topic Flahpunk does not recognize its functions (or, at least, it seems so).

Even if i include the net.flashpunk.Entity library in my code it continue to say me that collide function is not defined. Moreover, inside the debug mode, it say that there isn’t some of the var that i had previously defined inside the same page. Some ideas?

EDIT: This happens only on a part of the code, as follows:

if (collide('D_Muro', x, y) || collide('Enemy', x, y))
		{
			hitted = !hitted;
			
			if (!hitted)
			{
				sprPinco.play('morte');
				FP.world = new W_GameO();
			}
			
		}

(Jacob Albano) #2

You need to extend the Entity class to have access to any of its methods.


(Massimo) #3

In other words? Excuse, but they are the first approaches with Flashpunk for me!


(Jacob Albano) #4

Those functions you’re trying to use are member methods of the Entity class. In order to access them, your class needs to extend Entity.

public class YourClass extends Entity
{
    // ...
}

(Massimo) #5

Ha ok, but i already done. Probably there is something else.


(Jacob Albano) #6

Can you include the full source of the file that’s giving you trouble?


(Massimo) #7
package {

import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Spritemap;
import net.flashpunk.graphics.Text;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;

public class Pinco extends Entity {
	private var power:Number=0.2;
	private var jumpPower:Number=10;
	private var hFriction:Number=0.95;
	private var vFriction:Number=0.99;
	private var xSpeed:Number=0;
	private var ySpeed:Number=0;
	private var gravity:Number=0.3;
	private var isJumping:Boolean=false;
	private var doubleJump:Boolean = false;
	private var hitted:Boolean = false;
	
	[Embed(source = "../assets/pinco.png")] private const PINCO:Class;
	public var sprPinco:Spritemap = new Spritemap(PINCO, 54, 37.2);
	
	public function Pinco () {
		setHitbox(54,37.2);
		x = 40;
		y = 460;
		type = 'player';
		
		sprPinco.add('fermo', [0, 1, 2, 3, 4, 5], 13, true);
		sprPinco.add('corsa', [6, 7, 8, 9, 10, 11], 20, true);
		sprPinco.add('corsa_sx', [12, 13, 14, 15, 16, 17], 20, true);
		sprPinco.add('attacca', [18, 19], 20, false);
		sprPinco.add('salto', [20, 21], 20, false);
		sprPinco.add('morte', [30, 31, 32, 33, 34, 35], 20, false);
		graphic = sprPinco;
		sprPinco.play('fermo');
	}
	override public function update():void {
		
		var pressed:Boolean=false;
		if (Input.check(Key.LEFT)) {
			xSpeed-=power;
			pressed=true;
		}
		if (Input.check(Key.RIGHT)) {
			xSpeed+=power;
			pressed=true;
		}
		if(!Input.check(Key.UP) && isJumping){
			doubleJump=true;
		}
		if(Input.check(Key.UP) && doubleJump && isJumping){
			ySpeed=-jumpPower;
			isJumping=false;
			doubleJump=false;
		}
		if (collide("Muro",x,y+1)) {
			ySpeed=0;
			isJumping=false;
			if (Input.check(Key.UP)) {
				ySpeed=-jumpPower;
				isJumping=true;
			}
		} else {
			ySpeed+=gravity;
		}
		if (Math.abs(xSpeed)<1&&! pressed) {
			xSpeed=0;
		}
		xSpeed*=hFriction;
		ySpeed*=vFriction;
		moveBy(xSpeed,ySpeed,"Muro");
		if(xSpeed>0 || Input.pressed(Key.RIGHT)){
			sprPinco.play("corsa");
		}
		if(xSpeed<0 || Input.pressed(Key.LEFT)){
			sprPinco.play("corsa_sx");
		}
		if(xSpeed==0 || Input.released(Key.RIGHT) || Input.released(Key.LEFT)){
			sprPinco.play("fermo");
		}
	}
	
	//the truble start here! The collide function doesn't work
	if (collide('D_Muro', x, y) || collide('Enemy', x, y))
		{
			hitted = !hitted;
			
			if (!hitted)
			{
				sprPinco.play('morte');
				FP.world = new W_GameO();
			}
			
		}
	/*}
	override public function moveCollideX(e:Entity):void {
		xSpeed = 0;
	}
	override public function moveCollideY(e:Entity):void {
		ySpeed = 0;
	}
	*/
} }

The strange thing is that the function collide before my comment work properly!


(Massimo) #8

Ok, i’m REALLY a n00b ._____________.

I missed a brace to the end of the update function! Well, problem solved! Now i have another big problem… Mhè!

Thanks for your time!


(Matt L) #9

Are you using Flashdevelop? Its code completion and syntax checking would make making these kinds of mistakes almost impossible.


(Massimo) #10

Yep, i use FlashDevelope, but in this case the fault was mine :frowning: In fact, somehow, i don’t put a brace at the end of the update function.