Posted: 1st Jan 2012 22:45
If I may make a suggestion, physics needs to be added to the placement editor.

When you load in a sprite - its object properties needs more than just position, rotation and scale - it needs its physics properties set as well (you could make it so that when you choose a new level project, you are given the choice of a static level or one with physics).

That would make it much easier to create a physics-based game than to do it after-the-fact.

What do you think? Is this possible?

Mike
Posted: 2nd Jan 2012 0:43
Personally I think it is far more practical to set those properties yourself since there are an almost unlimited number of possible settings.

I am using some placeholders for complex physics objects that would take an age to set up one by one in every level of my game, for example...
Posted: 2nd Jan 2012 3:25
Question: Is the source to the placement editor available (I assume it was done in AGK)? Was it done as a tier 1 or tier 2 project?

I need to create my own level editor and I would love a head start since I am so darn rusty with coding.

I did successfully create the beginnings of my game engine - got images loaded successfully. Got physics, both static and dynamic, working properly and got movement working properly.

However, I need to start creating levels and I am having a really tough time utilizing the level editor files. When I code it by hand, it works, when I try to use the viewer along with a level, nothing works right.

Perhaps someone can give me hints or code fragments as to set movement, rotation, physics and collision to specific sprites. I cannot seem to figure out how they are assigned ID #s.

Any help is appreciated.

Mike
Posted: 2nd Jan 2012 9:37
I need to make a level editor too, and be able to assign certain reserved properties to every sprite, so that my game will know how to move the bad guys sprites, etc...
Posted: 2nd Jan 2012 17:22
I can use the existing placement editor - it's very good. However, I need someone's help in explaining how to single out sprites so I can assign code to them.

How are IDs assigned and how, in the main.agc file, do I reference them?

Mike
Posted: 2nd Jan 2012 18:29
Did my explanation not help? Sorry, I don't have time right now but I'll make a full example ASAP.
Posted: 2nd Jan 2012 18:42
The editor is a great start but you do need to be able to set the physics properties of the objects as well. Doing this after the fact seems to defeat the purpose of using an editor in the first place. I don't think it needs to be a comprehensive physics editor but should support the basic physics properties.
Posted: 2nd Jan 2012 20:59
Your code fragment:

