I am having some troubles. I am trying to load a simple background image and it is not showing up.
// 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:
// 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:
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:
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
YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com