Jump to content

  • Log In with Google      Sign In   
  • Create Account


tashaklikedi

Member Since 04 Jun 2012
Offline Last Active Jul 22 2013 08:38 AM

Topics I've Started

ActionScript 3 - calling method from a class which has a child class

27 May 2013 - 09:43 AM

Hello all, I need help with some calling issues.

I am trying to create a game engine for my future games in actionscript 3, and I am working on a method called Renderer, which I plan to add as member to all my classes which will be displayed on the screen. I use blitting method. I have a GameLoop method, which is in the Game class, and an Entity class, which incorporates an instance of the Renderer class.

 

I'll try to give examples with code:

 

** EDITED CODE **


//Game.as:

package
{
	//import things
	
	public class Game extends Sprite
	{
		var 	mDisplay:Bitmap;
		var	mDisplayBD:BitmapData;
		var	mEntity:Entity;

		public function Game()
		{
			//initialize things
			mDisplayBD = new BitmapData(Constants.SCREEN_WIDTH,Constants.SCREEN_HEIGHT,false,0x000000);
			mDisplay = new Bitmap(mDisplayBD);
			
			mEntity = new Entity(mDisplayBD);		

			this.addEventListener(Event.ENTER_FRAME,GameLoop);
			this.addChild(mDisplay);
		}
		
		public function GameLoop(e:Event)
		{
			mEntity.Render();
		}
	}

}
//Renderer.as



package 
{
	//import stuff

	public class Renderer
	{
		var mBitmapData:BitmapData;
		var mPoint:Point ;
		var mRect:Rectangle ;
		var mDisplayBD:BitmapData;
		public function Renderer(bitmapdata)
		{
			mBitmapData = bitmapdata;
			this.mDisplayBD = bitmapdata;
			mPoint = new Point();
			mRect = new Rectangle();
			mPoint.x = 0;
			mPoint.y = 0;
		}
		
		public function LoadBitmap(URL:String)
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnComplete);
			loader.load(new URLRequest(URL));
		
		}
		
		private function OnComplete(event:Event)
		{
			mBitmapData = event.target.content.bitmapData;
		}
		
		public function Render(posX,posY,clipX,clipY,width,height)
		{
			mDisplayBD.lock();
			mPoint.x = posX;
			mPoint.y = posY;
			mRect.x = clipX;
			mRect.y = clipY;
			mRect.width = width;
			mRect.height = height;
			mDisplayBD.copyPixels(mBitmapData,mRect,mPoint);
			mDisplayBD.unlock();
		}
		
	}
}


//Entitiy.as

package
{
	//import
	
	public class Entity extends Sprite 
	{
		
		var mPosX;
		var mPosY;
		var renderer:Renderer;
		var input:InputManager;
		var mDisplayBD:BitmapData;
		public function Entity (bitmapdata:BitmapData)
		{
			mDisplayBD = bitmapdata
			renderer = new Renderer(mDisplayBD);
			renderer.LoadBitmap("filename.png");
		}
		
		public function Render()
		{
			renderer.Render(mPosX,mPosY,0,0,Constants.SCREEN_WIDTH,Constants.SCREEN_HEIGHT);
		}

	
	}
} 

 

When I create a new renderer instance in the class game, and do something like renderer.Render() in the GameLoop method, it works, but not when I do it as entity.renderer.Render();

 

I have to solve this until tomorrow, please can anyone help me? I searched a lot on the internet, but found nothing... (maybe I dont know what to look for).

 

Edit: dont mind the var input:InputManager; line, I forgot to remove it from the sample code


visual c++ version runs differently than the exe in explorer!

10 April 2013 - 04:54 PM

Hello everyone, I have a strange issue ( noob programmer here )

Some of my game's collisions do not work when I click on the exe that is located in the "release" folder from windows explorer, but they work when I do "build and compile" from visual c++. I made sure I compiled in release mode, and the data folder is copy paste in both folders. 

I really don't understand. 


How to handle states in a fighting game?

18 February 2013 - 11:51 AM

Hi everyone, as a newbie programmer, I am trying to develop a 2D side scrolling Streets of Rage like fighting game with a lot of characters, moves, and animations. I started to learn programming 1 year ago, and I managed to have a game where I have two player controllable characters hit each other, jump to higher elevations in a streets of rage style map, etc...

 

However, since I am new to programming, and rushed enthusiastically into programming the game without any plan, my code got really messy. 

My problem is how to handle character states ( or moves ) , and their animation...

 

How I proceeded is: I have a huge switch function with states, another one with animations, another one with hitboxes for example:

 


//this is the base punch for the ninja character.
// this is the state switch function
case NINJA_BASEPUNCH:
		falsify(); // set everything to false (i.e. he cant jump while punch animation is on)
		bCanBasePunch = true; 
		enumAnimState = NINJA_AS_BASEPUNCH; //animation is set to base punch animation
		enumHitMessage = HIT_LIGHT_HI; //this will tell the enemy entity the damage type ( light ) and its position ( high )
		basePunch(); //punch function 
		break;

//once this is executed, the program will set the animation settings
//this is from animation switch function

case NINJA_AS_BASEPUNCH:
		sprite.w = 36;
		sprite.h = 36;
		iCurrentFrameCol = (bFaceRight ? 13:14);
		iCurrentFrameRow = 0;
		animation.maxFrames = 2;
		animation.setFrameRate(animation.getCurrentFrame() > 0 ? 100:60);
		break;
		}
//this is from the hitbox update function. 
case NINJA_AS_PUNCH:
		hitbox.w = groundPos.w;
		hitbox.h = 35;


 

All this is only for a simple basic punch. Now imagine how would it be if there was a big move list, big combos, stunts, etc... I need to get a better system for it, anyone who can think of a better implementation system?

 


playing multiple sound formats at the same time

12 October 2012 - 12:18 PM

Hi everyone, In the game I'm developping I'm trying to use nsf (nintendo sound format) files as music and waves as sound effects. The nsf library uses SDL_Sound. the problem is that I can never load two files simultaneously. The NSF library is not able to load two sounds at once, and when I try to load my wav files with SDL_Mixer, I can't play the NSF file.

I was wondering if multi threading would solve this...

Another issue with SDL joystick

30 September 2012 - 10:46 PM

Hi again, I ran into another problem with the joystick in SDL:

in libsdl.org, it says that the joystick has 8 directions with the hat: up, down, left, right, upleft, upright, downleft, downright. But when I press the up button, it reads at the same time up, upleft, up right. This is the same for each direction (for example, if I press left, it will read left, upleft, downleft. I wonder if this is normal, if there is a problem with my joystick, or if the problem is in my code (which is a uber simplistic program to see if I get my joystick to work).

Did anybody ran into this kind of problems? (please dont send me the LazyFoo links, because there is nothing about hats there ^^)

PARTNERS