if image$ = "Fan1.png"
`do stuff
setSpritePhysicsOn(id,2)
rem or whatever (id is the sprite ID)
endif

In the rem, you say id is the sprite id - great. How do we figure out what the sprite id is? Is it in an array? I just need to know how you get the ID so I can assign it physics properties.

Mike
Posted: 2nd Jan 2012 21:27
Ok, tomorrow I will set up a simple project as an example.
Posted: 2nd Jan 2012 21:41
I am having some troubles. I am trying to load a simple background image and it is not showing up.

+ Code Snippet
// load background image
//CreateSprite ( LoadImage ( "meadowback.jpg" ) )
newback = LoadImage( "meadowback.jpg" )
backimage = createsprite (newback)
setspriteposition (backimage, 0, 0)


Also, the first sprite I added using the placement editor was a small hammer. It will not show on screen no matter what I do. Everything else is perfect. What can I do?

curweapon is the variable for the hammer (physics is set on, shape of 3). curmat is the variable for the wood planks that have physics set on for them, shape of 2. Curmat2 is the ground variable that is set to static, shape of 2.

Here is the code for the project:

Main:

+ Code Snippet
// placement editor loading code
#include "placement_editor.agc"

// globals for the placement editor
global dim g_Entities [ 1000 ] as tEntity
global dim g_MediaList [ 1000 ] as tEntity
global     g_iEntityCount = 0
global     g_iMediaCount  = 1
global	   g_fJoystickSpeed#
global curweapon as integer
global curmat as integer
global curmat2 as integer

// load a level using a virtual resolution
LoadFromPlacementEditor ( "export.txt", "virtual" )

// load a level using the percentage system
// LoadFromPlacementEditor ( "export.txt", "percentage" )

// to delete data call
// DeletePlacementEditorData ( )

// load background image
//CreateSprite ( LoadImage ( "meadowback.jpg" ) )
newback = LoadImage( "meadowback.jpg" )
backimage = createsprite (newback)
setspriteposition (backimage, 0, 0)

// our main loop

SetPhysicsGravity( .5, 200 )
SetPhysicsDebugOn()

//image = LoadImage ("tinyhammer.png")
//curweapon = CreateSprite (image)
x#=100
y#=161
curmatx#=490
curmaty#=100
SetSpritePosition( curweapon, x#, y# )
SetPrintColor( 255, 255, 255 )

do
	// scroll the screen
	joystickX# = GetVirtualJoystickX ( 1 ) * g_fJoystickSpeed#
    joystickY# = GetVirtualJoystickY ( 1 ) * g_fJoystickSpeed#
    xcoord$ = str(GetPointerX())
    ycoord$ = str(GetPointery())
    printc (xcoord$)
    printc (" , ")
    printc (ycoord$)

	SetViewOffset ( GetViewOffsetX ( ) + joystickX#, GetViewOffsetY ( ) + joystickY# )

	 if ( GetPointerPressed ( ) = 1 )

        for i=1 to 500
            if GetSpriteCollision ( curweapon, curmat ) = 1
                force# = CreatePhysicsForce( x#, y#, 3, 25, 10, 1 )
                //SetSpritePhysicsOn ( curweapon, 2 )
                //SetSpritePhysicsOn ( curmat, 2 )
                //SetSpritePhysicsOn ( curmat2, 1 )
                //SetSpriteShape (curweapon, 3)
                //SetSpriteShape (curmat, 2)
                //SetSpriteShape (curmat2, 2)
                rem did sprite hit something
                //curweapon = GetSpriteHit ( GetPointerX ( ), GetPointerY ( ) )
                col# = GetPhysicsCollision( curweapon, curmat )
            endif

            SetSpritePosition (curweapon,x#,y#)
            x# = x# + 5
            SetSpriteAngle(curweapon,r#)
            r# = r# + 5
            sync ( )
        next i

    endif

	// update the screen
	sync ( )
loop


Placement Editor:

+ Code Snippet
type tEntity
	file as string
	id   as integer
	image as integer

	originalMediaIndex as integer

	properties as string
endtype

global curweapon as integer
global curmat as integer
global curmat2 as integer

function LoadFromPlacementEditor ( file$, mode$ )
	// now load the file
	file = OpenToRead ( file$ )

	// find out whether virtual or percentage system is being used
	vMode$         = ReadLine ( file )
	displayWidth$  = ReadLine ( file )
	displayHeight$ = ReadLine ( file )
	screenWidth$   = ReadLine ( file )
	screenHeight$  = ReadLine ( file )
	screenX$       = ReadLine ( file )
	screenY$       = ReadLine ( file )
	width#         = val ( displayWidth$ )
	height#        = val ( displayHeight$ )

	g_fJoystickSpeed# = 4.0

	if ( mode$ = "virtual" )
		SetVirtualResolution ( width#, height# )
		AddVirtualJoystick ( 1, width# - 60, height# - 60, 100 )
	else
		g_fJoystickSpeed# = 1.0
		SetDisplayAspect ( width# / height# )
		AddVirtualJoystick   ( 1, 85, 90, 15 )
	endif

	// next block of data is related to the editor - we don't need to care about this
	temp$ = ReadLine ( file )
	temp$ = ReadLine ( file )
	temp$ = ReadLine ( file )
	x$ = ReadLine ( file )
	y$ = ReadLine ( file )

	SetViewOffset ( val ( x$ ), val ( y$ ) )

	mediaCount$ = ReadLine ( file )

	g_iMediaCount = val ( mediaCount$ ) - 1

	for i = 0 to val ( mediaCount$ ) - 1
		g_MediaList [ i ].file = ReadLine ( file )
		g_MediaList [ i ].image = LoadImage ( g_MediaList [ i ].file )
	next i

	// now get the entity count
	entityCount$ = ReadLine ( file )

	// load all the entities
	for i = 0 to val ( entityCount$ ) - 1

		image$  = ReadLine ( file )
		index$  = ReadLine ( file )
		x$      = ReadLine ( file )
		y$      = ReadLine ( file )
		percentageX$  = ReadLine ( file )
		percentageY$  = ReadLine ( file )
		percentageWidth$  = ReadLine ( file )
		percentageHeight$  = ReadLine ( file )
		locked$ = ReadLine ( file )
		depth$  = ReadLine ( file )

		properties$ = ReadLine ( file )
		scaleX$ = ReadLine ( file )
		scaleY$ = ReadLine ( file )
		angle$ = ReadLine ( file )
		mirror$ = ReadLine ( file )
		flip$ = ReadLine ( file )

		index = val ( index$ )

		// create a new entity using the image from the media list
		g_Entities [ g_iEntityCount ].id   = CreateSprite ( g_MediaList [ index ].image )
		g_Entities [ g_iEntityCount ].properties = properties$

		// store the entities ID number
		id = g_Entities [ g_iEntityCount ].id

		if ( mode$ = "virtual" )
			SetSpritePosition ( id, val ( x$ ), val ( y$ ) )
		else
			SetSpritePosition ( id, val ( percentageX$ ), val ( percentageY$ ) )

			SetSpriteSize ( id, val ( percentageWidth$ ), val ( percentageHeight$ ) )
		endif

		if ( i = 0 and mode$ = "percentage" )
			x# = ( GetSpriteX ( id ) )
			y# = ( GetSpriteY ( id ) )

			SetViewOffset ( x#, y# )
		endif

		SetSpriteDepth ( id, val ( depth$ ) )
		SetSpriteVisible ( id, 1 )

		if ( mode$ = "virtual" )
			SetSpriteScale ( id, val ( scaleX$ ), val ( scaleY$ ) )
		endif

		SetSpriteAngle ( id, val ( angle$ ) )
		SetSpriteFlip ( id, val ( mirror$ ), val ( flip$ ) )

		if image$ = "tinyhammer.png"
            curweapon = id
            `do stuff
            setSpritePhysicsOn(id,2)
            SetSpriteShape(id,3)
            rem or whatever (id is the sprite ID)
        endif

        if image$ = "thinwoodsm.png"
            curmat2 = id
            `do stuff
            setSpritePhysicsOn(id,2)
            SetSpriteShape(id,2)
            rem or whatever (id is the sprite ID)
        endif

        if image$ = "greencube.png"
            curmat = id
            `do stuff
            setSpritePhysicsOn(id,1)
            SetSpriteShape(id,2)
            rem or whatever (id is the sprite ID)
        endif

		g_iEntityCount = g_iEntityCount + 1
	next i

	CloseFile ( file )
endfunction

function DeletePlacementEditorData ( )
	for i = 0 to g_iEntityCount
		DeleteSprite ( g_Entities [ i ].id )
	next i

	for i = 0 to g_iMediaCount
		DeleteImage ( g_MediaList [ i ].id )
	next i

	g_iEntityCount = 0
	g_iMediaCount = 1
endfunction


Setup:

+ Code Snippet
rem
rem ----------*** AGK Setup File ***----------
rem
rem NOTE: This file is used by the core binary
rem to configure basic  setup values  required
rem prior to execution of the  AGC source code.
rem No spaces allowed beyond this point:

global curweapon as integer
global curmat as integer
global curmat2 as integer

rem Window title (delete to hide window bar)
title=Throw Hammer

rem Specify the initial device width
width=640

rem Specify the initial device height
height=480


Mike
Posted: 2nd Jan 2012 21:59
OK, I kinda solved the background issue by loading it in using the placement editor instead of after the fact. However, the hammer refuses to show and it used to.

Also, how do I pin the entire level to fit full screen. If I set the width to 640 and height to 480, then place the background full screen and set all sprites into position, when I load the viewer, everything is offset by quite a bit (x and y) and I have to use the virtual joystick to center the level (based on the full screen background).

I did lock the background in the placement editor, but can that be done in the viewer?

[edit]: sort of fixed it. I found the two lines of data that represent the offset. The question is - why is it offset? Is there a way in the placement editor to make sure you are starting at 0,0 (top left)?

Mike
Posted: 3rd Jan 2012 11:31
I am having some troubles. I am trying to load a simple background image and it is not showing up.

I notice you aren't setting the scale. Could that be the problem? If you are scaling it down that might also be the problem. There was a bug where the placement editor was not using floats for scale so anything smaller than original size was being effectively deleted. There is a fix in for this in the next release.

I would make sure I manually set the correct depth for my sprites too as this might be why they are not visible. Could be they are behind your background image. I just finished a simple example but the code is no better than your own really. I'll attach it here for anyone interested.

I found the two lines of data that represent the offset. The question is - why is it offset? Is there a way in the placement editor to make sure you are starting at 0,0 (top left)?

Not sure about this myself... I would like to see it possible to position an "origin" point for (0,0) on the screen. I'll put a request in.

EDIT: added attachment...
Posted: 3rd Jan 2012 21:32
Thank you for the example.

I loaded my background using the placement editor and that fixed it, but that offset is really weird. I also figured out the numbers to make that offset disappear. I have to set it every time, but at least they are consistent.

Now I am working on a file loader. I hope AppGameKit has one built in. I want to be able to choose and load level files instead of auto loading them.

I am also working on a main menu of sorts.

Mike